Chapter 2 Linux File System
Chapter 2 Linux File System
$ cd path
changes your current working directory to path (which can be an
absolute or a relative path). One of the most common relative
paths to use is '..' (i.e. the parent directory of the current
directory).
Used without any target directory
$ cd
resets your current working directory to your home directory
(useful if you get lost).
If you change into a directory and you subsequently want to
return to your original directory, use
$ cd -
mkdir (make directory)
$ mkdir directory
creates a subdirectory called directory in the current working
directory. You can only create subdirectories in a directory if
you have write permission on that directory.
rmdir (remove directory)
$ rmdir directory
removes the subdirectory directory from the current working
directory.
You can only remove subdirectories if they are completely
empty (i.e. of all entries besides the '.' and '..' directories).
cp (copy)
cp is used to make copies of files or entire directories. To copy
files, use:
$ cp source-file(s) destination
where source-file(s) and destination specify the source and
destination of the copy respectively. The behavior of cp depends
on whether the destination is a file or a directory. If the
destination is a file, only one source file is allowed and cp makes
a new file called destination that has the same contents as the
source file. If the destination is a directory, many source files
can be specified, each of which will be copied into the
destination directory.
To copy entire directories (including their contents), use a recursive copy:
$ cp -rd source-directories destination-directory
mv (move/rename)
mv is used to rename files/directories and/or move them from one
directory into another. Exactly one source and one destination must be
specified:
$ tar -tvf archivename
To restore files from a tar archive, use
$ tar -xvf archivename
cpio
cpio is another facility for creating and reading archives.
Unlike tar, cpio doesn't automatically archive the contents of
directories.
So it's common to combine cpio with find when creating an archive:
$ find . -print -depth | cpio -ov -Htar > archivename
This will take all the files in the current directory and the
directories below and place them in an archive called archivename.
The -depth option controls the order in which the filenames are
produced and is recommended to prevent problems with directory
permissions when doing a restore. The -o option creates the
archive, the -v option prints the names of the files archived as they
are added and the -H option specifies an archive format type (in
this case it creates a tar archive).
Another common archive type is crc, a portable format with a
checksum for error control.
To list the contents of a cpio archive, use
$ compress filename
or
$ gzip filename
In each case, filename will be deleted and replaced by a
compressed file called filename.Z or filename.gz.
To reverse the compression process, use:
$ compress -d filename
or
$ gzip -d filename
2.14. Handling Removable Media (e.g.
floppy disks)
UNIX supports tools for accessing removable media such as CDROMs
and floppy disks.
mount, umount
The mount command serves to attach the filesystem found on some device
to the filesystem tree.
Conversely, the umount command will detach it again (it is very important to
remember to do this when removing the floppy or CDROM).
The file /etc/fstab contains a list of devices and the points at which they
will be attached to the main filesystem:
$ cat /etc/fstab
/dev/fd0 /mnt/floppy auto rw,user,noauto 0 0
/dev/hdc /mnt/cdrom iso9660 ro,user,noauto 0 0
In this case, the mount point for the floppy drive is /mnt/floppy and the
mount point for the CDROM is /mnt/cdrom.
To access a floppy we can use:
$ mount /mnt/floppy
Then you can do:
$ cd /mnt/floppy
$ ls (etc...)
To force all changed data to be written back to the floppy and to
detach the floppy disk from the filesystem, we use:
$ umount /mnt/floppy
RAIDS
Outline:
RAID 0
RAID 1
RAID 5
RAID 10
Performance
Storage space
Fault tolerant
What is RAID?
Stands for Redundant Array of Independent Disks.