|
Navigating the File System (cd command)
|
| Function |
Command |
Example |
Notes |
| To move to your home directory |
Type cd and press Enter. |
|
No matter where you are in the file system, you can use the cd (change directory) command to get you back to your home directory immediately. |
| To move to a subdirectory of your own |
Type cd <path> and press Enter.
|
cd public
To change from your home directory to your public directory.
|
When you are changing directories down from your current working directory, it is not necessary to type the full pathname. |
| To move to another person's home directory |
Type cd <path> and press Enter. |
cd /afs/andrew.cmu.edu/usr11/juser |
In this example, the <path> is the full path of the other person's directory. |
| Tilde (~) |
| Function |
Command |
Example |
Notes |
| To abbreviate the pathname. |
Type cd ~<Andrew ID> and press Enter. |
cd ~juser
To change into juser's directory without typing in the full path name.
|
The tilde is helpful when you don't know someone's complete pathname, or when you just want to save typing time.
The tilde can be used with any UNIX command; however, you should never use the tilde in command files such as.login or in your preferences file. In these cases, the tilde may not be recognized and can prevent Andrew and UNIX from working properly for you.
|
| Where am I? (pwd) |
| Function |
Command |
Example |
Notes |
To "ask" UNIX which directory you are in.
|
Type pwd and press Enter.
|
|
|
| View directory contents (ls) |
| Function |
Command |
Example |
Notes |
View names of files and subdirectories in a directory.
|
Type ls and press Enter. |
|
The ls command does NOT list any dot files (i.e., files that begin with dot (.)
|
To list files with status information
|
Type ls -l and press Enter. |
|
The ls -l command lists the file name, its owner, date last changed, and size. Files that are directories are preceeded with a "d"; plain files have an -rw-.
|
| To easily view differences between files and directories. |
Type ls -F and press Enter. |
|
Directories will be listed with a "/." |
| To list ALL files, including Dot files. |
Type ls -a and press Enter. |
|
|
| Recursive file listing |
Type ls -R and press Enter. |
|
Lists the files in the current directory as well as those in the subdirectories. |
| Create Directory (mkdir) |
| Function |
Command |
Example |
Notes |
| Create a directory |
Type mkdir <directoryname> and press Enter. |
mkdir playground
To make a new directory called playground.
|
Once you've made the directory, use the ls command to verify. |
| Copy Files (cp) |
| Function |
Command |
Example |
Notes |
| To copy a file in the same directory. |
Type cp <file> <file.copy> and press Enter. |
cp resume resume.copy
To make a copy of a file named "resume" in the same directory.
|
|
| To copy a file into another directory. |
Type cp <file> <directory> and press Enter. |
cp resume private
To make a copy of a file named "resume" in the private directory.
|
|
| To copy a file into another user's account. |
Type cp <path> / <file> <path> / <file> and press Enter. |
cp ~juser/notes sample/notes.joe
To copy a file named "notes" from your friend Joe's account into your sample directory and name the file notes.joe.
|
|
| Move Files or Directories (mv) |
| Function |
Command |
Example |
Notes |
| To move a file to a new file in the same directory (i.e., rename a file). |
Type mv <file> <file2> and press Enter. |
mv notes.joe notes.working
To move a file named "notes.joe" to a file named "notes.working." In this case, mv is simply renaming the file.
|
The difference between mv and cp is that cp places a copy of the file in a new location without disturbing the original copy. The mv commands deletes the file from its old location after saving it in the new location. |
| To move a file to a new file in a different directory |
Type mv <file> <path> / <file> and press Enter. |
mv notes public/notes
To move a file named "notes" from your home directory into your public directory, while IN your home directory.
|
The mv command is also used to move directories. |
| Remove a File (rm) |
| Function |
Command |
Example |
Notes |
| To remove a file. |
Type rm <file> and press Enter. |
rm notes.working
To remove the file named "notes.working"
|
|
| Prompt remove |
Type rm -i and press Enter. |
|
To invoke a prompt before removing a file; waits for a "Y" or "N" response. |
| Remove a Directory (rmdir) |
| Function |
Command |
Example |
Notes |
| To remove a directory (that does not contain files). |
Type rmdir <directory name> and press Enter. |
cd [Enter]
rmdir sample
To remove a directory named "sample" which is a subdirectory of your home directory.
|
Because the "sample" directory is in a subdirectory of your home directory, you must first move to your home directory (cd). |
| To force removal of a directory that contains files. |
Type rmdir -r <directory name> and press Enter. |
|
Removes a directory even if it contains files. |