SIMPLE UNIX COMMANDS
Here is a short introduction to unix
commands.
To obtain more information on a command type man command name.
Man stands for manual and gives you the pages of a manual on the
command.
To begin with a set of commands to look at files and
to find information on them.
To list the contents of a file... more filename
To list the end of a file... tail filename
To list the entire contents of a file at once... cat filename
To list the files in the current directory... ls
or ls | more
To list the files including invisible ones... ls
-a or ls -a | more
To list the files and their characteristics... ls
-al or ls -al | more
To copy a file... cp file1 file2
To move a file (i.e. rename it)... mv filename
newfilename
To delete a file... rm filename
In unix
the disk space assigned to a user can be divided up into directories. These directories are like folders in windows
and thus are useful for placing together a set of files that are related to
each other.
To make a directory... mkdir directoryname
To change directory... cd directoryname
To find one's current directory name... pwd
To copy a file to a directory… cp file directoryname/file
To move a file to a directory… mv file directoryname/file
Here are a few commands that may be of use.
To search a file for a given string of characters... grep
'string' filename
To list the processes running on the machine... ps
-ef | more
To list your processes running on the machine... ps
-ef | grep yourusername
To stop something you do not want anymore,
you will have to get the process number
by ps -ef... kill -9 processnumber
Vi editor
To alter the information in a file
(or to create a file with new data in it) you will use the vi
editor. This is not the most
sophisticated of editors, but it occurs on most unix systems.
One key thing to remember about vi is that it has two modes of operation. The input mode allows you to enter new
information into the file. To turn this mode off, press the esc key. The other mode allows you to move around the
file and alter the data or information that is already there.
To create a file or alter an existing file type vi
filename and then press return. Once in vi use the
following commands.
To insert text in the middle of a line, move the cursor to where you
want to insert then press i and type your text in.
Press the esc key to turn off insert mode.
To insert a new line between two lines press o with the cursor on the
line above. The esc key turns off the insert mode.
To move the cursor use the h j k l keys. h moves left, j down, k up and l right.
To delete some text put the cursor on the character to be deleted and
press x.
To delete a line, move to the line you want to delete and press d twice
(i.e.dd)
If you make a mistake (not in input) try typing u (for undo), it does
not always work,
but it is worth a try.
To leave the editor pess the shift key and
hold it down then type ZZ.
To abort out of the editor type :q!
To go to the top of a file type 1G (note it is captital
G)
To go to the bottom of a file type G (note it is capital G)
To go to a specific line number type :linenumber then press return.
To find a text string /string then press return.
To set line numbers :set line number then press
return
To replace one string by another between linex
and liney
:linex,lineys/string1/string2/cg then press return
XTERMINALS
to get an xterm...
xterm &
FILE TRANSFER
To transfer files to another machine (you will need the machine name or
the machine number)... sftp machine name/number
Then login to the remote machine at the prompt. To get a file type get
file name then press return or to put a file type put filename (followed by
return). mput and mget can be used to transfer more than one file with a
single command. You can use the cd command to change
directories on the remote machine.
REMOTE LOGIN TO ANOTHER MACHINE
To access another machine you can
ssh -l username machine name/number then press return.
You should then get a prompt for your password.
ALIAS
If you do not like the command as it is given you in unix then use the alias command to change it to what
you do like. For example you may use an abreviation
of a command rather than the full command name. Thus grep
could be made to gr by alias gr
'grep'.
FOR MORE INFORMATION
A possible source for more information on unix is
B.W.Kerighan and R.Pike
The Unix Programming Enviroment.