Results : UNIX |
| Thread / Author | Tags |
| Finding Files in Unix - rin2
| Unix,
Files,
Finding,
|
There are at least three ways to find files when you don't know their exact location:
* find
If you have a rough idea of the directory tree the file might be in (or even if you don't
and you're prepared to wait a while) you can use find:
$ find directory -name targetfile -print
find will look for a file called targetfile in any part of the directory tree rooted at
directory. targetfile can include wildcard characters. For example:
$ find /home -name *.txt -print 2>/dev/null
will search all user directories for any file ending in .txt and output any matching files
(with a full absolute or relative path). Here the quotes () are necessary to avoid filename
expansion, while the 2>/dev/null suppresses error messages (arising from errors such as not being
able to read the contents of directories for which the user does not have the right permissions).
|
| Finding Text in Files in Unix - rin2
| Unix,
Files,
Text,
Finding,
|
# grep (General Regular Expression Print)
$ grep options pattern files
grep searches the named files (or standard input if no files are named) for lines that match a given
pattern. The default behaviour of grep is to print out the matching lines. For example:
$ grep hello *.txt
searches all text files in the current directory for lines containing hello. Some of the more useful
options that grep provides are:
-c (print a count of the number of lines that match), -i (ignore case), -v (print out the lines that
don't match the pattern) and -n (printout the line number before printing the matching line). So
$ grep -vi hello *.txt
searches all text files in the current directory for lines that do not contain any form of the word
hello (e.g. Hello, HELLO, or hELlO).
If you want to search all files in an entire directory tree for a particular pattern, you can
combine grep with find using backward single quotes to pass the output from find into grep. So
|
| Handling Removable Media in Unix - rin2
| Unix,
Media,
Removable,
Handling,
|
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
$ cd /mnt/floppy
$ ls (etc...)
To force all changed data to be written back to the floppy and to detach the floppy disk from...
|
| Find UNIX Directory Structure - rin2
| Structure,
Directory,
UNIX,
Find,
|
The UNIX filesystem is laid out as a hierarchical tree structure which is anchored at a special
top-level directory known as the root (designated by a slash '/'). Because of the tree structure, a
directory can have many child directories, but only one parent directory. Fig. 2.1 illustrates this
layout.
To specify a location in the directory hierarchy, we must specify a path through the tree. The path
to a location can be defined by an absolute path from the root /, or as a relative path from the
current working directory. To specify a path, each directory along the route from the source to the
destination must be included in the path, with each directory in the sequence being separated by a
slash. To help with the specification of relative paths, UNIX provides the shorthand . for the
current directory and .. for the parent directory. For example, the absolute path to the directory
play is /home/will/play, while the relative path to this directory from zeb is ../will/play.
...
|
| Unix File Compression and Backup - rin2
| Backup,
Compression,
File,
Unix,
|
UNIX systems usually support a number of utilities for backing up and compressing files. The most
useful are:
tar (tape archiver)
tar backs up entire directories and files onto a tape device or (more commonly) into a single disk
file known as an archive. An archive is a file that contains other files plus information about
them, such as their filename, owner, timestamps, and access permissions. tar does not perform any
compression by default.
To create a disk file tar archive, use
$ tar -cvf archivenamefilenames
where archivename will usually have a .tar extension. Here the c option means create, v means
verbose (output filenames as they are archived), and f means file.To list the contents of a tar
archive, use
$ 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...
|