Unix Command Summary
For more documentation on a command, use the man pages. For example, for more information on ls, use the command man ls.
Contents
- cd --- change directory
- cp --- for copying files
- ls --- see what files you have
- less --- use to read and search files
- mkdir --- create directory
- mv --- for moving and renaming files
- emacs or gedit --- for editing files
- pwd --- find out what directory you are in
- rm --- remove a file
- rmdir --- remove directory
ls
Use ls to list the files in the directory (folder) you are in.
[bloggs@blue15 ~]$ ls
cd
Use cd to change directory. Use pwd to see which directory (folder) you are in.
[bloggs@blue15 ~]$ cd english
[bloggs@blue15 ~]$ pwd
/import/raid1-LG1/rhome/a/bloggs/english
[bloggs@blue15 ~]$ ls
novel poems
[bloggs@blue15 ~]$ cd novel
[bloggs@blue15 ~]$ pwd
/import/raid1-LG1/rhome/a/bloggs/english/novel
[bloggs@blue15 ~]$ ls
ch1 ch2 ch3 journal scrapbook
[bloggs@blue15 ~]$ cd ..
[bloggs@blue15 ~]$ pwd
/import/raid1-LG1/rhome/a/bloggs/english
[bloggs@blue15 ~]$ cd poems
[bloggs@blue15 ~]$ cd
[bloggs@blue15 ~]$ pwd
/import/raid1-LG1/rhome/a/bloggs
bloggs began in his home directory, then went to his english subdirectory. He listed this directory using ls, found that it contained two entries, both of which happen to be diretories. He cd'd to the diretory novel, and found that he had got only as far as chapter 3 in his writing. Then he used cd .. to jump back one level. If had wanted to jump back one level, then go to poems he could have entered cd ../poems. Finally he used cd with no argument to jump back to his home directory.
cp
Use cp to copy files or directories.
[bloggs@blue15 ~]$ cp foo foo.2
This makes a copy of the file foo.
[bloggs@blue15 ~]$ cp ~/poems/jabber .
This copies the file jabber in the directory poems to the current directory. The symbol "." stands for the current directory. The symbol "~" stands for the home directory.
To copy a whole directory use "cp -r"
[bloggs@blue15 ~]$ cp poems old_poems
This copies the entire directory poems and all it's contents to a directory old_poems. If old_poems doesn't exist it will be created and will be a copy of poems. If it does already exist then the behaviour is slightly different - a copy of poems is placed in the subdirectory old_poems/poems.
mkdir
Use this command to create a directory.
[bloggs@blue15 ~]$ mkdir essays
To get "into" this directory, do
[bloggs@blue15 ~]$ cd essays
To see what files are in essays, do this:
[bloggs@blue15 ~]$ ls
There shouldn't be any files there yet, since you just made it. To create files, see editors.
less
Less is a command used to read text files. For example, we could do this:
[bloggs@blue15 ~]$ less poems
The effect of this command to let you read the file "poems ". It probably will not fit in one screen, so you need to know how to "turn pages". Here are the basic commands:
- q --- quit less
- spacebar --- read next page
- return key --- read next line
- b --- go back one page
For still more information, use the command man less.
mv
Use this command to change the name of files and directories.
[bloggs@blue15 ~]$ mv foo foobar
The file that was named foo is now named foobar. If foobar is a directory then the file foo will be moved to that directory.
emacs and gedit editors
Use either of these commands to create and edit files.
[bloggs@blue15 ~]$ emacs my_file
This command displays a window in which you can view and edit the contents of my_file. If my_file doesn’t already exist, you can enter text in the window and create this file. Note that you must have an X-windows server installed and running on your machine before you can use the GUI version of these editors. If your local computer is a PC running Windows XP (or a related operating system) then we recommend that you install, and run Exceed. For the details of installing and running Exceed please see our ssh page. If you don't want to start a GUI and need a simple command line editor then nano is recommended.
While you can these editors within a GUI in an intuitive fashion, they also have many powerful features, eg. for searching for and replacing text , editing multiple files, which are worth getting to grips with if you have advanced editing requirements.
pwd
Use this command to find out what directory you are working in.
[blogg@blue15~]$ pwd
/import/raid1-LG1/rhome/a/bloggs
[bloggs@blue15 ~]$ cd homework
[bloggs@blue15 ~]$ pwd
/import/raid1-LG1/rhome/a/bloggs/homework
[bloggs@blue15 ~]$ ls
assign-1 assign-2 assign-3
[bloggs@blue15 ~]$ cd
[bloggs@blue15 ~]$ pwd
/import/raid1-LG1/rhome/a/bloggs
[bloggs@blue15 ~]$
Bloggs began by working in his "home" directory. Then he cd 'd into his homework subdirectory. cd means " change directory". He used pwd to check to make sure he was in the right place, then used ls to see if all his homework files were there. (They were). Then he cd'd back to his home directory.
rm
Use rm to remove files from your directory.
[bloggs@blue15 ~]$ rm foo
The first command removed a single file. Be very careful! As you can see the rm command does not prompt you for confirmation (it just does the deletions). Also there is no waste bin to retrieve files from. We may be able to restore deleted files from back up, however please don't rely on this.
rmdir
Use this command to remove a directory. For example, to remove a directory called "essays", do this:
[bloggs@blue15 ~]$ rmdir essays
A directory must be empty before it can be removed. To empty a directory, use rm.

News feeds