login: Enter your username here password: Enter your password here
UNIX> passwd
UNIX> logout logs you out of the system --or-- UNIX> exit logs you out of the system
UNIX> cat > file Enter text and end with ctrl-D UNIX> vi file Edit file using the vi editor
UNIX> mkdir directory-name
UNIX> cat file display contents of file UNIX> more file page through contents of file
UNIX> diff file1 file2 line by line comparison UNIX> cmp file1 file2 byte by byte comparison
UNIX> chmod mode file1 file2 changes modes of file1 and file2 UNIX> chmod -R mode dir changes modes of all files in dir
u user (owner)
g group
o other (world)
+ add permission
– remove permission
r read
w write
x execute
As an example, chmod go-rwx foo.c removes read, write, and execute permissions for group and other on foo.c.
UNIX> ls list contents of directory UNIX> ls -a include files with "." (dot files) UNIX> ls -l list contents in long format (show modes)
UNIX> mv src-file dest-file rename src-file to dest-file UNIX> mv src-file dest-dir move a file into a directory UNIX> mv src-dir dest-dir rename src-dir, or move to dest-dir UNIX> mv -i src dest copy & prompt before overwriting
UNIX> cp src-file dest-file copy src-file to dest-file UNIX> cp src-file dest-dir copy a file into a directory UNIX> cp -R src-dir dest-dir copy one directory into another UNIX> cp -i src dest copy & prompt before overwriting
UNIX> rm file remove (delete) a file UNIX> rmdir dir remove an empty directory UNIX> rm -r dir remove a directory and its contents UNIX> rm -i file remove file, but prompt before deleting
UNIX> gzip file compress a file, replacing it with file.gz UNIX> gunzip file.gz uncompress file.gz, replacing it with file
UNIX> cd return to your login (home) directory UNIX> cd dir change to directory dir
UNIX> pwd display absolute path of working directory
foo.c if you currently are in the same directory as foo.c, you can access it like this pgms/foo.c if foo.c is located in /home/jruser/pgms/foo.c and your current directory is /home/jruser then you can give a relative path to the file /home/jruser/pgms/foo.c the full path to foo.c
~ Your home (login) directory ~username Another user's home directory . Working (current) directory .. Parent of working directory ../.. Parent of parent directory
UNIX> date display date and time
? single character wild card Example: UNIX> fo?.c would match foa.c, fob.c, foc.c, fo1.c, fo2.c, etc... * Arbitrary number of characters Example: UNIX> foo.* would match foo.txt, foo.exe, foo.png, foo.jpeg, etc...
UNIX> lpr file print file on default printer UNIX> lpr -Pprinter file print file on printer UNIX> lpr -c# file print # copies of file UNIX> lpr -d file interpret file as a dvi file UNIX> lpq show print queue (-Pprinter also valid) UNIX> lprm -# remove print request # (listed with lpq)
UNIX> command > file direct output of command to file instead of standard output (screen), replacing current contents of file UNIX> command >> file as above, except output is appended to the current contents of file UNIX> command < file command receives input from file instead of standard input (keyboard) UNIX> cmd1 | cmd2 "pipe" output of cmd1 to input of cmd2 UNIX> script file log everything displayed on the terminal to file; end with exit
UNIX> grep hello file show lines comtaining string "hello" in file UNIX> grep hello file1 file2 ... show lines containing string "hello" in any file in filelist UNIX> grep hello * show lines containing string "hello" in any file in the directory UNIX> grep -v hello * show lines not containing string "hello" UNIX> grep -i hello * show lines containing string "hello", ignoring the case
UNIX> finger user or UNIX> finger user@machine get information on a user UNIX> finger @machine list users on a machine UNIX> who list current users on the computer you are currently on
UNIX> alias runvim /usr/local/bin/vim will run /usr/local/bin/vim whenever you type in runvim
Previously typed commands can be recalled
UNIX> history show command history UNIX> !num repeat command with history number num UNIX> !str repeat last command beginning with string str UNIX> !! repeat entire last command line UNIX> !$ repeat last word of last command line
pid→Process IDentification number. See this section
job-id→Job identification number. See this section
UNIX> ps report processes and pid numbers UNIX> ps gx as above, but include "hidden" processes UNIX> jobs report current jobs and job id numbers
UNIX> press ctrl and z to suspend a process. Note that the process still exists
UNIX> mozilla & starts mozilla running in the background. Note that the browser window will still come up UNIX> mozilla UNIX> CRTL-Z [1]+ Stopped UNIX> bg starts mozilla, then suspends it, then starts it running in the background
UNIX> fg bring a job to foreground UNIX> fg %job-id foreground by job-id (see 7.2)
UNIX> CTRL-C press ctrl and c to kill a foreground process UNIX> kill -KILL 12345 kill process with process-id 12345
UNIX> man command-name display on-line manual pages UNIX> man -k string list one-line summaries of manual pages containing string