Basic Unix Commands
Basic commands
There are a number of Unix commands which the user should become familiar with from the outset:
passwd This command allows you to change your login password. You are prompted to enter your current password, and then prompted (twice) to enter your new password. On Linux systems (Example: Forum and Gateway) passwords should exceed 6 characters in length, and contain at least one non-alphanumeric character (such as #, %, *, ^, [, or @ etc.)
cd This command, as in DOS, changes directories. You can use .. to represent the directory above the current directory. You can use ~ to represent your root directory (also called your home or top directory). Example: cd maindir to move into the maindir directory, cd .. to move to the directory above, or cd ~ to move to your root directory.
pwd This command tells you which directory you are currently working in. Your home directory is represented by the tilde ~ symbol. To go to your home directory from anywhere, type cd ~, however typing cd without the ~ also works on Linux systems.
ls This gives you a listing of all files in a directory. You can't tell which are files and which are directories.
ls -F This shows which files are text files (they have no special symbols at the end), which are directories (they end in a / character), and which are executables (they end in a * character). These symbols are NOT part of the file name.
ls -l "Long" format. Gives more details about files and directories in the current directory.
ls -a Lists "hidden" files in current directory (those starting with a . character).
ls -la Options may usually be combined. This particular combination would list both hidden and unhidden files in the long format.
mv The move command is how you rename files. Example: mv oldfile.txt newfile.txt
cp Allows you to copy one or more files. Example: cp myfile.c backup.c
rm Deletes a file. BE CAREFUL!! There's no "undelete" command. Example: rm janfiles.*
cat Sends the contents of a file to stdout (usually the display screen). The name comes from concatenate. Example: cat index.html
more Like cat but displays a file one page at a time. Example: more long_file.txt
wc Counts the number of lines, words, and characters in a file. Example: wc essay.rtf
tail -n Displays the last n lines of a file. Example: tail -n 5 myfile
head -n Displays the first n lines of a file. Example: head -n 5 myfile
mkdir Creates a new directory, located below the present directory. (Use pwd first to check where you are!) Example: mkdir new_dir
rmdir Deletes a directory. Example: rmdir old_dir
man The most important Unix command! It displays the manual pages for a chosen Unix command. Press [Enter] to advance one line, [Spacebar] to advance one page, and the [Q] key to quit and return to the Unix prompt. Example: man ls
man -k Displays all Unix commands related to a given keyword. Example: man -k date will list all Unix commands whose man pages contain a reference to the word date.
date Shows the current time and date.
logout or exit Terminates the current login session, (and returns you to your SSH client, if that is how you established the session originally).
The commands above are those you will use 90% of the time. However you should consult one of the Unix tutorials below if you need details of the use of a command not listed above.
I/O Redirection
< Input redirection. This allows you to take input from a file rather than stdin. Example: traz < text
> Output redirection. This allows you to send output to a file rather than stdout. Example: ls -l > listing
| Pipe. This allows you to connect stdout from one command with stdin of another. Example: ls -la | more
Editors
To create files on a Unix system you usually use a text editor.
There are two editors available on Hermes, they are: vi and nano. A full description of each can be obtained by reading the man page.
The nano editor (which is a clone of the editor included with the pine email program) on the other hand is extremely simple to learn and use, and for all of the text editing activities you will encounter in this subject, it is perfectly adequate. Type man nano for an overview, and then use the on-line help in the program itself, or use one of the pico tutorials below. Nano is a GNU clone of the program Pico created because the license is not a free software license.
Please note that e-mail should only be used to contact other users on the same machine. Since Hermes does not have a real IP address it is unable to recive mail from the rest of the world. You can still sendmail from Hermes to a real e-mail address if needed.
Unix tutorials
There are a number of excellent Unix tutorials on the Web, including:
* A Basic Unix Tutorial http://www.isu.edu/departments/comcom/unix/workshop/unixindex.html
* UNIXhelp for users http://www.cit.gu.edu.au/services/UNIXhelp/
* UNIX help searchable index http://www.mcsr.olemiss.edu/cgi-bin/unixhelp_search
* The Marshall Brain Tutorials - UNIX http://www.eos.ncsu.edu/help/tutorials/brain_tutorials/index.html
* FAQs for Unix - UAH/CS http://merlin.cs.uah.edu/resources/tutorials/faqunix.htm
* Jamming with UNIX http://www.acusd.edu/ac/help/?Jamming
Pico tutorials
We use Nano as our text editor, but it is a clone of Pico. These tutorials will still give info about using Nano.
The Web also has some quick introductions to the Pico editor:
* Pico Tutorial - USD http://www.usd.edu/trio/tut/pico/index.html
* PICO Tutorial - NCSU http://www2.ncsu.edu/ncsu/cc/pub/tutorials/pico_tutor/pico_intro.html
* Pico Text Editor - UOA http://www.ualberta.ca/HELP/editors/pico.html
* PICO tutorial - ISDS Duke http://www.isds.duke.edu/computing/unix/pico.html
Much of the information for this page was gained from:
Jeff Ash, Charles Sturt University
URL - http://magrathea.mur.csu.edu.au/~jash/intro-to-unix.html