uzix.{net,org}
· Home
· About me
· Photos
· cgvg
UNIX User Basics
Joshua Uziel - 1/17/99

(PDF version of this document with a vi editor overview as well, which was produced for a UCLA LUG tutorial I gave many moons ago.)

Getting Help

man - Look at manual page, do this to see almost any command's options - example: "man ls" - DO THIS WITH MOST OF THESE COMMANDS!!!

Listing and Moving Files and Directories

ls - LiSt files - "-a" lists all files, "-l" give a long DOS-dir-like output - example: "ls -la"

cp - CoPy - copy file(s) from one location to another - example: "cp *.c another_directory/"

mv - MoVe - move file(s) from one location to another, same as cp except it removes files afterwards

rm - ReMove - delete files - example: "rm *.o"

cd - Change Directory - example "cd /tmp"

mkdir, rmdir - MaKe DIRectory and ReMove DIRectory

ln - LiNk - make a link to a file - two types of links, normal and symbolic - example: "ln -s original newlink"

Special Directories - '.' is current, '..' is current's parent, '~' is home, and '/' is the root (or top) of all directories

Redirection and Shell Stuff

| - Pipe, one of UNIX's best features, used to send output from one program to be input to another - example: "ls -l | grep uzi"

>, >>, < - Redirect output of a program to a file, append output to end of a file, and get input from a file - example: "./a.out < input > ouput"

*, ? - Wildcards - used to specify any number (including zero) of any character for '*', and any one character for '?' - example: "ls *.?"

$var - An environment variable, where "var" is the name and a value can be seen using "echo $var"

set, setenv - used to set environment varibles, depending on shells.

Managing File Permissions

Sample "ls -l /bin/ls" output: -rwxr-xr-x 1 root root 29980 Apr 23 1998 /bin/ls
     - First ten characters are the file's permissions. First is file type, '-' for normal, 'd' for directory, 'l' for symlink, etc.
     - Three sets of three characters of "rwx", or Read, Write, Execute permission - first for owner, then group owner, then everyone.
     - Then we have number of links to file, owner of the file, group owner of file, file size, date it was last modified, and the file's name.

chmod - Change a file's mode or permissions - one way is to use octal numbering - example: "chmod 751 /bin/ls" for rwxr-x--x

chgrp - Change a file's group - example: "chgrp users /bin/ls"

chown - Change a file's owner - example: "chown uzi /bin/ls"

umask - Set default file permissions (generally, do the opposite, or "777 minus what you want")

Process Management

ps - Get a listing of running "processes" or programs - example: "ps -aux"

kill - Kill a running process - example: "kill -CODE PID", where CODE is an optional kill code, and PID is the process ID #.

& - Run a program in the background - example "netscape &"

CTRL-Z - Suspend a running program

CTRL-C - Kill a running program

fg, bg - Put a suspended program in the foreground or background

jobs - List running programs of this terminal - each has a number that can be refered to as %#, or %1 for number one (useful with fg, bg and kill)

nice - Make a program use less computer time

nohup - Let a program run after you log out (NO Hang-UP)

Viewing Text Files

cat - Concatinate and display files, used to output a file's contents without pausing - example: "cat textfile"

more - Like cat, but pauses every screen-full - example: "more prog.c"

less - Like more, but more powerful

head, tail - View the beginning or ending of a file, given a number option with display that many lines - example: "tail -25 /var/spool/mail/uzi"

wc - Get statistics of how many lines, words and characters in a file - example: "wc file.txt"

Searching and Comparing

find - Find a file, second argument is where to search from - example: "find . -name '*.c' -print"

grep - Look for text in a file - example: "grep variable *.c"

cmp - Compare two files - example: "cmp file1 file2"

diff - Output difference between two files - example: "diff prog.c.orig prog.c > prog.c.diff"

Printing - Depending on which Unix you're using (BSD type, SYSV type) is which you may be using

lpr, lp - Print a file -examples: "lpr -P printer file" or "lp -d printer file"

lpq, lpstat - Get statistics on a printer(s)

lprm, cancel - Cancel a print job

Finding and Communicating with other Users

finger - Get information on another user on the system - example: "finger uzi"

w, who - Find out who else is on a system

write - Write a message to a user (user CTRL-D to stop) - example: "write uzi"

talk - Talk to a user (CTRL-C to stop, and there's also "ytalk" which is an enhanced version) - example: "talk uzi"

mesg - Use "mesg y" or "mesg n" to allow or disallow others to write and talk to you

Remote Commands

telnet - Open a connection on another system - example: "telnet fire.csua.ucla.edu"

ftp - Retrieve files with the File Transfer Protocol - example: "ftp ftp.kernel.org"

rlogin - Similar to telnet, but if you have a ".rhosts" file with allowed machines, you can log in without a password

rsh - Also using ".rhosts", lets you run one command on another machine without logging in

rcp - Another that uses ".rhosts" and lets you copy files from another machine

Miscellaneous

alias - Aliases can be used to make a shortcut for a common command - example: "alias dir 'ls -l'" or "alias dir='ls -l'", depending on shell

at - Lets you have a program run "at" a certain time

crontab - Schedule regular programs to run at certain times (some let all users have their own crontab file)

cal - Print a calendar for a given month - example: "cal 8 1976" or just "cal" for this month

date - Print current time and date

df - Find out how much free disk space is available - example: "df -k ." for current directory in kilobytes

du - Find out disk usage of a file or directory - example: "du -ks ~" for size of your entire home directory

echo - Repeats or echoes the argument - example: "echo hello" prints "hello"

tar - Tape ARchive - allows you to pack many files together - example: "tar -xvf file.tar" to extract

gzip, gunzip - Compress or uncompress *.gz files - example: "gzip file.tar"

passwd - Change your password on a system

spell - Spellcheck a text file against system dictionary - example: "spell paper.txt"

sort - Sort contents of a file

time - Get runtime of a program - example: "time ls -l"

uname - Get info on a machine - example: "uname -a"

uptime - Get how long a machine has been up

which, whence, where - File out which program you'll be running, or where all occurences of a program is in your path - example: "which ls"

vi, pico, emacs, jed, joe - Text editors

pine, elm, mutt, mailx, mail - Email programs


unixbasics.html last modified July 11, 2003
Questions? Comments? Email me at uzi@uzix.org