| Introduction to Basic Unix System Administration | ||
|---|---|---|
| <<< Previous | Access to the Unix system, to files and directories | Next >>> |
It is very important that you understand the way paths are referenced in Unix. If a given path starts with a slash, it can only point to one directory on the system. If not, it could be anywhere, because the pathname will then be relative to your current working directory.
In practice:
tille:~>pwd /nethome/tille tille:~>ls Desktop/ GNUstep/ Xrootenv.0 images/ nsmail/ web/ Documents/ Machines@ app-defaults/ imp/ office52/ www Emacs@ Mail/ clo/ mail/ training/ Fvwm@ Nautilus/ cv/ ns_imap/ verlanglijst tille:~>cd images/ /nethome/tille/images tille:~/images>cd /images bash: cd: /images: No such file or directory tille:~/images>pwd /nethome/tille/images tille:/>cd tille:~>pwd /nethome/tille tille:~>ls /usr/local/ Acrobat4/ bin/ etc/ info/ man/ sbin/ src/ bcast/ doc/ games/ lib/ netscape/ share/ tille:~>cd .. tille:/nethome>ls bram@ diane@ jo@ tille@ |
![]() | Note: see man cd, man pwd and man ls for more information or try the --help option with every command to get a short syntax overview. |
On most Linux systems, the locate command comes in very handy. The system indexes every file it contains once a day, usually at 1 o'clock in the morning, and serves the database containing this information to the locate command.
Use the command locate yourfile to find your lost file.
![]() | Pipe through grep and/or more if the listing is too long, see Chapter 7: Redirecting I/O. |
Since the locate database only gets updated once a day, recently added files (added after the last update) won't show up immediately.
find is the ancestor of locate. If locate is not available on your system, ask your system admin to install it and use find meanwhile. To perform a query for all JPEG images in your homedirectory, enter the command
find /home -name "*.jpeg" -print
grep comes in useful everywhere. It prints lines matching a given pattern.
A practical example below: to find out how to spell a word, grep it out of /usr/share/dict/words, the Unix dictionary:
tille:~>grep unnec /usr/share/dict/words unnecessarily unnecessary tille:~> |
The -v option to grep makes it display output lines NOT containing the searchstring.
The grep is often fed output from other commands, e.g. to search for a file or to make a long listing shorter. See Chapter 7.
![]() | See man find and man grep for more information. |
which file (or file filename on some systems) searches the user's entire searchpath as defined in the PATH or path (csh) environment variable and displays the location of the file if found.
| <<< Previous | Home | Next >>> |
| Access to the Unix system, to files and directories | Up | How Unix security works |