Unix/Linux Command Reference

Last modified: 2008.08.27 by Abe Pralle


General
 ssh username@unix.cefns.nau.edu Creates a secure shell "telnet" connection to the specified Unix host computer and with the given username. The rest of the commands in this document assume that you have established such a connection or that you're already on a Unix-like system. On Unix, Linux, and Mac OS X you can run this command from the terminal window (on Mac OS X you can start a terminal window by running Applications→Utilities→Terminal. On Windows you can download and run the PuTTY program that can SSH to a computer instead of typing an "ssh" connection command.
 passwd Allows you to enter a new password.
 man cmd (Manual page) Displays help text on any Unix command. E.g. "man passwd".
 exit Logout from PuTTY or close terminal window on workstation.


Directories
 ls Lists the contents of the current directory.
 ls -l (ls dash L) Lists files with more detailed information.
 pwd (Print Working Directory) Prints the name of the current directory.
 mkdir newdir Creates a new directory inside the current directory.
 cd newdir Changes the current working directory to the specified location.
 pushd newdir Like a "cd" except it saves the old directory address.
 popd "cd's" to the directory remembered by "pushd".


Files
 vim filename Starts editing a new file called "filename". See the Vim Command Reference.
 mv old new MoVes (renames) a file from its old (current) name to a new name.
 cp old new CoPies a file - makes a duplicate of old and calls it new.
 rm filename ReMoves a file, erasing it permanently.
 rm -r dir Removes the named directory and all files and subdirectories within. Highly dangerous. Use with caution.
 cat filename Lists a text file to the screen. "cat -n" lists line numbers.
 more filename Lists a text file to the screen, pausing after every screenful.
 sftp username@unix.cefns.nau.edu Opens a secure file transfer protocol connection to a specified host computer and with the given username. This lets you upload and download files between your local computer and the specified remote host computer. Unix, Linux, and OS X can run this command directly. Windows users should download PSFTP and save it to their C:\WINDOWS or C:\WINNT directories so that it can be run from the command line. Note: easier-to-use, click-and-drag version of SFTP are described further below. Once you're connected you can use the following commands:
 pwd (Print Working Directory) Print the current directory on the remote host computer that file transfers will go to or from.
 lpwd (Local PWD) Prints out the name of the directory on your local computer that file transfers will go to or from.
 cd newdir Changes the current directory on the remote host computer.
 lcd newdir Changes the current directory on your local computer. Note that on Windows you can type "lcd", a [SPACE], and then drag the desired folder into the terminal window to have Windows type out the directory name for you.
 ls Lists the contents in the current directory of the remote host computer.
 put filename Uploads "filename" from your local current directory to the remote host computer's current directory.Use "mput wildcard-pattern to upload multiple files at once.
 get filename Downloads "filename" from the remote host computer's current directory to your local current directory. Use "mget wildcard-pattern to download multiple files at once.
 bye Log out and shut down your sftp connection.
 Miscellaneous You can also move, rename, delete, and chmod files and folders. Type "help" to see a list of all commands.
GUI-Based SFTP Programs There are several SFTP programs that have a Graphical User Interface and are much easier to use that the command-line SFTP. For Windows there's WinSCP available here as well as "Secure File Transfer Client" on the START→Internet Applications menu of Engineering lab computers. For Mac there's Cyberduck. Remember that you need to connect to "unix.cefns.nau.edu"; the rest should be fairly self-explanatory.


Miscellaneous
 CTRL+C Terminates execution of the current program. Works with most programs.
 date Gives you the time and date.
 a2ps filename Prints a file to the default printer in room 106.. SEE NEXT COMMAND!
 cancel -u userid If you print the wrong thing you may end up with dozens of pages of garbage. To stop the printer from printing this garbage and wasting paper use the cancel command. For example, if I were going to stop my printer commands I would type "cancel -u ap27".
 !v Repeats the last UNIX command you typed that started with "v"
 !! Repeats the very last Unix command you typed.
 chmod Changes the permissions of who can access your file. Necessary to make html files visible on the web in your /www/yourlogin directory.
Usage: chmod [u/g/o/a] [+/-] [r/w/x]
Who it affects: u=user=you, g=group, o=others, a=all
+/- = add or remove permission to: r=read w=write x=execute the file.
For example, "chmod a+rx filename" adds read and execute permission to all users for the file "filename".
 grep abc *.txt Prints out all lines that contain the word "abc" in all files that end with ".txt"
 prog1 | prog2 Takes the output that would have printed out from "program one" and sends it to be the input that would have been read from the keyboard in "program two". E.g. "ls | grep java"
 prog > temp.txt Saves what the program "prog" would have printed out into the file "temp.txt". E.g. "java Driver > results.txt".
 prog < temp.txt Whenever "prog" tries to read input from the keyboard, it reads from the contents of the file "temp.txt" instead. E.g. "java Driver < data.txt".


Advanced
 ps -u userid Lists all the processes running that are owned by you (i.e. all your programs that are running). A process ID number is listed next to each one.
 kill 1234 Asks process number 1234 to shut down (e.g. terminates the program).
 kill -HUP 1234 Forcefully kills process 1234 - use if the normal kill doesn't work. Example: Your Sun workstation won't let you log out (a bug that pops up every once in a while). You type: "ps -u yourid". Find the process that says XServer or something similar, then "kill -HUP xserverID". And presto, everything shuts down and you're logged out!
 CTRL+Z Suspends (pauses) execution of the current program or "job". Works with most programs.
 jobs Lists the programs you have running, whether suspended or active. Is similar to the "ps" command, except it lists the jobs using numbers that can be used with the "fg" command.
 fg Resumes a program (to the "foreground") that was suspended with CTRL+Z. You can use the number you got from "jobs" to pick one ("fg %1", "fg %2") or just "fg" by itself to resume the most recently suspended one.
 bg Works like fg, except the resumed program starts running concurrently in the "background" (i.e. multitasking). You can do other things, but any output from the background job will print out to the screen. Good for long calculations or searches.
 program & Runs "program" as a background job.