Unix File Management Quick Reference
Unix files are stored in a directory tree, and each user has a home
directory. The upper-most level of the file system is called root and is
referenced by the character "/". Under root are any number of
subdirectores, with user's home directory typically under /home or
/users; for example, /home/auser is the pathname of a user's home
directory. Files or other directories may be stored under the user's home
Changing your working directory
Type "pwd" to display your working directory, and type "cd" to change the
$ cd play
To return to your home directory from any location, type "cd" with no
pathname following it.
To see the files in a directory, use the ls command:
play prog1 work
If you have a new account and are logged in for the first time, ls will
display nothing and you'll see a new shell prompt. Some files are
normally hidden from view to ls -- to see these use the -a option:
$ ls -a
. .. .kshrc .exrc .profile play prog1
Filenames starting with "." are not displayed by ls unless the -a option
is used: ".." refers to the parent directory (the one above the current
working directory); "." is the relative name for the current working
directory; .profile and .kshrc contain commands automatically executed
when you login; and .exrc contains commands automatically executed when
you run the ex or vi editors. Note that other Unix shells may use
different system files.
To see the types of files displayed by ls, use ls -F as shown below:
$ ls -F
play/ prog1* work
Directories are listed with a "/" at the end of their names, and
executable programs are listed with a "*" at the end.
Seeing inside files
Use the command more to view a fileÕs contents:
$ more work
This file is a very short one to show how
more does it's work.
At the --More-- prompt, press the space bar to see the next screen's worth
of the file. If more is not on your system, try pg.
Files are usually created with an editing program; see the Quick
Reference handouts on vi and Emacs for information about these.
Copying and moving files
Use cp to copy a file to a new one, and use mv to change a file's name
$ cp work morework
$ mv morework lesswork
Use rm to remove a file from your directory:
$ rm lesswork
Caution: be very careful using rm -- there is usually no easy way to
recover files removed with it.
Creating and removing directories
Use mkdir to make directories in your home directory, and use rmdir to
remove those directories:
$ mkdir newstuff
$ ls -F
newstuff/ play/ prog1* work
$ rmdir newstuff
Note that rmdir will remove directories only when they are empty!
See the man pages for the commands discussed above.
See the Quick Reference handouts for the vi and ex editors and the Emacs