Recent Changes - Search:




Main.FreeBSD History

Hide minor edits - Show changes to output

December 13, 2012, at 09:37 PM by -
Added lines 13-1611:

'''Useful FreeBSD/UNIX commands from'''


pwd Present Working Directory
uptime Server UpTime stats & operation
df D_isk F_ree space
w W_ho is logged on & server info
who WHO is logged on and IP address
last LAST users logged on and statuses
ac ACcounting of total time logged on
top TOP processes currently executing listed per CPU time
ps aux
ps ax
uname -a
env Shows current environment variables, including user & path
cd Change the Directory that you are working in
man Show the MANual pages for a program
tail -300 maillog Show the TAILend of the 'maillog' file -- last 300 lines
kill -9 PID KILLs a specific process # (PID), non-catchable, non-ignorable (-9)
shutdown -r now ShutDown the computer, then reboot, immediately
vmstat -w 5
vmstat boot
more Display a file, showing a page at a time. Show MORE by hitting 'space'.
ls -lt LiSt (-l with L_ots of info) (-t sort by time)
ls -laTFWi LisT all info
FIND (starting in root dir) "nameoffile" or anything begining with that
find / -name "nameoffile*"

FIND files modified within last day:
find / -mtime -1 -print
FIND files modified over 5 days ago:
find / -mtime +5 -print

users Shows which users are logged on using shell / command line

Backs up a file, preserving date/time stamp:

mv hosts.allow hosts.allow-2005-Apr-16
cp hosts.allow-2005-Apr-16 hosts.allow

Compress a log file, then mail as an attachment
gzip -c access_log.processed -v > access_log.processed.gz; ls -lt
uuencode access_log.processed.gz | mail -s " Log File"
Or inline:
mail -s "Some Text File" < file.log

ls -laTFWiR LiSt files with all info R = recurse subdirs. Takes 3 hours!
chown userowner somedirectory
Change the owner to 'userowner' of directory 'somedirectory'
Show brief statistics about qmail
Show the summary info for EACH email in qmail queue
pkg_info List the packages installed
pkg_add Add a package
ftp connects to ftp site
'get' gets a file
'cd' changes a directory
Ctrl-C Cancel operation
Ctrl-S PauSe operation
Alt-F1 Alternate to the 1st terminal window when using 'shell'
Alt-F2 Alternate to the 2nd terminal window when using 'shell'


Unix Commands and Editors

Prof. L. N. Long
AERSP 497B / 597C

Sources of Material


* "Running Linux" by Welsh, Dalheimer, and Kaufman, 3rd Edition,
(Chap. 1)

* A few internet sites



A Few Preliminary Words About Unix Commands


* Unix is case sensitive. LS won't work, but ls will...

* You can get by with a very small number of commands, and look up
the other ones that you need later on.

* You should not be logged in as root any more than you have to. It
is dangerous (e.g. you could delete some important files by
mistake) and it is not secure (e.g. if you walk away from your
desk, someone could take complete control of your machine).

* Everything in Unix is a file (including devices)

