Brief Synopsis of Linux
Brief Synopsis of Linux
1
2 CONTENTS
Here you have some basic, useful Linux commands. This synopsis is not meant to be exhaustive or
to always offer the best way to achive one goal. It is rather intended to help a beginner use a Linux
system and get a quick start in running the lab applications. The synopsis is mainly concerned with
the Fedora distribution (the one which is used in the lab). Unless otherwise specified, the commands
are to be typed at a terminal prompt.
3
4 CHAPTER 1. BRIEF SYNOPSIS OF LINUX
1.6 Copy files on some other computer via secure copy: scp
Example: if you want to copy file f1 from computer c1 to destination computer c2, into account
iia, open a terminal on c1, change directory (see Section 1.7.1) to the one containing f1 and type:
scp f1 iia@c2: < −− Please note the colon at the end!
then type the password of iia on computer c2. f1 is copied on computer c2, in /home/iia.
1.7.2 Print working directory (the name of the current directory): pwd
This prints the complete name of the current directory. You can also do echo $PWD (see section 1.8)
Let us assume that the current directory is /home/iia and we create here a folder called d1 and a
file called f1.txt in d1. We can reffer to the file f1.txt either as d1/f1.txt (we will say we use the
”relative path”) or as /home/iia/d1/f1.txt (in this case, we use the ”absolute path”). If we type
./d1/f1.txt, we also use a relative path as a dot means ”the current directory”.
If we now change directory to d1, we can reffer to f1.txt as simply f1.txt or as ./f1.txt, or as
/home/iia/d1/f1.txt. Please note the absolute path remains the same, while the relative path (not
surprisingly) changes.
Here, by ”path” we mean the name of a file preceded by the the names of the directories containing
it.
This command creates a symbolic link (like a Windows shortcut: an alternative name for a file). It’s
usually used in order to give a ”constant” name to a file whose ”true” name changes over time (e.g.,
a library, whose name includes the version number). Example:
ln -s /usr/local/lib/myjar.0.1.23.jar myjar.jar
• PATH contains the name of directories, separated by colons, in which a file launched into exe-
cution is to be searched
• CLASSPATH tells Java applications and JDK tools where to search for classes
The env command shows all environment variables and their values.
3. if the directory containing f1.exe (i.e., /home/iia/d2) has been added to PATH, you can just
type f1.exe and this will work no matter which your current directory is
1.9. USB MEMORY STICK 7
5. provided you have changed directory to d2, you can do a f1.exe but this only works if the
current directory, denoted in Linux by a dot, has been added to the PATH. If this is not the
case and the directory containing f1.exe has not been added to the PATH either, then simply
typing f1.exe WILL NOT WORK and will return a command not found error.
Let us assume if you have the dot in your PATH, but no other directories have been added there, and
you have a file called f1.exe in directory d1 and a file also called f1.exe in directory d2. If you
type just f1.exe, you will be able to run f1.exe, but the version to be run depends on your current
directory. So, if you do cd /home/iia/d1 then f1.exe, you will actually run /home/iia/d1/f1.exe.
But if you do cd /home/iia/d2 then f1.exe, you will actually run /home/iia/d2/f1.exe.
The command export PATH=$PATH:. in the example above basicly tells that, if the user tries to run
file x by typing x at the prompt, the shell must search x in the directory where the command x has
been issued, besides the other directories in the PATH.
To find out the absolute path to a program progr which is run, type:
which progr
If we want to see which is the current value of a specific environment variable, we may use:
echo $VARIABLE NAME
Example:
echo $PATH
If you want directory /home/iia/d1 to be added to your PATH automatically each time you log in,
please make sure the following lines are added to the file /home/iia/.bash profile:
PATH=$PATH:/home/iia/d1
export PATH
(alternatively, you can use the file .bashrc in your home directory).
Example:
grep abc file1
displays every line in file1 containing the string abc. The string could actually be a regular
expression (grep actually stands for ”get regular expression pattern”), e.g., f*.txt which means ”all
strings starting with f and ending in .txt”.
The result of a command can be sent into a file instead of being displyed on the screen. This is done
by > dest, if you want the original dest file to be erased, or >> dest if you need it to be appended.
Example:
ls -l > all.txt
creates a detailed list with all files in the current directory which will be written in the file all.txt.
Similarly, one can instruct the system to read from a file f.in instead of the keyboard (to redirect
the input). This is done by using < f.in (e.g., go < f.in makes go read from f.in).
10 CHAPTER 1. BRIEF SYNOPSIS OF LINUX
1.15 Pipes: |
More programs could be pipelined such that the output of one is used as the input for the next; the
operator used is |.
Example:
ls -l | grep *.c
produces a list of all files in a directory (ls -l); this list will be the input for grep *.c, which
searches for all files whose name end in .c.
#include<stdio.h>
void main() {
printf("Hello, world!\n");
}
./configure
make
make install
...
iia 5712 2692 0 22:54 ? 00:00:00 kdeinit4: kio_file [kdein e
root 5713 2 0 22:55 ? 00:00:00 [kworker/2:2]
iia 5752 2481 0 22:57 pts/0 00:00:00 ps -ef
...
showing each program running on your system, together with its ”process identifier”, or pid, which
is a unique number attached to each process, as seen in column 2.