UNIX Reference Sheet

UNIX Reference Sheet

Navigation Commands (Doing stuff with Directories)

[j@ccbtl06 j]$ pwd Tells you where you are.
[j@ccbtl06 j]$ cd Change Directory (this command will bring you to your home directory)
[j@ccbtl06 j]$ cd ~ This command will also bring you to your home directory
[j@ccbtl06 j]$ cd .. Will bring you up one directory
[j@ccbtl06 j]$ cd ../.. Will bring you up two directory
[j@ccbtl06 j]$ cd / Will bring you to the root directory
[j@ccbtl06 j]$ cd directory_name/ Will bring you into directory_name
[j@ccbtl06 j]$ cd ./directory_name/ Will also bring you into directory_name
[j@ccbtl06 j]$ ls Lists the contents of your current directory (files and folders)
[j@ccbtl06 j]$ ls -l Lists the contents of your current directory along with details like permissions and size
[j@ccbtl06 j]$ ls directory_name Lists the contents of directory_name
[j@ccbtl06 j]$ mkdir directory_name Makes a sub directory in your current directory called directory_name
[j@ccbtl06 j]$ rmdir directory_name Removes EMPTY directory called directory_name

File Commands (Doing stuff with Files)

[j@ccbtl06 j]$ cp file_name file_destination_name Copies file_name to file_destination_name
[j@ccbtl06 j]$ cp directory_name/* . Copies every (*) file in directory_name to the current directory (.)
[j@ccbtl06 j]$ cp -r directory_name/* . Copies every (*) file and sub directory in directory_name to the current directory (.)
[j@ccbtl06 j]$ mv file_name file_destination_name Moves file_name to file_destination_name
[j@ccbtl06 j]$ rm file_name Removes file_name
[j@ccbtl06 j]$ more file_name Allows you to view the contents of file_name (Spacebar = PageDown, Ctrl+C = exit)
[j@ccbtl06 j]$ less file_name Better way to view the contents of file_name (You can use arrows to go up and down, Spacebar = PageDown, b = PageUp, q = exit, Less is more!)
[j@ccbtl06 j]$ tail -n # file_name Allows you to view the last # of lines in file_name
[j@ccbtl06 j]$ wc file_name Counts the number of lines, words and bytes (in that order) in file_name
[j@ccbtl06 j]$ grep "string" file_name Finds lines containing “string” in file_name and spits them out in the command terminal
[j@ccbtl06 j]$ grep "string" file_name > out_file Makes a file called out_file where it puts the lines containing “string” in file_name (> works with any command that outputs to the command terminal)
[j@ccbtl06 j]$ grep "string" file_name >> out_file Appends to out_file the lines containing “string” in file_name (>> works with any command that outputs to the command terminal)
[j@ccbtl06 j]$ tail -n 100 file_name | grep "string" Prints out lines containing “string” that are in the last 100 lines of file_name ( | takes the output of the command on the left and does the command on the right to it, also known as a pipe)
[j@ccbtl06 j]$ emacs file_name Opens up Emacs to edit file_name, it will create file_name if it doesn’t exist (See Below)

Some other useful commands

[j@ccbtl06 j]$ man command Gives you the manual on how to use commands
[j@ccbtl06 j]$ history Prints out the history of commands you’ve typed
[j@ccbtl06 j]$ ssh jay@ta.wustl.edu Lets you securely login on another server (you’ll be asked for a password)
[j@ccbtl06 j]$ scp jay@ta.com:./file_name . Lets you securely copy file_name in the home directory of another server to the current directory
[j@ccbtl06 j]$ scp file_name jay@ta.com:./folder_name/ Lets you securely copy file_name to folder_name of another server
[j@ccbtl06 j]$ chmod ugoa+wrx file_name Changes the premissions on file_name so that everyone (User, Group, Others, and All) has Write, Read, and eXecutable permission
[j@ccbtl06 j]$ chmod o-wr file_name Takes away write and read permissions for Others on file_name

Emacs commands

CTRL-X-S Save contents of file.
CTRL-X-C Quit emacs.
CTRL-X-F Open a new file without stopping and restarting emacs.
CTRL-V Scroll down one page.
ALT-V Scroll up one page.
CTRL-A Move to the beginning of the line.
CTRL-E Move to the end of the line.
ALT-< Move to the beginning of the file. (note: hold down shift to use arrow key)
ALT-> Move to the end of the file. (note: hold down shift to use arrow key)
CTRL-S Search for a string letter by letter. In other words, as you type the word you are looking for, emacs finds the letters as you type.
CTRL-S, Return Plain old search for a string.
CTRL-G Start command sequence over again. E.g., if you mess up by hitting CRTL-X-X by accident, hit CTRL-G to start over. CRTL-G is your friend. You can do it anytime.

Spelling mistakes? Something not clear? E-mail Jay at jgertz@genetics.wustl.edu
Last updated: Friday Jan 20, 2005 Created by Jay Gertz, 2005