* Most of the commands that the average user uses are the same on all
Unix systems (e.g. Solaris, AIX, HPUX, IRIX, Linux, ...), but the
system files and system commands can be quite different in the
various flavors of Unix. [so while Unix System Administrators argue
over which Unix is the best, to the average user they all look very


Top 10 List of Commands


This is the unix help command. To get help you also sometimes need
to know the command name. For example, you could type

man passwd

But you can also do keyword searches if you don't know the exact
name of the command you want information on, for example :

man -k password

The info for these help commands are stored in the"manpages"

This command COPIES files. For example

cp file.dat new.dat

Or to copy all the files in one directory to the current directory:

cp ../mydir/* .

.. means to go up one level in directories.
. means current working directory. To copy all the files in the
current directory to another directory:

cp * ~/filedir/

~ will take you to your home directory.
Note that the above command WILL NOT copy files that begin with a

Lets you view a file on the screen, for example

more file.dat

(use the space bar to page thru the file). Look also at the cat
command, which is similar.

This LISTS files in a directory. Most often you would type 'ls -l'
. The "-l" key gives all file details. Also, the -a option will
show all files that begin with "." Also, "ls -lt" will sort the
files according to date/time.

ls -lt | more

will "pipe" the output of "ls -lt" to the more command, so you can
view it one page at a time.

This makes a directory just like in DOS, e.g.

mkdir newdir


cd newdir

Typing just "cd" will take you to your home directory. (note to go
up one directory do: cd ..) What does this do:

cd .

Tells you which directory you are currently in (print working

removes (deletes) a file, e.g.

rm file.dat

(you might want to use "rm -i" for safety, which will cause it to
prompt you before deleting it.). Be very careful here, especially
with wildcards such as "*". The command:

rm *

would erase all files in the current directory (except those
starting with ., and files you do not have permission to erase).

The following is an extremly dangerous command. If you have root
privilege, this could delete all files from the entire machine:

rm -r /*

The -r tells it to recursively delete all subdirectories !!

One of the original Unix editors. Available on basically all Unix
machines, so it is important to know the basic vi commands.

This moves a file (sort of like renaming it), for example

mv oldfile.dat newfile.dat

Some Other Key Commands


removes a directory

If there are long strings of commands that you type often, you can
create an alias for them. For example,

alias godir 'cd ~/myfiles/temp'

Standard unix mail program (note that mail and Mail do different
things sometimes)

Menu driven mail program. very handy.

f77 (or f90 or pgf90 or xlf90 )
Fortran compiler command. e.g.

f77 test.f -o test

puts the executable into "test". To run the program you then just
type "test" .

cc or gcc
c compiler, e.g.

gcc myprog.c -o myexec

Changes your password.

Shows jobs running on the system. e.g.

ps -aef

Shows jobs running on the system. (you can use "kill %1" to kill
job number 1). You can use "fg %1" to bring job 1 into the
foreground. (ctrl c will kill current process, ctrl z will put
current process in background)

Prints a file. To print to the 315 Hammond Postscript printers, use

lpr -Pps

(sometimes it is lp instead of lpr) (use lpstat or lpq to check the
status of the print job)

Shows who is currently on the system. (see also 'who')

"control" c
Kills your current job

"control" z
Suspends you current job. bg then puts it in the background, or fg
brings it back into the foreground. "jobs" will display them.

Some More Key Unix Commands
(be careful. some of these commands have no effect if your file system
uses AFS or DFS !!)


Checks disk usage, e.g.

du -k

shows amount of space left on all the disk drives, e.g.

df -k

quota -v
Shows your quota and your current usage of disk space. Be careful,
some systems that use afs or dfs might not use this command for
quotas, so it might give you misleading info. (to check your quota
on an AFS system, use "fs lq" )

used to change the protection on your files. To not allow anyone to
read, write, or execute your files, do

chmod 700 *

To give other people read and execute privelege do

chmod 755 *

Again, be careful, if your system uses DFS or AFS then this will
have NO effect !

This lets you change the ownership of a file, e.g.

chown joe file.dat

where joe is your userid

to search thru files to see if the expression 'exp' is contained in
those files do:

grep exp file.dat

You could search thru all the files in a directory using:

grep exp .

This will compare two files and tell you where they are different,

diff file1.dat file2.dat

This will search the disk drives for a particular file, e.g.

find . -name file.dat -print

will start searching in the current director (.) for a file called
'file.dat' and it will print to the screen.

This is a very powerful and useful command, it lets you create
links between files, e.g.

ln -s file1.dat file2.dat

will create a new file called 'file2.dat' which simply points to
'file1.dat'. This is also useful for directories.

Finds the location of an executable file (e.g. which more)

Shows the first few lines of a file (e.g. head file.dat)

Shows the last few lines of a file (e.g. tail file.dat)

xclock, xcalc, xgraph
Useful X-windows routines

Sets the priority of a job (e.g. nice +6 myjob). The higher the
number the lower the priority (and the 'nicer' you are to others)

Turns on scripting to record everything that happens in a login
session (e.g. script myrecord). If you just type script, then the
results are stored in a file called typescript. To stop recording
type 'exit'

Uncompresses files such as files.dat.Z (e.g. uncompress

archiving utility


A standard unix editor. my prefered choice.

A standard unix editor. Available on virtually ALL unix machines.
Some people use this a lot, others use it just for editing small files
quickly. (see also vim)

A simple X-windows editor (will not work from a dumb terminal)

The vi editor

To start vi :

vi filename

where filename is the name of the file you wish to edit.

A few vi commands

* h, moves cursor left
* j, moves cursor down
* k, moves cursor up
* l, moves cursor right
* x, delete character
* dw, delete word
* dd, delete line
* p, put last deletion after cursor
* u, undo last change
* i, turn on insert mode (hit the esc key twice to stop)
* :wq, write file and quit
* :q!, quit without saving file
* ctrl f, move forward one page
* ctrl b, move backward one page
* /text, will search for next occurance of 'text' (hitting n will
find next occurence)
* G, go to end of file
* 1G, go to first line of file




* GNU Emacs emacs is an incredibly powerful editor. It is almost an
operating system. You can do the standard cut & paste, but you could also
read your mail in it. It can also show two files at once using a split
screen. Incidentally, I wrote this document (and almost all my documents)
using emacs.

emacs can be used in X-windows (you need to understand 'setenv DISPLAY'
and 'xhost') OR you can use it on a 'dumb terminal'. To run emacs on a
dumb terminal (or inside a unix shell), you may want to enter 'emacs -nw'
instead of just 'emacs'.

emacs relies on 'control' or 'meta' commands. These are intimidating at
first, but are really quite simple. For example


means hold down the 'Ctrl' key and then hit the 'a' key. This will put the
cursor at the start of a line. Some commands require you to use the 'meta'
key. The meta key on most key boards will be the 'Esc' key.

Once emacs is running you can just start typing. Or you can read in a file
by tpying:

ctrl-x ctrl-f

and it will then ask you to enter a filename.

The following keystroke combinations are some of the ones


Ctrl-a Beginning Of Line Meta-b Backward Word

Ctrl-b Backward Character Meta-f Forward Word

Ctrl-d Delete Next Character Meta-i Insert File

Ctrl-e End Of Line Meta-k Kill To End Of Paragraph

Ctrl-f Forward Character Meta-q Form Paragraph

Ctrl-g Multiply Reset Meta-v Previous Page

Ctrl-h Delete Previous Character Meta-y Insert Current Selection

Ctrl-j Newline And Indent Meta-z Scroll One Line Down

Ctrl-k Kill To End Of Line Meta-d Delete Next Word

Ctrl-l Redraw Display Meta-D Kill Word

Ctrl-m Newline Meta-h Delete Previous Word

Ctrl-n Next Line Meta-H Backward Kill Word

Ctrl-o Newline And Backup Meta-< Beginning Of File

Ctrl-p Previous Line Meta-> End Of File

Ctrl-r Search/Replace Backward Meta-] Forward Paragraph

Ctrl-s Search/Replace Forward Meta-[ Backward Paragraph

Ctrl-t Transpose Characters

Ctrl-u Multiply by 4 Meta-Delete Delete Previous Word

Ctrl-v Next Page Meta-Shift Delete Kill Previous Word

Ctrl-w Kill Selection Meta-Backspace Delete Previous Word

Ctrl-y Unkill Meta-Shift Backspace Kill Previous Word

Ctrl-z Scroll One Line Up

ctrl-x ctrl-f Read File

ctrl-2 split screen

ctrl-1 single screen


You can order printed copies of the GNU Emacs Manual for $20.00/copy
postpaid from the Free Software Foundation, which develops GNU software
(contact them for quantity prices on the manual). Their address is:

Free Software Foundation 675 Mass Ave. Cambridge, MA 02139

Your local Emacs maintainer might also have copies avail- able. As with
all software and publications from FSF, everyone is permitted to make and
distribute copies of the Emacs manual. The TeX source to the manual is
also included in the Emacs source distribution.

* Emacs Commands



* Click here for info on makefiles

* Click here for sample makefiles


Networking Commands

Lets you connect to another computer and copy files back and forth.
(e.g. "ftp") Once you get connected, you use the
"get" and "put" commands. You can also type "help" for a list of more
commands. 'prompt' will toggle prompt on and off. 'mget' will let you
get a huge list of files (multiple get). 'bin' and 'asc' will tell it
whether you are transferring binary or ascii files, respectively.

This allows you to connect to another computer and run programs on
it. (e.g. "telnet") For security reasons, most people
use ssh instead of telnet now.

setenv DISPLAY
This command is crucial for using Xwindows. When you use telnet to
connect to a remote computer, you have to telnet that computer where to
display the Xwindows. That is what this command does. (e.g.

setenv DISPLAY

The ":0" tells it to use monitor number 0. In this example, farman is
the machine you are physically sitting at. On the local machine you may
also have to type

xhost remote-machine-name

which lets the other machine (named remote-machine name) send images to
your machine.

this command lets you control what other computers can send
Xwindows images to your computer. It is used as: "xhost" (which would give the remote computer (cupcake) the
ability to display Xwindows images on your computer. The command "xhost
+" lets ANY computer send Xwindows images to your computer, this is very
dangerous and a unix/network security problem. You should NOT use xhost

As we discussed earlier, this is used to configure your network

This command lets you add and delete network routes, and gateways

This will show you what route your packets are taking from your
local machine to some remote machine, e.g.


Commands for Working with Files




more (or cat)






A Few Key System Commands


* passwd


File Permissions in UNIX

A file is a structure defined by the operating system.
Typical UNIX files have three types of permissions associated with them:

read - the contents of the file can be looked at.

write - the contents of the file can be edited or changed.

execute (x) - the file initiate a UNIX process

These are said to be permission bits.

Permission bits on a file are give two three groups of users relative to
the owner of the file. These are:

The user (u) -- the person who owns the file

The group (g) -- a member of the group that corresponds to the group of
the file.

The world (o) -- All other (o) users on the system.

An "ls -l" of this file looks like:

-rw-r--r-- 1 leous 784 Aug 30 12:42 file.html

^^^^^^^^^ ^ ^^^^^ ^^^^ ^ ^

||||||||| | ||||| |||| | |_______ name

||||||||| | ||||| |||| |________________ creation date

||||||||| | ||||| ||||______________________ file size

||||||||| | |||||____________________________________ owner of file

||||||||| |__________________________________________ link count

|||_____________________________________________ other permissions

|||________________________________________________ group permissions

|||___________________________________________________ owner permissions

Other file permissions:



-rwxr-xr-- 1 leous 4700 Jun 22 11:47 file.exe (754)

-r--r--r-- 1 leous 784 Aug 30 9:32 file.txt (444)

-rw-rw-r-- 1 leous 784 Aug 24 1995 (664)

-rw-rw-rw- 1 leous 784 Jul 11 12:42 bad.idea (666)

That is,

r = 4 (i.e. 2**2)

w = 2 (i.e. 2**1)

x = 1 (i.e. 2**0)


rwx = 7

r-- = 4

rw- = 6

rwxr-xr-- = 754

To use the above codes you use the 'chmod' command. For example if you
wanted to set a file to the permissions shown above (on the file file.txt)
for a file called mine.dat, you would do :

chmod 444 mine.txt



|______ CODE

Brief Notes on AFS

(This is used in the 316 Hammond Unix Lab)


* To login, do:
o klog

* To change to your AFS directory, (ASSUMING YOUR USERID IS SAM) do:
o cd /afs/
(note the directories s and a match the first two letters in sam)

* To make this easier, create your own dfs directory via:
o cd
o ln -s /afs/ dfs

* To make a directory available to be read by ALL other users, cd to
that directory and then do:
o fs setacl . system:anyuser rl

* To make a directory secure and NOT available to other users, cd to
that directory and then do:
o fs setacl . system:anyuser none

* To see what your acl's are set do:
o fs listacl

* To check your disk quota do:
o fs listquota



Brief Notes on DCE


* To login, do:
o dce_login
* To change to your DCE directory, (ASSUMING YOUR USERID IS SAM) do:
o cd /.../
(note the directories s and a match the first two letters in sam)
* To make this easier, create your own dfs directory via:
o cd
o ln -s /.../ dfs

Maintained by: Prof. L. N. Long , 233M Hammond Bldg
© Copyright 2000, Lyle N. Long

Unix Command Summary

See the Unix tutorial for a leisurely, self-paced introduction on how to
use the commands listed below. For more documentation on a command, consult
a good book, or use the man pages. For example, for more information on
grep, use the command man grep.


* cat --- for creating and displaying short files
* chmod --- change permissions
* cd --- change directory
* cp --- for copying files
* date --- display date
* echo --- echo argument
* ftp --- connect to a remote machine to download or upload files
* grep --- search file
* head --- display first part of file
* ls --- see what files you have
* lpr --- standard print command (see also print )
* more --- use to read files
* mkdir --- create directory
* mv --- for moving and renaming files
* ncftp --- especially good for downloading files via anonymous ftp.
* print --- custom print command (see also lpr )
* pwd --- find out what directory you are in
* rm --- remove a file
* rmdir --- remove directory
* rsh --- remote shell
* setenv --- set an environment variable
* sort --- sort file
* tail --- display last part of file
* tar --- create an archive, add or extract files
* telnet --- log in to another machine
* wc --- count characters, words, lines



This is one of the most flexible Unix commands. We can use to create, view
and concatenate files. For our first example we create a three-item
English-Spanish dictionary in a file called "dict."

% cat >dict
red rojo
green verde
blue azul

<control-D> stands for "hold the control key down, then tap 'd'". The
symbol > tells the computer that what is typed is to be put into the file
dict. To view a file we use cat in a different way:

% cat dict
red rojo
green verde
blue azul

If we wish to add text to an existing file we do this:

% cat >>dict
white blanco
black negro

Now suppose that we have another file tmp that looks like this:

% cat tmp
cat gato
dog perro

Then we can join dict and tmp like this:

% cat dict tmp >dict2

We could check the number of lines in the new file like this:

% wc -l dict2

The command wc counts things --- the number of characters, words, and line
in a file.


This command is used to change the permissions of a file or directory. For
example to make a file essay.001 readable by everyone, we do this:

% chmod a+r essay.001

To make a file, e.g., a shell script mycommand executable, we do this

% chmod +x mycommand

Now we can run mycommand as a command.

To check the permissions of a file, use ls -l . For more information on
chmod, use man chmod.


Use cd to change directory. Use pwd to see what directory you are in.

% cd english
% pwd
% /u/ma/jeremy/english
% ls
novel poems
% cd novel
% pwd
% /u/ma/jeremy/english/novel
% ls
ch1 ch2 ch3 journal scrapbook
% cd ..
% pwd
% /u/ma/jeremy/english
% cd poems
% cd
% /u/ma/jeremy

Jeremy 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 gotten 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 said cd ../poems. Finally he used cd with no
argument to jump back to his home directory.


Use cp to copy files or directories.

% cp foo foo.2

This makes a copy of the file foo.

% 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.


Use this command to check the date and time.

% date
Fri Jan 6 08:52:42 MST 1995



The echo command echoes its arguments. Here are some examples:

% echo this
% echo $EDITOR
% echo $PRINTER

Things like PRINTER are so-called environment variables. This one stores
the name of the default printer --- the one that print jobs will go to
unless you take some action to change things. The dollar sign before an
environment variable is needed to get the value in the variable. Try the
following to verify this:

% echo PRINTER



Use ftp to connect to a remote machine, then upload or download files. See
also: ncftp

Example 1: We'll connect to the machine, then change director to
mystuff, then download the file homework11:

% ftp solitude
Connected to
220 FTP server (Version wu-2.4(11) Mon Apr 18 17:26:33 MDT 1994) ready.
Name (solitude:carlson): jeremy
331 Password required for jeremy.
230 User jeremy logged in.
ftp> cd mystuff
250 CWD command successful.
ftp> get homework11
ftp> quit

Example 2: We'll connect to the machine, then change director to
mystuff, then upload the file collected-letters:

% ftp solitude
Connected to
220 FTP server (Version wu-2.4(11) Mon Apr 18 17:26:33 MDT 1994) ready.
Name (solitude:carlson): jeremy
331 Password required for jeremy.
230 User jeremy logged in.
ftp> cd mystuff
250 CWD command successful.
ftp> put collected-letters
ftp> quit

The ftp program sends files in ascii (text) format unless you specify
binary mode:

ftp> binary
ftp> put foo
ftp> ascii
ftp> get bar

The file foo was transferred in binary mode, the file bar was transferred
in ascii mode.



Use this command to search for information in a file or files. For example,
suppose that we have a file dict whose contents are

red rojo
green verde
blue azul
white blanco
black negro

Then we can look up items in our file like this;

% grep red dict
red rojo
% grep blanco dict
white blanco
% grep brown dict

Notice that no output was returned by grep brown. This is because "brown"
is not in our dictionary file.

Grep can also be combined with other commands. For example, if one had a
file of phone numbers named "ph", one entry per line, then the following
command would give an alphabetical list of all persons whose name contains
the string "Fred".

% grep Fred ph | sort
Alpha, Fred: 333-6565
Beta, Freddie: 656-0099
Frederickson, Molly: 444-0981
Gamma, Fred-George: 111-7676
Zeta, Frederick: 431-0987

The symbol "|" is called "pipe." It pipes the output of the grep command
into the input of the sort command.

For more information on grep, consult

% man grep



Use this command to look at the head of a file. For example,

% head essay.001

displays the first 10 lines of the file essay.001 To see a specific number
of lines, do this:

% head -20 essay.001

This displays the first 20 lines of the file.


Use ls to see what files you have. Your files are kept in something called
a directory.

% ls
foo letter2
foobar letter3
letter1 maple-assignment1

Note that you have six files. There are some useful variants of the ls

% ls l*
letter1 letter2 letter3

Note what happened: all the files whose name begins with "l" are listed.
The asterisk (*) is the " wildcard" character. It matches any string.


This is the standard Unix command for printing a file. It stands for the
ancient "line printer." See

% man lpr

for information on how it works. See print for information on our local
intelligent print command.


Use this command to create a directory.

% mkdir essays

To get "into" this directory, do

% cd essays

To see what files are in essays, do this:

% ls

There shouldn't be any files there yet, since you just made it. To create
files, see cat or emacs.


More is a command used to read text files. For example, we could do this:

% more poems

The effect of this 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 more
* spacebar --- read next page
* return key --- read next line
* b --- go back one page

For still more information, use the command man more.



Use this command to change the name of file and directories.

% mv foo foobar

The file that was named foo is now named foobar



Use ncftp for anonymous ftp --- that means you don't have to have a

% ncftp
Connected to
> get jokes.txt

The file jokes.txt is downloaded from the machine



This is a moderately intelligent print command.

% print foo
% print
% print manuscript.dvi

In each case print does the right thing, regardless of whether the file is
a text file (like foo ), a postcript file (like, or a dvi file
(like manuscript.dvi. In these examples the file is printed on the default
printer. To see what this is, do

% print

and read the message displayed. To print on a specific printer, do this:

% print foo jwb321
% print jwb321
% print manuscript.dvi jwb321

To change the default printer, do this:

% setenv PRINTER jwb321



Use this command to find out what directory you are working in.

% pwd
% cd homework
% pwd
% ls
assign-1 assign-2 assign-3
% cd
% pwd

Jeremy 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


Use rm to remove files from your directory.

% rm foo
remove foo? y
% rm letter*
remove letter1? y
remove letter2? y
remove letter3? n

The first command removed a single file. The second command was intended to
remove all files beginning with the string "letter." However, our user
(Jeremy?) decided not to remove letter3.


Use this command to remove a directory. For example, to remove a directory
called "essays", do this:

% rmdir essays

A directory must be empty before it can be removed. To empty a directory,
use rm.


Use this command if you want to work on a computer different from the one
you are currently working on. One reason to do this is that the remote
machine might be faster. For example, the command

% rsh solitude

connects you to the machine solitude. This is one of our public
workstations and is fairly fast.

See also: telnet


% echo $PRINTER
% setenv PRINTER myprinter
% echo $PRINTER



Use this commmand to sort a file. For example, suppose we have a file dict
with contents

red rojo
green verde
blue azul
white blanco
black negro

Then we can do this:

% sort dict
black negro
blue azul
green verde
red rojo
white blanco

Here the output of sort went to the screen. To store the output in file we
do this:

% sort dict >dict.sorted

You can check the contents of the file dict.sorted using cat , more , or
emacs .


Use this command to look at the tail of a file. For example,

% head essay.001

displays the last 10 lines of the file essay.001 To see a specific number
of lines, do this:

% head -20 essay.001

This displays the last 20 lines of the file.


Use create compressed archives of directories and files, and also to
extract directories and files from an archive. Example:

% tar -tvzf foo.tar.gz

displays the file names in the compressed archive foo.tar.gz while

% tar -xvzf foo.tar.gz

extracts the files.


Use this command to log in to another machine from the machine you are
currently working on. For example, to log in to the machine "solitude", do

% telnet solitude

See also: rsh.


Use this command to count the number of characters, words, and lines in a
file. Suppose, for example, that we have a file dict with contents

red rojo
green verde
blue azul
white blanco
black negro

Then we can do this

% wc dict
5 10 56 tmp

This shows that dict has 5 lines, 10 words, and 56 characters.

The word count command has several options, as illustrated below:

% wc -l dict
5 tmp
% wc -w dict
10 tmp
% wc -c dict
56 tmp


Here's a command reference card for some regularly used unix commands, tested on linux but
should hopefully work on most unix command shells. Any additional (non-obscure) commands you
think should be added,or corrections please email me.

A DOS version of this reference card (+2000 resource kit additions) will be coming soon.

General help
[command] --help - gives syntax for using that command
man [command] - brings up the manual page for the command, if it exists
man [command] > file.txt - dumps the manual page(s) for the command into 'file.txt'
whatis [command] - gives a short description of the command.
help - gives a list of commands (GNU Bash).
help [command] - gives extra information on the commands listed above.

Viewing/editing/creating a text file
vi [filename] - opens VI text editor, if the file doesn't exist, it'll be created on saving.
(when inside vi)
- using 'i' inserts
- pressing 'escape' and then ':' goes back to command mode.
- '/searchstring' searchs for 'searchstring' using regular expressions.
- ':' followed by 'w' writes
- ':' followed by 'qw' writes then quits
- ':' followed by 'q' quits.
- ':' followed by 'q!' quits regardless of whether changes are made.
- ':' followed by 'z' undos.
pico [filename] - launches the PICO editor for the filename.
more [filename] - shows one screen's worth of the file at a time.
less [filename] - similar to more
cat [filename] | more - works like more, cat concats 2 strings

General/System commands
su [user] - changes the login to 'user', or to the root if no 'user' is given.
date - shows the system date
whoami - tells you who you're logged in as
uptime - how long the computer has been running, plus other details
w - shows who's logged on, what they're doing.
df - how much disk space is left.
du - disk usage by your login, it can also total up directories.
uname -mrs - userful info about the system
uname -a - all details about the system

Desktop / X server + client
Switchdesk {manager - gnome, Enlightenment, etc} - Switches your desktop

What's running
ps - what's running.
ps ax - shows all processes
top - sort of interactive version of ps.
kill [pid] - terminates the named process, which can be name or number or other options.
killall -HUP [command name] - kill a process, running the command specified, by name.
killall -9 [command] - similar to the above
xkill - kills a frozen application in X (gnome,kde etc. desktops), you just click on the
frozen app.

File system
ls -la - list all files/directories
dir - simple form of ls
cd [dir] - change directory
cd ~ - go back to the home directory
cdup - similar to using "cd ..", go up one directory.
pwd - print which directory you're in.
./[filename] - run the file if it's executable and in the current directory
rm [filename] - delete a file
rm -R [directory] - delete a directory
mv [oldfilename] [newfilename] - renames the file (or directory)
cp [filename-source] [filename-destination] - copy the file from one place to another
cp -R [dir-source] [dir-destination] - copy a directory an all its subdirectories
mkdir [name] - makes a directory.
cat [sourcefile] >> [destinationfile] - appends sourcefile to the end of destinationfile

- zipping/taring
tar -cvzf mytar.tar.gz sourcefilesordir - creates a new tar file, verbose options on, runs it
through gnuzip,f is the filename
tar -xvf mytar.tar.gz destination - extracts a tar file (this example is compressed with
gzip), verbosely, f is the filename
gzip fileordir - compresses a file with gzip.
gunzip file.gz - decompresses a file with gzip.
NB gzip only compresses files, it doesn't collect them into a single file like a tarball

locate [filename] - searches the system using an indexed database of files. use updatedb to
update the file database
locate [filename] | sort - sorts the files alphabetically
whereis [filename] - locates an application, such as 'whereis bash'
find [filename] - searches the filesystem as with locate, but without a database so its
find /directory -atime +30 -print - searches for files not used in the past 30 days.

Setting up links
ln -s target linkname - creates a symbolic link, like a shortcut to the target directory or
ln target linkname - creates the default hard link. Deleting this will delete the targetted
file or directory.

Network commands
dig domainname - retrieves information about a domain, such as name servers, mx records
whois domainname - whois info on a domain
finger user - gives info about a user, their group status, but can also be used over a
netstat -ape - lots of info about whos connected to your machine, what processes are doing
what with sockets

Piping to another command is straight forward enough:

locate filename | grep /usr/local > searchresults.txt - searches for filename, runs the
results through grep to filter everything without /usr/local in it, and then outputs the
results to searchresults.txt

| runs one application via another, and can be used multiple times e.g. cat /usr/group | more
| grep root | sort
> creates a new file if once doesn't already exist, overwrites the contents of the file if it
does exist
>> appends to the end of the file, and creates the file if one doesn't exist.
< sends everything after this to the application, e.g. ./mysql -u bob -p databasename <

Permissions and directory listing format
groups [username] - shows what groups the user belongs to
id [username] - shows extended information about a user.
finger [user] - give details about a user.
passwd [user] - changes the password for a user, or without the user argument, changes your
chsh [user] - changes the shell for a user.
userdel [user] - removes a user from the system, use -r to remove their home directory too.
newgrp [group id] - log into a new group.
useradd -d /home/groupname -g groupname - add a new user with the d being the homedirectory,
g the default group they belong to.
groupadd [groupname] - adds a group

Take a look at the users/groups on the system with:

cat /etc/passwd | sort
cat /etc/group | sort

The stuff below is in the man pages also.
The format of passwd is:
password denoted by x (use cat /etc/shadow | sort to list the shadow password file)
uid - user identifier number
gid - group identifier number
misc information such as real name
users home directory
shell for the user

The format of group is:
name of group
password denoted by x (use cat /etc/gshadow | sort to list the shadow group file)
gid - group identifier number
list of additional users assigned to the group

Break down of permissions in a directory listing:
-rw-r--r-- 1 mainuser devel 9054 Dec 28 12:42 index.html

The first character indicates whether it is a directory or file (d for directory).
After that, the next 3 (rw-) are owner permissions.
The following 3 (r--) are group permissions
The following 3(r--) are permissions for other users.

After that reads the number of files inside the directory if it's a directory (which it isn't
so it's 1) this can also be links to the file, the owner of the file, the group the file
belongs to, size in bytes, date and time and then the filename.

Chmod and Chown
Owner,group and other permissions can be r,w,x. Translated into their decimal equivalents
(actually octal but...)
owner - read=400,write=200,execute=100
group - read=40,write=20,execute=10
other - read=4,write=2,execute=1

Unix file permissions calculator
Read Write Execute


So add them up and you've got your user permissions for chmoding:
chmod [mode] fileordirectory - changes the permissions on a file or directory. use -r to
recursively change a whole directory and its sub directories.

e.g chmod 755 myfile.txt - changes the permissions on the file to 755 which is : owner
read,write,execute; group read,execute; other read,execute.

chown [user:group] fileordirectory - changes the user and group ownership of a file or
directory. Use -R to recursively change a whole directory and its sub directories.
chgrp [group] fileordirectory - changes the groupownership of a file or directory. Use -R to
recursively change a whole directory and its sub directories.


mysqldump - Dumps a table,database or all databases to a SQL file. Use the --opt argument for
best results e.g.
mysqldump -u username -p --opt database > file.sql
mysql - The mySQL query manager. To import/export a database to or from a SQL try:
mysql -u username -p database < file_to_go_in.sql
mysql -u username -p database > file_to_go_to.sql
Added lines 1-4:
Added line 8:
Added lines 12-14:

October 13, 2007, at 05:58 AM by -
Added line 6:
* [[Download-FreeBSD-Handbook-and-documentation]]
August 07, 2007, at 09:13 AM by -
Changed lines 3-5 from:
* [[Using Free BSD Portsnap]]
* [[Using Free BSD Portsnap]]
* [[Installing-Software-in-FreeBSD]]
* [[Where-to-check-FreeBSD-Softwares
May 05, 2007, at 02:47 AM by -
Added lines 1-3:
* [[Installing GNOME in FreeBSD and starting GNOME]]
* [[Installing KDE in FreeBSD and starting KDE]]
* [[Using Free BSD Portsnap]]
May 05, 2007, at 02:46 AM by -
Deleted lines 0-2:
* [[Installing GNOME in FreeBSD and starting GNOME]]
* [[Installing KDE in FreeBSD and starting KDE]]
* [[Using Free BSD Portsnap]]
May 02, 2007, at 01:48 AM by -
Added line 2:
* [[Installing KDE in FreeBSD and starting KDE]]
May 02, 2007, at 01:36 AM by -
Added line 1:
* [[Installing GNOME in FreeBSD and starting GNOME]]
April 20, 2007, at 01:31 PM by -
Added line 1:
* [[Using Free BSD Portsnap]]
Edit - History - Print - Recent Changes - Search
Page last modified on December 13, 2012, at 09:37 PM