07 – Filesystem
December 5, 2009 – 10:16 pmPlease note… This information no longer exists at the referenced locations. This is only a copy of what was available in 2003.
Basic Linux Training™
Filesystem
Henry White
Table of Contents
Filesystem Types
Generally speaking, each operating system has its own unique filesystem. Files created on one operating system are not readable on any other operating system, or, at least, that’s the way it used to be before some frustrated hackers decided to change the rules of that game
At the present time, Linux “supports” more filesystems than any other OS. (This is not the default, so it won’t work for all these other filesystems right out of the box. You will probably have to recompile your kernel to include any other filesystems you need.)
When you installed Linux you “created” the filesystem on your hard disk. As far as Unix is concerned, a filesystem is any device formatted to store files which can be randomly accessed – this would include your hard disk partitions, floppy disks, CD-ROMs, but not tape drives (which are accessed sequentially and thus cannot contain a filesystem per se; more on tape drives when we discuss system administration).
The current list of major filesystems supported by Linux:
- Coherent Filesystem – coherent
- Extended Filesystem – ext (this has been superseded by ext2)
- Fast Filesystem – ffs Amiga
- HPFS Filesystem – hpfs OS/2 (supported in real-mode only)
- ISO9660 Filesystem – iso9660 CD-ROM
- Linux Swap Filesystem – swap
- Minix Filesystem – minix Minix (This filesystems has its origin in academic projects on operating systems, more specifically as a way to teach how operating systems work. Minix was the first file system used for Linux. Nowadays it is used as filesystem for floppy disks.)
- MS-DOS Filesystem – msdos DOS in all it’s brain-dead 8 dot 3 glory
You’ll probably want to use vfat instead to access your Windows partition. - Network File System (NFS) – nfs Here data can be stored on any machine in a network and access may be granted via a network.
- Novell Filesystem – ncpfs Novell servers.
- NT – ntfs This one has been a problem for a long time, but work has recently resumed on it, so you can probably expect real progress in mid- to late-’01 or early in ’02.
- /proc Filesystem – proc Virtual filesystem used by the kernel to provide information about processes to the user.
- Second Extended Filesystem – ext2 Linux standard filesystem.
- SMB Filesystem – smbfs Windows for Workgroups and NT servers.
- System V Filesystem – sysv System V variants; used on SCO-Unix, Xenix and Coherent (commercial Unix systems for PCs).
- Uniform Filesystem – ufs Used by BSD , SunOS and NeXTstep; is only supported in read-only mode.
- UMSDOS Filesystem – umsdos Unix on MSDOS Is applied on top of a normal fat filesystem. It achieves Unix functionality (permissions, links, long filenames) by creating special files. It is rather slow. It is required for the demo-mode.
- Virtual FAT Filesystem – vfat Windows (FAT Extension of the fat file system, supports long filenames).
- Xenix Filesystem – xenix More or less obsolete.
- Xia Filesystem – xiafs Another old filesystem that is hardly used anymore.
There are several new filesystems you will undoubtedly encounter soon – ext3 and reiserfs (both are still considered to be in beta testing, but most people who have tried them, particularly reiserfs which has been shipped with recent versions of S.u.S.E., seem to like them.
Since most new users will be coming from DOS/Windows and dual-booting, you will want to include those. Also there is a nice utility called mtools that works especially well with your floppy drive – just affix an m to the usual DOS command (e.g. mdir and mcd etc. without going through the mount/umount procedure. There are also several ways to access your Windows applications that you’ll want to check into. Both wine and samba are GPL, and there are a couple of commercial applications that run on top of Linux – win4lin and vmware, both of which require a fairly fast microprocessor with plenty of RAM.
Mounting Filesystems
Storage media can be linked into the Linux filesystem via the command mount (which can only be invoked by `root‘ unless you give normal users permission to use it, and only after that media is listed in /etc/fstab and you have created the directory where they will be mounted).
A simple way to remember this is that /etc/fstab list the filesystems available to mount; /etc/mtab lists the filesystems that are currently mounted.
Unmounting Filesystems
umount removes a partition from Linux’ filesystem; it does NOT delete it from your hard disk, it just makes it ‘invisible’ as part of the Linux filesystem. You can pass either the name of the device or the name of the directory where it is mounted as an argument to umount. So, for removing /dev/hda2 which is mounted under /dos you can enter either of:
# umount /dos
# umount /dev/hda2
¹ – This command used to be called unmount but the `n’ got lost somewhere early in Unix history. In the same category as the infamous ‘creat‘ without the final ‘e‘
(Which is another way of saying, programmers are not better spellers or typists than anyone else.
It is important (if you have mounted a disk) to execute umount before you remove the disk since not all files are necessarily written to disk at this time; you can lose your data that way! If there are opened files on this device umount will try to write them otherwise it produces an error message. You have to leave the filesystem or directory you want to unmount before you issue the command umount. If there are still users working in this directory (for example, in a shell), the filesystem can not be unmounted
System Information
Sometimes it is important to gather information about the system’s state. The commands df, free, top, ps are the most commonly used.
- df outputs information on the used and occupied hard disk space. Output is given similar to this example (obtained by using df):
/dev/hda6 2266651 509350 1640123 24% / /dev/hda8 3018725 160576 2702037 6% /home /dev/hda9 3018725 797332 2065281 28% /var /dev/hda5 29247 11671 16066 43% /boot /dev/hda1 4874180 1849144 3025036 38% /windows
- free gives information on usage of RAM and swap:
total used free shared buffers cached Mem: 125176 119140 6036 0 36620 8692 -/+ buffers/cache: 73828 51348 Swap: 128484 2476 126008
- w shows all currently active users on your system. This command outputs a rather informative list on certain issues. It shows you all users, how long the system has been up and running, its load and the user’s current action.
- du gives information on the space that is used by subdirectories and single files. More can be found under the manpage of infopage ( man du).
- kill sends signals to currently active processes, and expects a process number (PID) as an argument. This PID can be obtained by ps a. kill is invoked using the PID associated with the process you want to kill:
# kill <pid>
If the corresponding process catches the signal it can be killed by giving the optional parameter -9.
Entering
# kill -9 <pid>
- ps (process status) shows the processes started by the user. More information on this command can be obtained in manpage for ps. ps shows information on running processes of the other users as well. Giving the process id it is possible to kill running processes.
- top outputs all running processes and their loads and other information. This list is being updated every few seconds (generally ’5′). You can end it using q.
Working with Directories
The directory tree of your Linux system is well organized. Some important directories are:
/ - "root" directory, start of the directory tree
/bin - commands needed to run the system
/boot - boot files
/dev - device files that represent the system hardware
/etc - important system configuration files
/home - the (private) directories of the users
/lib - shared libraries (for dynamically linked programs)
/opt - optional software, large systems (e.g. KDE)
/proc - the process file system
/sbin - commands reserved for the superuser
and needed for system start
/sbin/init.d - scripts for system start
/tmp - temporary files
/usr - user commands and applications,
documentation, example configuration files, can be mounted
read-only
/usr/bin - publicly accessible commands
/usr/doc - documentation files
/usr/include - header files for the C compiler
/usr/include/g++ - header files for the C++ compiler
/usr/local - local extensions, independent
from the distribution
/usr/man - manual pages
/usr/sbin - commands reserved for the superuser
/usr/src - source code for the system software
/usr/src/linux - the kernel sources
/var - files that are generally more 'permanent'
that the ones in /tmp but more 'temporary'
than the rest of the system - for example, your incoming and
outgoing email will be stored here
/var/tmp - big temporary files
The actual location in the hierarchy for some files and directories will vary slightly from distribution to distribution. Bringing everybody to a common location is one of the primary goals of the Linux Standards Base, and once that has been decided and every distribution conforms to the same standard, it will be much easier to switch from one distribution to another. This will eliminate a lot of the confusion for new users, and others trying to help them
After login you’ll find yourself in your home directory. You can check this by typing pwd (print working directory):
henry@suse6.0:/home/henry$ pwd /home/henry
For changing into another directory there is the cd command (change directory). Typing
henry@suse6.0:/home/henry$ cd /usr/bin
henry@suse6.0:/usr/bin$
changes into directory /usr/bin, as shown in the prompt.
If you invoke cd without any argument you will be brought back home. This can be reached by typing a tilde (`~’) as well.
`.’ signifies the current directory whereas `..’ stands for the parent directory.
You can create new directories with mkdir (make directory).
The command
henry@suse6.0:/home/henry$ mkdir texts
creates texts under the current directory, so you will have an empty directory called /home/henry/texts
Empty directories can be removed using the command rmdir (remove directory). (All files in the directory must be deleted or moved before you can delete the directory.)
Until they are replaced by objects or symbols (in future days) files play a vital and central role while working with a computer. Therefore a huge variety of file commands exist under Linux.
Working with Files
The syntax for copying files under Linux is cp (copy)
cp <source> <target>
For copying file /etc/XF86Config into your own home directory you would use:
henry@suse6.0:$ cp /etc/XF86Config ~
where the tilde symbol ~ represents the home directory for the user.
Files can be removed using the rm command (remove). A very handy option is -r which deletes recursively (removing all subdirectories and their files as well; this is comparable to deltree in DOS). Entering:
henry@suse6.0:$ rm -r articles
deletes /articles and all files and subdirectories within. Please use this option with extreme precaution.
You can move (or rename) files by typing mv (move); syntax is identical to cp.
henry@suse6.0:$ mv xvnews.tgz XVNEWS.tgz
moves file xvnews.tgz to XVNEWS.tgz which is no more than just renaming it. It’s gets to be more interesting if you move whole directory trees:
henry@suse6.0:$ mv articles ~/html
This moves the directory articles (if there is one) to ~/html. All files that used to be under articles are now to be found under ~/html. Even this command should be used with care since it is very easy to move whole trees to places that you do not remember afterward.
Moving a complete directory tree only is possible only within one filesystem (one partition). However, if you are using mc, this is no longer a restriction.
Searching and grepping Files
This leads to another useful command: find (find). For searching all subdirectories of the current directory for the file articles you should enter:
henry@suse6.0:$ find . -name "articles"
First argument gives the directory where the search should commence. The option name expects a search string (wild cards are allowed). Thus, for searching all files containing the string `articles‘ you would have to change the line to:
henry@suse6.0:$ find . -name "*articles*"
As with all commands we suggest you look at the man pages for more information. There is a fast way; try finding files with locate.
If you do not want to search for a file but for a string inside a file instead, you should use the grep command. This command line searches for the string `device‘ in the file articles:
henry@suse6.0:$ grep "device" articles
Thus you can search vast amounts of data for certain strings very quickly. Any number of filenames can be entered, even searching using wild cards and regular expressions (which we’ll cover in detail in a later lesson) can be used. grep sends its results to standard output; it gives you every location where the string was found. grep knows many options; please have a look at manpage for grep.
File Ownership and Permissions
The command ls (list) outputs the contents of your current directory. A list of all filenames and directories is presented. Directory names end with a `/’. Of course you can see any directory if you enter a directory:
henry@suse6.0:$ ls /usr/bin
Executable programs do not have any extensions as .exe or .com, but an asterisk `*’. You don’t have to set it, it is set by the attribute “executable” behind the filename.
A rather nice option is -l. This gives you a long list of filenames including their owner, permissions, groups and size. Just the kind of stuff you’ll probably need the most
henry@suse6.0:$ ls -l
This will create an output as shown. The meaning of the entries is explained in the table that follows.
drwxr-xr-x 6 henry users 1024 Mar 21 12:39 ./
drwxr-xr-x 4 henry users 1024 Mar 21 17:13 ../
drwxr-xr-x 2 henry users 1024 Nov 6 16:19 bin/
-rwxr-xr-x 1 henry users 4160 Mar 21 12:38 check*
drwxr-xr-x 2 henry users 1024 Nov 6 16:23 etc/
drwxr-xr-x 2 henry users 1024 Nov 6 16:19 sbin/
drwxr-xr-x 12 henry users 1024 Nov 6 18:20 usr/
-rw-r--r-- 1 henry users 185050 Mar 15 12:33 xvi.tgz
-rw-r--r-- 1 henry users 98444 Mar 14 12:30 xvnews.tgz
Permissions The first character indicates the
file type. `d' stands for directory, `l' for a link
and `-' is a normal file. The next 9 characters
indicate permissions for the user, the group and all
other users (three characters each which can also be
represented in binary form, adding permission for the
three groups). `r' (4) stands for read, `w' (2) for
write, and `x' (1) for execution. For example,
`-rw-r--r--' (644) refers to a file which can be read
by the owner, the group and all others, whereas it can
only be changed by the owner. See manpage for
chmod.
Owner The owner of the file. See manpage for
chown.
Group The group the file belongs to. See manpage for
chgrp.
Size The file's size in bytes. last
change Date when the file has been changed last. Files
that have been changed more than a year ago are marked
with the year instead of hours:minutes.
Name The file or directory's name.
Note that anytime a reference is made to the man pages that it implies also checking the same command in info. Some overlap, some do not; the information in info generally is more complete and up to date.
Only the user `root’, being the system administrator, has got unrestricted permissions to all files.
Let’s have a look at a hypothetical file linux.info:
-rw-r-xr-- 1 henry users 29524 Jun 29 13:11 linux.info
Well, this file can be read and written by the owner (henry); all members of the group users are allowed to read and execute it whereas all other users are only allowed to read it. `-‘ indicates that this is a “normal” file.
The same applies to directories; if the given file is a directory there is a `d‘ in front of those 9 characters (d stands for directory). This might look like:
drwxr-xr-- 3 henry users 1024 Jun 29 13:11 info/ `x'
in this case means that one is allowed to cd into this directory.
Changing Permissions
You can change permissions with the chmod command (change mode). The main options chmod needs are the permissions to be changed and a filename.
- permissions that are to be changed
- a file name
Those three categories are represented by `u‘ (user), `g‘ (group, and `o‘ (others) followed by the corresponding permissions. A `+‘ or a `-‘ means adding or removing the corresponding flag. Our example sets permissions of the file linux.info to readable, changeable and executable for group members:
henry@suse6.0:$ chmod g+rwx linux.info
If permissions for all categories should be set, then giving the permissions to be changed is sufficient. This command sets permissions of pathlinux.info so nobody has write permissions:
henry@suse6.0:$ chmod -w linux.info
Those permissions concerning reading and executing are not involved in this example. You can give permissions and remove them within a single command line. This sets the permissions of linux.info to executable, not readable, and not changeable:
henry@suse6.0:$ chmod u+x-rw linux.info
If you look at the result:
henry@suse6.0:$ ls -l linux.info
---xr-xr-- 1 henry users 29524 Jun 29 13:11 linux.info
Hidden Files
A special sort of files are the hidden files. Those files begin with a dot and are only seen if you pass the shell the special option -a. In your home directory just enter ls -a; now you should see all files, even these hidden ones (like .profile or .xinitrc). Hidden files are protected from an otherwise hazardous rm * (those files have to deleted separately with rm <.filename>.
Entering rm .* deletes all hidden files of the current directory. If the option -r is added (recursive; rm -r .*) all files of the parent directory are deleted as well (they are named `../bla’ which is represented by `.*’ as well)
So be extremely careful with recursion (various commands may use -r or -R)!
There is an undelete program in Linux, but it is not a standard part of any distribution. (BTW, when configuring your editor there is an option to create backups automatically with the tilde (~) appended to the file as it was before you began editing. For new users, it is crucial that you first copy any configuration file and append a standard suffix – such as .orig. This is the cheapest insurance you can take out when you start and very hard to get into the habit of doing if you don’t consistently do this as a matter of routine right from the beginning. I can assure you that the time will come when you will NOT have access to the outside world, and having one of these originals to fall back on will save you hours of frustration.)
In /root and the home directory of a user there are several configuration files which for practical reasons are “hidden” (‘dot’ files so named because the filename begins with a dot). (These files are rarely changed after the initial configuration is running correctly.) Any file becomes hidden if you attach a dot at the beginning of the file. You can see those files with the command ls -a; they do not appear with ls (unless, of course, you alias ls to ls -a). Some examples are below.
- .profile login script (for bash)
- .bashrc bash configuration
- .exrc vi configuration
- .xinitrc X-Window system startup script
- .fvwmrc Configuration of fvwm window manager
- .ctwmrc Configuration of ctwm window manager
- .openwin-menu Configuration of olvwm and olwm window manager
These files are copied from /etc/skel when creating a new user.
Links
By means of symbolic links you can give another name or file path to a file. This name “points” to the corresponding file. Imagine that you want to keep different versions of a file but the version actually used should be obtainable by the same name (always). The solution is called symbolic linking which points to the currently in use version. Symbolic links behave just like the file they link too, thus being executable if the “source” file is executable. The entry
henry@suse6.0:$ ln -s check.2.4 check
creates a symbolic link. In your directory this looks like:
lrwxrwxrwx 1 henry users 1024 Mar 21 17:13 check -> check.2.4*
(Note the ‘l‘ in the first field for the modes, indicating that this is a link and also the -> at the end of the normal listing pointing to the linked file.)
Symbolic links can be removed by rm.
Note: only the link is removed not the source file!
Assignments
Terms and Concepts:
Define and add these to your glossary:
Utilities & Commands
- cd
- chgrp
- chmod
- chown
- ln
- ls
- mkdir
- mv
- pwd
- rmdir
- stty
- umask
Files & Directories
- ~/.X.err
- ~/.Xdefaults
- ~/.bash_history
- ~/.bashrc
- ~/.bash_profile
- ~/.cshrc
- ~/.emacs
- ~/.exrc
- ~/.fvwm2rc
- ~/.ispell_english
- ~/.login
- ~/.mailcap
- ~/.mc
- ~/.mime.types
- ~/.newsrc-news
- ~/.xftpcache
- ~/.xftprc
- ~/.xinitrc
- ~/mbox
- /bin
- /boot
- /dev
- /etc
- /etc/ppp
- /etc/skel
- /home
- /lib
- /lost+found
- /mnt
- /opt
- /proc
- /root
- /sbin
- /tmp
- /usr
- /usr/bin
- /usr/doc
- /usr/include
- /usr/lib
- /usr/lib/X11R6
- /usr/src
- /var
- /var/log
- /var/spool
Terms & Concepts
- absolute path
- access permissions
- children
- device files
- directory
- directory files
- execute
- family tree
- filename
- filename extension
- filesystem
- full pathname
- group
- hard link
- hidden file
- hierarchical
- inode
- invisible file
- link
- ordinary file
- owner
- pathname
- parent
- read
- relative path
- simple filename
- special files
- symbolic link
- tree
- write
- symbolic link
On-line:
- ~/linux-2.4.0/linux/Documentation/filesystems – the kernel source has a lot of specific information about the filesystems supported at the kernel level
- http://www.linuxbase.org/ – Linux Standard Base
- http://www.pathname.com/fhs/ – Filesystem Hierarchy Standard
(There is also an RPM on the File Hierarchical Standard – e.g., fhs.rpm included on many of the CDROMs.) - http://www.atnf.csiro.au/~rgooch/linux/docs/devfs.html – Linux Devfs (Device File System) FAQ by Richard Gooch
Copyright © 1997-2003 Henry White. All Rights Reserved.
Reproduction or redistribution without prior written consent is strictly prohibited. Address comments and inquiries to info@basiclinux.net.
Filesystem
Henry White
Table of Contents
Filesystem Types
Generally speaking, each operating system has its own unique filesystem. Files created on one operating system are not readable on any other operating system, or, at least, that’s the way it used to be before some frustrated hackers decided to change the rules of that game
At the present time, Linux “supports” more filesystems than any other OS. (This is not the default, so it won’t work for all these other filesystems right out of the box. You will probably have to recompile your kernel to include any other filesystems you need.)
When you installed Linux you “created” the filesystem on your hard disk. As far as Unix is concerned, a filesystem is any device formatted to store files which can be randomly accessed – this would include your hard disk partitions, floppy disks, CD-ROMs, but not tape drives (which are accessed sequentially and thus cannot contain a filesystem per se; more on tape drives when we discuss system administration).
The current list of major filesystems supported by Linux:
- Coherent Filesystem – coherent
- Extended Filesystem – ext (this has been superseded by ext2)
- Fast Filesystem – ffs Amiga
- HPFS Filesystem – hpfs OS/2 (supported in real-mode only)
- ISO9660 Filesystem – iso9660 CD-ROM
- Linux Swap Filesystem – swap
- Minix Filesystem – minix Minix (This filesystems has its origin in academic projects on operating systems, more specifically as a way to teach how operating systems work. Minix was the first file system used for Linux. Nowadays it is used as filesystem for floppy disks.)
- MS-DOS Filesystem – msdos DOS in all it’s brain-dead 8 dot 3 glory
You’ll probably want to use vfat instead to access your Windows partition. - Network File System (NFS) – nfs Here data can be stored on any machine in a network and access may be granted via a network.
- Novell Filesystem – ncpfs Novell servers.
- NT – ntfs This one has been a problem for a long time, but work has recently resumed on it, so you can probably expect real progress in mid- to late-’01 or early in ’02.
- /proc Filesystem – proc Virtual filesystem used by the kernel to provide information about processes to the user.
- Second Extended Filesystem – ext2 Linux standard filesystem.
- SMB Filesystem – smbfs Windows for Workgroups and NT servers.
- System V Filesystem – sysv System V variants; used on SCO-Unix, Xenix and Coherent (commercial Unix systems for PCs).
- Uniform Filesystem – ufs Used by BSD , SunOS and NeXTstep; is only supported in read-only mode.
- UMSDOS Filesystem – umsdos Unix on MSDOS Is applied on top of a normal fat filesystem. It achieves Unix functionality (permissions, links, long filenames) by creating special files. It is rather slow. It is required for the demo-mode.
- Virtual FAT Filesystem – vfat Windows (FAT Extension of the fat file system, supports long filenames).
- Xenix Filesystem – xenix More or less obsolete.
- Xia Filesystem – xiafs Another old filesystem that is hardly used anymore.
There are several new filesystems you will undoubtedly encounter soon – ext3 and reiserfs (both are still considered to be in beta testing, but most people who have tried them, particularly reiserfs which has been shipped with recent versions of S.u.S.E., seem to like them.
Since most new users will be coming from DOS/Windows and dual-booting, you will want to include those. Also there is a nice utility called mtools that works especially well with your floppy drive – just affix an m to the usual DOS command (e.g. mdir and mcd etc. without going through the mount/umount procedure. There are also several ways to access your Windows applications that you’ll want to check into. Both wine and samba are GPL, and there are a couple of commercial applications that run on top of Linux – win4lin and vmware, both of which require a fairly fast microprocessor with plenty of RAM.
Mounting Filesystems
Storage media can be linked into the Linux filesystem via the command mount (which can only be invoked by `root‘ unless you give normal users permission to use it, and only after that media is listed in /etc/fstab and you have created the directory where they will be mounted).
A simple way to remember this is that /etc/fstab list the filesystems available to mount; /etc/mtab lists the filesystems that are currently mounted.
Unmounting Filesystems
umount removes a partition from Linux’ filesystem; it does NOT delete it from your hard disk, it just makes it ‘invisible’ as part of the Linux filesystem. You can pass either the name of the device or the name of the directory where it is mounted as an argument to umount. So, for removing /dev/hda2 which is mounted under /dos you can enter either of:
# umount /dos
# umount /dev/hda2
¹ – This command used to be called unmount but the `n’ got lost somewhere early in Unix history. In the same category as the infamous ‘creat‘ without the final ‘e‘
(Which is another way of saying, programmers are not better spellers or typists than anyone else.
It is important (if you have mounted a disk) to execute umount before you remove the disk since not all files are necessarily written to disk at this time; you can lose your data that way! If there are opened files on this device umount will try to write them otherwise it produces an error message. You have to leave the filesystem or directory you want to unmount before you issue the command umount. If there are still users working in this directory (for example, in a shell), the filesystem can not be unmounted
System Information
Sometimes it is important to gather information about the system’s state. The commands df, free, top, ps are the most commonly used.
- df outputs information on the used and occupied hard disk space. Output is given similar to this example (obtained by using df):
/dev/hda6 2266651 509350 1640123 24% / /dev/hda8 3018725 160576 2702037 6% /home /dev/hda9 3018725 797332 2065281 28% /var /dev/hda5 29247 11671 16066 43% /boot /dev/hda1 4874180 1849144 3025036 38% /windows
- free gives information on usage of RAM and swap:
total used free shared buffers cached Mem: 125176 119140 6036 0 36620 8692 -/+ buffers/cache: 73828 51348 Swap: 128484 2476 126008
- w shows all currently active users on your system. This command outputs a rather informative list on certain issues. It shows you all users, how long the system has been up and running, its load and the user’s current action.
- du gives information on the space that is used by subdirectories and single files. More can be found under the manpage of infopage ( man du).
- kill sends signals to currently active processes, and expects a process number (PID) as an argument. This PID can be obtained by ps a. kill is invoked using the PID associated with the process you want to kill:
# kill <pid>
If the corresponding process catches the signal it can be killed by giving the optional parameter -9.
Entering
# kill -9 <pid>
- ps (process status) shows the processes started by the user. More information on this command can be obtained in manpage for ps. ps shows information on running processes of the other users as well. Giving the process id it is possible to kill running processes.
- top outputs all running processes and their loads and other information. This list is being updated every few seconds (generally ’5′). You can end it using q.
Working with Directories
The directory tree of your Linux system is well organized. Some important directories are:
/ - "root" directory, start of the directory tree
/bin - commands needed to run the system
/boot - boot files
/dev - device files that represent the system hardware
/etc - important system configuration files
/home - the (private) directories of the users
/lib - shared libraries (for dynamically linked programs)
/opt - optional software, large systems (e.g. KDE)
/proc - the process file system
/sbin - commands reserved for the superuser
and needed for system start
/sbin/init.d - scripts for system start
/tmp - temporary files
/usr - user commands and applications,
documentation, example configuration files, can be mounted
read-only
/usr/bin - publicly accessible commands
/usr/doc - documentation files
/usr/include - header files for the C compiler
/usr/include/g++ - header files for the C++ compiler
/usr/local - local extensions, independent
from the distribution
/usr/man - manual pages
/usr/sbin - commands reserved for the superuser
/usr/src - source code for the system software
/usr/src/linux - the kernel sources
/var - files that are generally more 'permanent'
that the ones in /tmp but more 'temporary'
than the rest of the system - for example, your incoming and
outgoing email will be stored here
/var/tmp - big temporary files
The actual location in the hierarchy for some files and directories will vary slightly from distribution to distribution. Bringing everybody to a common location is one of the primary goals of the Linux Standards Base, and once that has been decided and every distribution conforms to the same standard, it will be much easier to switch from one distribution to another. This will eliminate a lot of the confusion for new users, and others trying to help them
After login you’ll find yourself in your home directory. You can check this by typing pwd (print working directory):
henry@suse6.0:/home/henry$ pwd /home/henry
For changing into another directory there is the cd command (change directory). Typing
henry@suse6.0:/home/henry$ cd /usr/bin
henry@suse6.0:/usr/bin$
changes into directory /usr/bin, as shown in the prompt.If you invoke cd without any argument you will be brought back home. This can be reached by typing a tilde (`~’) as well.
`.’ signifies the current directory whereas `..’ stands for the parent directory.
You can create new directories with mkdir (make directory).
The command
henry@suse6.0:/home/henry$ mkdir texts
creates texts under the current directory, so you will have an empty directory called /home/henry/textsEmpty directories can be removed using the command rmdir (remove directory). (All files in the directory must be deleted or moved before you can delete the directory.)
Until they are replaced by objects or symbols (in future days) files play a vital and central role while working with a computer. Therefore a huge variety of file commands exist under Linux.
Working with Files
The syntax for copying files under Linux is cp (copy)
cp <source> <target>
For copying file /etc/XF86Config into your own home directory you would use:
henry@suse6.0:$ cp /etc/XF86Config ~
where the tilde symbol ~ represents the home directory for the user.Files can be removed using the rm command (remove). A very handy option is -r which deletes recursively (removing all subdirectories and their files as well; this is comparable to deltree in DOS). Entering:
henry@suse6.0:$ rm -r articles
deletes /articles and all files and subdirectories within. Please use this option with extreme precaution.You can move (or rename) files by typing mv (move); syntax is identical to cp.
henry@suse6.0:$ mv xvnews.tgz XVNEWS.tgz
moves file xvnews.tgz to XVNEWS.tgz which is no more than just renaming it. It’s gets to be more interesting if you move whole directory trees:
henry@suse6.0:$ mv articles ~/html
This moves the directory articles (if there is one) to ~/html. All files that used to be under articles are now to be found under ~/html. Even this command should be used with care since it is very easy to move whole trees to places that you do not remember afterward.
Moving a complete directory tree only is possible only within one filesystem (one partition). However, if you are using mc, this is no longer a restriction.
Searching and grepping FilesThis leads to another useful command: find (find). For searching all subdirectories of the current directory for the file articles you should enter:
henry@suse6.0:$ find . -name "articles"
First argument gives the directory where the search should commence. The option name expects a search string (wild cards are allowed). Thus, for searching all files containing the string `articles‘ you would have to change the line to:
henry@suse6.0:$ find . -name "*articles*"
As with all commands we suggest you look at the man pages for more information. There is a fast way; try finding files with locate.
If you do not want to search for a file but for a string inside a file instead, you should use the grep command. This command line searches for the string `device‘ in the file articles:
henry@suse6.0:$ grep "device" articles
Thus you can search vast amounts of data for certain strings very quickly. Any number of filenames can be entered, even searching using wild cards and regular expressions (which we’ll cover in detail in a later lesson) can be used. grep sends its results to standard output; it gives you every location where the string was found. grep knows many options; please have a look at manpage for grep.
File Ownership and Permissions
The command ls (list) outputs the contents of your current directory. A list of all filenames and directories is presented. Directory names end with a `/’. Of course you can see any directory if you enter a directory:
henry@suse6.0:$ ls /usr/bin
Executable programs do not have any extensions as .exe or .com, but an asterisk `*’. You don’t have to set it, it is set by the attribute “executable” behind the filename.
A rather nice option is -l. This gives you a long list of filenames including their owner, permissions, groups and size. Just the kind of stuff you’ll probably need the most
henry@suse6.0:$ ls -l
This will create an output as shown. The meaning of the entries is explained in the table that follows.
drwxr-xr-x 6 henry users 1024 Mar 21 12:39 ./
drwxr-xr-x 4 henry users 1024 Mar 21 17:13 ../
drwxr-xr-x 2 henry users 1024 Nov 6 16:19 bin/
-rwxr-xr-x 1 henry users 4160 Mar 21 12:38 check*
drwxr-xr-x 2 henry users 1024 Nov 6 16:23 etc/
drwxr-xr-x 2 henry users 1024 Nov 6 16:19 sbin/
drwxr-xr-x 12 henry users 1024 Nov 6 18:20 usr/
-rw-r--r-- 1 henry users 185050 Mar 15 12:33 xvi.tgz
-rw-r--r-- 1 henry users 98444 Mar 14 12:30 xvnews.tgz
Permissions The first character indicates the
file type. `d' stands for directory, `l' for a link
and `-' is a normal file. The next 9 characters
indicate permissions for the user, the group and all
other users (three characters each which can also be
represented in binary form, adding permission for the
three groups). `r' (4) stands for read, `w' (2) for
write, and `x' (1) for execution. For example,
`-rw-r--r--' (644) refers to a file which can be read
by the owner, the group and all others, whereas it can
only be changed by the owner. See manpage for
chmod.
Owner The owner of the file. See manpage for
chown.
Group The group the file belongs to. See manpage for
chgrp.
Size The file's size in bytes. last
change Date when the file has been changed last. Files
that have been changed more than a year ago are marked
with the year instead of hours:minutes.
Name The file or directory's name.
Note that anytime a reference is made to the man pages that it implies also checking the same command in info. Some overlap, some do not; the information in info generally is more complete and up to date.
Only the user `root’, being the system administrator, has got unrestricted permissions to all files.
Let’s have a look at a hypothetical file linux.info:
-rw-r-xr-- 1 henry users 29524 Jun 29 13:11 linux.info
Well, this file can be read and written by the owner (henry); all members of the group users are allowed to read and execute it whereas all other users are only allowed to read it. `-‘ indicates that this is a “normal” file.
The same applies to directories; if the given file is a directory there is a `d‘ in front of those 9 characters (d stands for directory). This might look like:
drwxr-xr-- 3 henry users 1024 Jun 29 13:11 info/ `x'
in this case means that one is allowed to cd into this directory.
Changing PermissionsYou can change permissions with the chmod command (change mode). The main options chmod needs are the permissions to be changed and a filename.
- permissions that are to be changed
- a file name
Those three categories are represented by `u‘ (user), `g‘ (group, and `o‘ (others) followed by the corresponding permissions. A `+‘ or a `-‘ means adding or removing the corresponding flag. Our example sets permissions of the file linux.info to readable, changeable and executable for group members:
henry@suse6.0:$ chmod g+rwx linux.info
If permissions for all categories should be set, then giving the permissions to be changed is sufficient. This command sets permissions of pathlinux.info so nobody has write permissions:
henry@suse6.0:$ chmod -w linux.info
Those permissions concerning reading and executing are not involved in this example. You can give permissions and remove them within a single command line. This sets the permissions of linux.info to executable, not readable, and not changeable:
henry@suse6.0:$ chmod u+x-rw linux.info
If you look at the result:
henry@suse6.0:$ ls -l linux.info
---xr-xr-- 1 henry users 29524 Jun 29 13:11 linux.info
Hidden Files
A special sort of files are the hidden files. Those files begin with a dot and are only seen if you pass the shell the special option -a. In your home directory just enter ls -a; now you should see all files, even these hidden ones (like .profile or .xinitrc). Hidden files are protected from an otherwise hazardous rm * (those files have to deleted separately with rm <.filename>.
Entering rm .* deletes all hidden files of the current directory. If the option -r is added (recursive; rm -r .*) all files of the parent directory are deleted as well (they are named `../bla’ which is represented by `.*’ as well)
So be extremely careful with recursion (various commands may use -r or -R)!
There is an undelete program in Linux, but it is not a standard part of any distribution. (BTW, when configuring your editor there is an option to create backups automatically with the tilde (~) appended to the file as it was before you began editing. For new users, it is crucial that you first copy any configuration file and append a standard suffix – such as .orig. This is the cheapest insurance you can take out when you start and very hard to get into the habit of doing if you don’t consistently do this as a matter of routine right from the beginning. I can assure you that the time will come when you will NOT have access to the outside world, and having one of these originals to fall back on will save you hours of frustration.)
In /root and the home directory of a user there are several configuration files which for practical reasons are “hidden” (‘dot’ files so named because the filename begins with a dot). (These files are rarely changed after the initial configuration is running correctly.) Any file becomes hidden if you attach a dot at the beginning of the file. You can see those files with the command ls -a; they do not appear with ls (unless, of course, you alias ls to ls -a). Some examples are below.
- .profile login script (for bash)
- .bashrc bash configuration
- .exrc vi configuration
- .xinitrc X-Window system startup script
- .fvwmrc Configuration of fvwm window manager
- .ctwmrc Configuration of ctwm window manager
- .openwin-menu Configuration of olvwm and olwm window manager
These files are copied from /etc/skel when creating a new user.
Links
By means of symbolic links you can give another name or file path to a file. This name “points” to the corresponding file. Imagine that you want to keep different versions of a file but the version actually used should be obtainable by the same name (always). The solution is called symbolic linking which points to the currently in use version. Symbolic links behave just like the file they link too, thus being executable if the “source” file is executable. The entry
henry@suse6.0:$ ln -s check.2.4 check
creates a symbolic link. In your directory this looks like:
lrwxrwxrwx 1 henry users 1024 Mar 21 17:13 check -> check.2.4*
(Note the ‘l‘ in the first field for the modes, indicating that this is a link and also the -> at the end of the normal listing pointing to the linked file.)
Symbolic links can be removed by rm.
Note: only the link is removed not the source file!
Assignments
Terms and Concepts:
Define and add these to your glossary:
Utilities & Commands
- cd
- chgrp
- chmod
- chown
- ln
- ls
- mkdir
- mv
- pwd
- rmdir
- stty
- umask
Files & Directories
- ~/.X.err
- ~/.Xdefaults
- ~/.bash_history
- ~/.bashrc
- ~/.bash_profile
- ~/.cshrc
- ~/.emacs
- ~/.exrc
- ~/.fvwm2rc
- ~/.ispell_english
- ~/.login
- ~/.mailcap
- ~/.mc
- ~/.mime.types
- ~/.newsrc-news
- ~/.xftpcache
- ~/.xftprc
- ~/.xinitrc
- ~/mbox
- /bin
- /boot
- /dev
- /etc
- /etc/ppp
- /etc/skel
- /home
- /lib
- /lost+found
- /mnt
- /opt
- /proc
- /root
- /sbin
- /tmp
- /usr
- /usr/bin
- /usr/doc
- /usr/include
- /usr/lib
- /usr/lib/X11R6
- /usr/src
- /var
- /var/log
- /var/spool
Terms & Concepts
- absolute path
- access permissions
- children
- device files
- directory
- directory files
- execute
- family tree
- filename
- filename extension
- filesystem
- full pathname
- group
- hard link
- hidden file
- hierarchical
- inode
- invisible file
- link
- ordinary file
- owner
- pathname
- parent
- read
- relative path
- simple filename
- special files
- symbolic link
- tree
- write
- symbolic link
On-line:
- ~/linux-2.4.0/linux/Documentation/filesystems – the kernel source has a lot of specific information about the filesystems supported at the kernel level
- http://www.linuxbase.org/ – Linux Standard Base
- http://www.pathname.com/fhs/ – Filesystem Hierarchy Standard
(There is also an RPM on the File Hierarchical Standard – e.g., fhs.rpm included on many of the CDROMs.) - http://www.atnf.csiro.au/~rgooch/linux/docs/devfs.html – Linux Devfs (Device File System) FAQ by Richard Gooch
Copyright © 1997-2003 Henry White. All Rights Reserved.
Reproduction or redistribution without prior written consent is strictly prohibited. Address comments and inquiries to info@basiclinux.net.
Sorry, comments for this entry are closed at this time.