UNIX COMMANDS


File Commands

cat
Syntax: cat filename
Copies the contents of filename to standard output. If no files are listed, standard input is copied to standard output.

head
Syntax: head filename
copies the first ten lines of filename to standard output

tail
Syntax: tail filename
copies the last ten lines of filename to standard output

more
Syntax: more filename
copies one screenful of filename on standard output. Press spacebar to display another screenful, and q to quit.

ls
Syntax: ls -options filenames, ls -options directories
lists information about files and directories. If no argument is given ls lists the contents of the current directory. Options: a=all; l=long.

cp
Syntax: cp fromfilename tofilename
The above command copies the contents of fromfilename to tofilename in the current directory.
cp file1 file2 directory
this command copies file1 and file2 to the specified directory. Use . (period) to specify the current directory.

mv
Syntax: mv fromfile tofile
This command renames (moves) the fromfilename to tofilename in the current directory.
mv fromfile directory
This command moves the fromfile from the current directory to the specified directory.

rm
Syntax: rm file1 file2
erases file1 and file2

chmod
Syntax: chmod permissions filenames directories
changes the access previleges for files and directories to permissions e.g.,
chmod ugo+rwx file1
This command adds read (r), write (w), and execute (x) previleges to user (u), group (g), and all others (o) for file1.


Directory Commands

cd
Syntax: cd dir
changes directory from the current directory to dir. If no directory is specified the current directory is changed to the user's home directory.

mkdir
Syntax: mkdir dir
creates a directory named dir under the current directory.

rmdir
Syntax: rmdir dir
erases the dir directory. Note it will only erase an empty directory.

pwd
Syntax: pwd
displays the current directory on the standard output.


vi Editor Commands

vi
Syntax: vi filename
loads filename into buffer for editing. If filename does not exist then a new file named filename is created.

ZZ
Syntax: ZZ
saves the contents of the edit buffer to file invoked with the vi command, and quits. The command :wq also will do the same.

:q
Syntax: :q
will quit from the buffer without saving the file. If changes have been made to the file in the buffer during the edit session, you must use :q! to quit without saving.

:w
Syntax: :w
writes to file which was invoked with the vi command.

i
Syntax: i
change to insert mode. Type i anywhere within the file in order to insert new data. i allows you to insert data before the current cursor position. To insert data after the current cursor position type a (lowercase a).

ESC/PF11
Syntax: ESC (press the escape key) or PF11
change to command mode. You must be in the command mode in order to make any changes other than inserting new data into the file.

o
Syntax: o (lowercase o)
inserts a new line after the current lineand toggle into insert mode. An O (uppercase O) will insert a new line before the current line and toggle into insert mode.

Deleting Characters and Lines, Moving Lines, and Copying Lines

x
Syntax: x (lowercase x), nx
nx will delete n characters starting from the current cursor position. x is interpreted as 1x.

dw
Syntax: dw, ndw
ndw will delete n words starting from the word at the current cursor position. dw is interpreted as 1dw.

dd
Syntax: dd, ndd
dd will delete the current line. ndd will delete n lines, starting with the current line.

P
Syntax: p, P
p (lowercase p) will paste the last deleted line(s) or character(s) after the current line or character. P (uppercase P) will paste the last deleted line(s) or character(s) before the current line or character.

yy
Syntax: yy, nyy
yy will copy current line into a temporary buffer. This line may then be copied to another location in the file by using the p or P (paste) command. The command nyy copies n lines into the temporary buffer. These lines may then be pasted to some other location by using the p or P commands.

.
Syntax: . (period)
repeats the last command. Used frequently to copy a line repeatedly.

Other Commands

u
Syntax: u (lowercase u)
will undo the most recent change.

U
Syntax: U (uppercase U)
will restore the current line.

$
Syntax: $
positions cursor at the end of the current line.

^
Syntax: ^
positions cursor at the beginning of the current line.

w
Syntax: w
moves cursor (forward) to the end of the current word.

b
Syntax: b
moves cursor (backward) to the beginning of the current word.

G
Syntax: G (uppercase G), nG
nG positions cursor on the nth line, G positions cursor on the last line.




Back to BA 224 Syllabus

Document:
Local Date:
Last Modified On: