This article describes how to create directories and the different ways to display them. It also explains how to copy and move files and directories. In this context, we will describe a command that allows you to copy files from a workstation to a server and vice versa, which is particularly useful for people operating private homepages. We will then deal with ownership and the allocation of permissions for files and directories. Finally, we will explain how crashed programs (i.e. "hanging" processes) can be terminated without having to reboot the machine.
The option "-l" results in the display of a long file list. The option "-a" adds all hidden files to the list, i.e. the ones starting with a dot (.). [In linux, apart from the coloration system,] the object type is indicated by a character appended to the end of the filename. (e.g. "*" for an executable file or "/" for a directory). Here are some samples:
wfw sciences> ls ELC/ einstein.quotes josiah.displ IRAF/ far2001.tex.Z mail/ SKYCALC/ fgs-fold.mag nsmail/ WWW/ fgs.mag.clip smartclass.err.msg dtu_crdom.readme.txt.Z info.login tapedrive.info.Z wfw sciences>
wfw sciences> ls -a ./ .netscape/ SKYCALC/ ../ .pine-debug1 WWW/ .TTauthority .pine-debug2 dtu_crdom.readme.txt.Z .Xauthority .pine-debug3 einstein.quotes .acrorc .pine-debug4 far2001.tex.Z .addressbook .pinerc fgs-fold.mag .addressbook.lu .solregis/ fgs.mag.clip .cshrc .ssh/ info.login .dt/ .vacation.dir josiah.displ .dtprofile* .vacation.msg mail/ .forward .vacation.msg~ nsmail/ .hotjava/ .vacation.pag smartclass.err.msg .jetadmin/ ELC/ tapedrive.info.Z .login IRAF/ wfw sciences>
wfw sciences> ls -l total 62 drwx------ 6 wfw 512 Jul 1 13:26 ELC/ drwx------ 4 wfw 512 Aug 22 14:01 IRAF/ drwxr-xr-x 2 wfw 512 Nov 22 2000 SKYCALC/ drwxr-xr-x 9 wfw 1024 Jul 1 14:28 WWW/ -rw-r--r-- 1 wfw 8723 Oct 6 2000 dtu_crdom.readme.txt.Z -rw-r--r-- 1 wfw 638 Feb 3 2002 einstein.quotes -rw------- 1 wfw 7347 Oct 2 2001 far2001.tex.Z -rw------- 1 wfw 22528 Jun 22 22:49 fgs-fold.mag -rw------- 1 wfw 12152 Jun 30 18:02 fgs.mag.clip -rw------- 1 wfw 1008 Feb 20 2002 info.login -rw------- 1 wfw 43 Apr 12 11:08 josiah.displ drwx------ 2 wfw 512 Aug 5 22:12 mail/ drwx------ 2 wfw 512 Aug 22 13:36 nsmail/ -rw------- 1 wfw 246 Aug 22 13:55 smartclass.err.msg -rw------- 1 wfw 483 Dec 18 2000 tapedrive.info.Z wfw sciences>
In this last example, ("ls -l"), we have the following from left to right: The first column defines the file type (directory, file or link) and permissions (see below). The second column indicates the number of links to each particular object. Next you can find in a sucession: the file owner, the file group, file size, last change date, and file name.
/iraftmp/iraftmp2/
. This is
an absolute path. Examples of relative moves look like this:
"cd .." moves up one directory level.
"cd ../../myfits" moves up two hierarchy levels and then
moves to subdirectory myfits
.
Just entering "cd" brings you back to your home
directory regardless of your position in the directory tree.
"cd ~" produces the same effect. chmod
("change mode") command changes
permissions for files and directories. If you have a Windows background,
you should first know something about Unix permissions. As we mentioned
above, all files and directories belong to an owner, and this in turn
belongs to a group. Permissions must be separately defined for the owner,
for the group and for all others. An object can be read, written, and
executed by these three (owner, group and all others). Now it's turn to
explain the somewhat "cryptic" characters from the ls -l output
(see above). Just create the subdirectory images in your home
directory by entering mkdir images. Then use ls -l to
display its contents. The output line for this directory will be something
like:
drwxr-xr-x 2 bobby user 35 Jul 16 16:00 images/
Let's first consider the initial sequence of characters. The first
character implies that we are dealing with a directory (d = directory).
The nine following characters are essential because they inform us about
permissions. The first three characters represent the owner, the next
three the group and the last three all others. r stands for
readable, w for writable and x for executable. Program
files and directories must be executable. The sequence
rwxr-xr-x
thus means that bobby, as directory's owner,
can read, write and execute it. The rest (group and all others) can read
and execute it. In the case of directories, execute means that you can
change to them. Defining permissions can be done in two different ways:
with flags for the various users and permissions, or by means of the
so-called octal number.
Symbols: The symbols u, g and a stand for "user", "group" and "all others", and r, w, and x stand for read, write, and executable. Granting and deleting permissions can be done with plus (+) and minus (-). So, if the file bob.pl must be readable for all, the corresponding command reads:
chmod a+r bob.pl
Please notice that by granting permissions for all others (a), the respective flags will be set not only for a, but also for u and g, i.e. all three positions. However, granting permissions to u or g will only set the flag for the first or second position. When granting permissions to a, the a can be omitted in the command:
chmod +r bob.pl
Octal number: This procedure is more elegant because you can set all permission flags for the three groups at the same time. It works by adding a three-digit number to chmod, where the first digit stands for the user (u), the second for the group (g) and the third for all (a). Number 4 corresponds to the flag "read", number 2 for "write" and 1 for "execute". When setting several permission flags, the corresponding numbers will be added to each position. For example, we want to set the following permission flags for the file bob.pl: The user must be able to read, write, and execute. The group must be able to read and execute and the rest shall have "read only" permission. We will then assign 4, 2, and 1 to the user, 4 and 1 to the group (read and execute) and just 4 to all others (read only). The command will read:
chmod 754 bob.pl
killall netscape
After such a "rough" process termination, a so-called "lockfile" is often created. In the case of Netscape, it can be found in directory ~/.netscape and is plainly called lock. If a program cannot be restarted after having been terminated (this often happens with Netscape), this lockfile must be first deleted. In case killall does not seem to work, the option -9, which is actually rougher than the command itself, must be used.
kill works in the same way as killall. The only differece is that not the program's name, but the program's number, the so-called PID, must be given. An individual process number is assigned to every program or command that is started either by booting or by the user. The ps command shows all running processes. In order to display all started processes ps -ax must be executed. If you now want to know e.g. Netscape's process number, you can scroll all processes or, more elegantly, pipe the output of ps -aux into the command grep to filter the Netscape process. The elegant command thus reads:
ps -aux | grep netscapeThe output looks approximately like this:
hansi 11779 0.0 5.1 22284 13120 ? S 11:58 0:01 /opt/netscape/netscape hansi 11968 0.0 0.2 1676 708 pts/0 S 12:53 0:00 grep netscape
In the first place you can see the user who has started the process,
and after it, the process number (PID). We can see two processes above
because grep
has searched for the string "netscape"
and the grep
commmand is also a process with an assigned
number. Netscape will be terminated by entering the command
kill with the process PID, which in our example is:
kill 11779
For persistent cases the option -9 can also be used:
kill -9 11779.