|
Introduction to Unix Shell Commands |
A 'How To' Guide for the Nanopublisher |
When you first login on to a Unix or Linux system you are given a command interpreter, known as your shell. There are different types of shells. The two most common shells are bash and tcsh (referred to as the T-C-Shell). You can determine which shell you are using by running the command “echo $SHELL”. If you are running the wrong shell, simply type the name of the desired shell as a command into your current shell. To permanently change your login shell, use the command chsh (change shell). For simple commands, both bash and tcsh behave the same. The instructions given below are suitable for either.
When the shell first starts up, it gives you a prompt, indicating that it ready for you to type in a command. Commands are generally given on one line, and start with the name of the command or program to run. Most everything else on the line is treated as an argument for the command or program.
| ls | list contents of current directory |
| ls dir | list directory dir |
| rm file | remove or delete file |
| rm r dir | remove or delete dir and all of its contents (careful with this one) |
| vi file | edit file using the vi text editor |
| cp file1 file2 | copy file1 to file2. If file2 already exists, it is overwritten. |
| cp file1 file2 … dir | copy files to dir |
| mv file1 file2 | rename file1 to file2 |
| mv file1 file2 … dir | move files to dir |
| cd dir | change directory (make dir the current working directory). |
| cd | Takes you to your home directory. |
| cd .. | Takes you to the parent of the current directory. |
| pwd |
print the name of the current working directory |
| mkdir dir |
makes a new directory dir |
| rmdir dir | removes a directory dir (directory must be empty) |
| less file | displays contents of file one screenful at a time (less is a replacement for more, which was named after the prompt that it printed after is displayed each page) |
| clear | clear the screen |
| lpr file | print file on printer |
| gcc file.c | compile c program |
| g++ file.cc | compile c++ program |
| gdb prog | run debugger on prog (must be compiled with -g flag) |
| a.out | run compiled c++ program (assuming the compiler use the default name of a.out for its output, otherwise use the chosen output file name) |
| make | make your program (make uses makefile to define what files make up your program, makefile should contain “executable : file1.cc file2.cc …” where executable will be name of executable (takes place of a.out) and file1 … are the names of the c++ files. There must be a tab between the name of the executable and the colon.) |
| man cmd | prints reference manual page describing cmd |
hit tab while entering a command to complete file or directory names.
type ^p (control p) or up arrow key repeatedly to step through previous commands, then hit enter to execute after possibly editing command using arrow keys.
type ^n (control n) or down arrow key repeatedly to step through later commands, then hit enter to execute after possibly editing command using arrow keys.
type ^r (control r) and then the beginning letters on a previously entered line to bring back that line.
Add “> file” to the end of a command to send the output of the command to file
Add “| cmd” to the end of a command to send the output of the command to another command cmd.
Add --help to a command to print usage information for the command.
Use "man cmd" to the view the manual for a particular command cmd.
Use "man -k keyword" to find manual entries related to a particular keyword.
![]() |
![]() |
Any questions or comments on these notes can be directed to theNurds@nurdletech.com.
| Created and hosted by |
|||||||||||