You are on page 1of 42

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.

Contents

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

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

<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 <control-D> %

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 8

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

chmod 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 information on chmod, use man chmod.
-l

. For more

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

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

Date

Use this command to check the date and time.


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

echo The echo command echoes its arguments. Here are some examples:
% echo this this % echo $EDITOR /usr/local/bin/emacs % echo $PRINTER b129lab1

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 PRINTER

ftp Use ftp to connect to a remote machine, then upload or download files. See also: ncftp Example 1: We'll connect to the machine fubar.net, then change director to mystuff, then download the file homework11:
% ftp solitude Connected to fubar.net. 220 fubar.net 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. Password: 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 fubar.net, then change director to mystuff, then upload the file collected-letters:
% ftp solitude Connected to fubar.net. 220 fubar.net 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. Password: 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> ftp> ftp> ftp> binary put foo ascii get bar

The file foo was transferred in binary mode, the file bar was transferred in ascii mode. grep 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" is not in our dictionary file.

brown.

This is because

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

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

ls Use ls to see what files you have. Your files are kept in something called a directory.
% ls foo foobar letter1 % letter2 letter3 maple-assignment1

Note that you have six files. There are some useful variants of the ls command:
% 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.

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

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

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


% mv foo foobar

The file that was named foo is now named foobar

ncftp Use ncftp for anonymous ftp --- that means you don't have to have a password.
% ncftp ftp.fubar.net Connected to ftp.fubar.net > get jokes.txt

The file jokes.txt is downloaded from the machine ftp.fubar.net.

print This is a moderately intelligent print command.


% print foo % print notes.ps % 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 notes.ps, 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 notes.ps jwb321 % print manuscript.dvi jwb321

To change the default printer, do this:


% setenv PRINTER jwb321

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

/u/ma/jeremy % cd homework % pwd /u/ma/jeremy/homework % ls assign-1 assign-2 assign-3 % cd % pwd /u/ma/jeremy %

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

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

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

rsh 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

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

sort 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 . tail 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. tar 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.

telnet 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 this:
% telnet solitude

See also: rsh.

wc 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

dummy

Under construction

Basic Unix Commands


More information on almost any of the commands that follow can be found in the online manual pages. Type "man commandname" at the command line to look at the manual page for the command "commandname".

Files Display files in a directory :ls Copying files : cp Delete file(s) : rm What kind of file is this ? : file Where is this file ? : find , which, whereis Compile a file : cc, cc++, g++, gcc, CC Debug a program : gdb, dbx, xgdb Whats in this file ? : more, less, cat Whats different with these two files ? diff, cmp View a file in PostScript (.ps file): ghostview Edit a file : emacs, vi, jove

Environment Keep getting "Can"t open display: :0" :setenv Display current environment variables: env Networking

Check your mail or mail


someone : mail , elm, pine Write message to persons screen: write Graphically display new mail xbiff Information on a person : finger Information on people loggedon rwho

Change permission : chmod Finding man page : man -k Moving files : mv Did I spell that right?: spell, ispell

Directories

Info on Printers : printers Printing a file : lpr Check the print queue : lpq Cancel print jobs :lprm Transfer files over Network : ftp, kermit HOW DO I QUIT !? : logout Information on Servers : rupall Processes

Where am I now ?? : pwd What program is running now? jobs, ps Moving around : cd , ln Create a directory : mkdir Passwords Delete a directory : rmdir Change permissions to a CHANGE YOUR PASSWORD directory : chmod ! yppasswd How much disk space do I have left ? quota -v c++ {filename} A compiler for the C++ programming language. Command line parameters are similar to the "cc" compiler"s. A typical invocation might be "c++ -g file.cpp -o executablename llib". cat {filename} Prints out ( to the screen ) the contents of the named file. Can also be used to concatenate files. Say you want file1 and file2 to be all together in one file named file3. If file1 is first, then "cat file1 file2 > file3" will produce the correct file3. cc

A compiler for the "C" programming language. "cc" is ANSI compatible on the SGI, IBM, and newer Sun machines. You might try also try "gcc", GNU CC, which is also available on the SGI, SUN, and IBM machines. A typical invocation might be "cc -g file.c -o executablename -llib". cd {dirname} Change current directory. Without a "dirname", it will return you to your home directory. Otherwise, it takes you to the directory named. "cd /" will take you to the root directory. chmod {options} Changes the permission modes of a file. If you type "ls -l" in a directory, you might get something like this:
drwx-----drwxr-xr-drwxr-xr-x -rw-r--r--rw-r--r--rwxr-xr-x 3 2 3 1 1 1 ertle ertle ertle ertle ertle ertle 512 512 512 373 747 244 Jul 16 13:38 LaTeX/ Jun22 12:26 X/ Jul 13 16:29 Xroff/ Oct 3 1992 o.me Nov 21 1992 profile Jul 16 23:44 zap*

The first part of the line tells you the file"s permissions. For example, the "X" file permissions start with a "d" which tells that it is a directory. The next three characters, "rwx" show that the owner has read, write, and execute permissions on this file. The next three characters, "r-x" shows that people in the same group have read and execute permission on the file. Finally, the last three characters "r-" show that everyone else only has read permission on that file ( To be able to enter a directory, you need read AND execute permission ). Users can use "chmod" to change these permissions. If the user didn"t want anybody else to be able to enter the "X" directory, they would change the permissions to look like those of the LaTeX directory, like this : "chmod og-rx X" this means remove the read ("r" ) and execute ("x") permissions from the group ("g") and others ("o").

cmp {file1} {file2} Compares the contents of two files from eachother. Reports the first different character found, and the line nummber. cp {filename(s)}{path} Copies files from one directory/filename to another. "cp f1 f2" makes a file "f2" identical to "f1". "cp *.c src/" copies all files that end in ".c" into the "src" subdirectory. ctags Creates a tags file for use with ex and vi. A tags file gives the location of functions and type definitions in a group of files. ex and vi use entries in the tags file to locate and display a definition. date Shows current date and time. dbx {executable} Source level debugger. In order to use this, you must use the "-g" option when compiling your source code. Allows you to set break-points, single step through the program, etc. diff {file1} {file2} Displays all the differences between two files or directories to the screen. elm {login-name} Runs a screen oriented mail reader. With a "login-name", starts elm to send mail to "login-name". Otherwise, it starts elm for an interactive session. emacs {filename}

Runs the most recent version of the text editor named EMACS ( produced by the GNU project ). If filename is present, it will start editing that file. Type "<CTRL>-x <CTRL>-h t" to start a tutorial. "<CTRL>-x <CTRL>-c" will exit from emacs. env Prints out the values for all the current environment variables. Some typical environment variables are "DISPLAY", "EDITOR", and "PRINTER". xemacs {filename} An X version of emacs. file filename(s) Looks at "filename(s)" and tells what type of files they are. This is useful in checking a file to be sure that it is text before you "cat" it out ( using "cat" on binary files can be a bummer ). Example:
ertle@newton (55)> file * useful.dvi: data useful.hlp: English text useful.tex: ascii text xwin.dvi: data xwin.tex: English text ertle@newton (56)>

find Searches the named directory and it"s sub-directories for files. Most frequently called like this:
find ./ -name "t*" -print

Which searches the current directory ( and all of its subdirectories ) for any files that begin with the letter "t" and then prints them out. If you are looking for a specific

filename, then replace "t*" with "filename", and "find" will print out all incidences of this file. finger {login-name} Without a "login-name", finger shows who is currently logged on the system, with limited information about them. With a "login-name" you get more detailed info, along with anything that is in that person"s ".plan" file. ftp {address} File Transfer Program. "ftp" transfers files to and from a remote network site. There are many ftp-sites that will let you log in as "anonymous" and get software/data/documents from them for free. After connecting, "ls" will print out the files in the current directory, and "get filename" will transfer the named file into your local directory. Be sure to type "binary" before transferring non-ascii ( executable, compressed, archived, etc ) files. To exit "ftp" type "bye". See also "xarchie". g++ GNU project"s compiler for the C++ language. Parameters are similar to those of "cc". A typical invocation might be "g++ -g filename.cpp -o executablename -llib". More information available under "libg++" in the emacs information browser ( M-x info while in emacs ). gcc GNU project"s compiler for the C language. Command line parameters are mostly similar to those of "cc". More information available under "gcc" in the emacs information browser ( M-x info while in emacs ). gdb

GNU project"s source level debugger. Must use the "-g" command line option when compiling to use this debugger. This debugger is superior to dbx when called from inside emacs ( M-x gdb ) because it gives you a full-screen look at the source code instead of line by line, and allows you to move around and make break-points in the source file. More information available under "gdb" in the emacs information browser ( M-x info while in emacs ). ghostview {filename.ps} X PostScript previewer. PostScript is a text processing and graphics language, and ghostview is handy for looking at the resulting page or picture before you send it to the printer. gossip Anonymous local message center. ispell filename Interactively checks the spelling of the named file, giving logical alternatives to the misspelled words. Type "?" to get help. "ispell" can be accessed from the command line, and also through emacs with M-x ispell-buffer. jobs Shows backgrounded (<CTRL>-z"ed) processes with pid #"s. If you use "jobs" to find the processes that you have suspended or are running in the background, what you get back might look like the following:
[1] 21998 Suspended emacs useful.tex [2] - 22804 Suspended (signal) elm [3] + 22808 Suspended badb

jove {filename}

Johnathan"s Own Version of Emacs. Another emacs editor. Jove doesn"t have as many features as GNU"s emacs, but some people prefer it. <CTRL>-x <CTRL>-c to exit. less filename Displays file with minimal space. kermit File transfer program. Allows you to transfer files between computers - your PC at home to/from the computers at school, for instance. For more information, look in the online manual pages. ln -s {source} {dest} Creates a symbolic link from {source} to {dest}. {Source} can be a directory or a file. Allows you to move around with ease instead of using long and complicated path names. logout Exits and disconnects your network connection. lpq {-Pprintername} Reports all print jobs in the queue for the named printer. If no printer is named with -Pprintername, but the "PRINTER" environment variable is set to a printer name, "lpq" will report on that printer. lpr {-Pprintername}filename Queues file "filename" to be printed on "printer". If no printer is specified with -Pprintername, but the "PRINTER" environment variable is set, then the job will be queued on that printer. lprm {-Pprinter}{job-number}

Lprm removes a job or jobs from a printer"s spooling queue ( i.e. it stops it from being printed or printing out the rest of the way ). Typically, you"d get the job number from the "lpq" command, and then use lprm to stop that job. ls {directory} Shows directory listing. If no "directory" is specified, "ls" prints the names of the files in the current directory. ls -l {directory} Shows long directory listing. If you type "ls -l" in a directory, you might get something like this:
drwx-----drwxr-xr-drwxr-xr-x -rw-r--r--rw-r--r--rwxr-xr-x 3 2 3 1 1 1 ertle ertle ertle ertle ertle ertle 512 512 512 373 747 244 Jul Jun Jul Oct Nov Jul 16 13:38 LaTeX/ 22 12:26 X/ 13 16:29 Xroff/ 3 1992 o.me 21 1992 profile 16 23:44 zap*

The first part of the line tells you the file"s permissions. For example, the "X" file permissions start with a "d" which tells that it is a directory. The next three characters, "rwx" show that the owner has read, write, and execute permissions on this file. The next three characters, "r-x" shows that people in the same group have read and execute permission on the file. Finally, the last three characters "r-" show that everyone else only has read permission on that file ( To be able to enter a directory, you need read AND execute permission ) mail {login-name} Read or send mail messages. If no "login-name" is specified, "mail" checks to see if you have any mail in your mail box. With a "login-name", "mail" will let you type in a message to send to that person. For more advanced mail processing, you might try "elm" or "pine" at the command line, or "M-x mail" in emacs.

mkdir dirname Makes a sub-directory named "dirname" in the current directory. man -k pattern Shows all manual entries which have "pattern" in their description. man {section}name Shows the full manual page entry for "name". Without a section number, "man" may give you any or all man pages for that "name". For example, "man write" will give you the manual pages for the write command, and "man 2 write" will give you the system call for "write" ( usually from the C or Pascal programming language ). more filename Displays the contents of a file with pagebreaks. Usefull to use "file" first so you don"t display garbage. mv filename path Moves "filename" to "path". This might consist of a simple renaming of the file, "mv file1 file2", moving the file to a new directory, "mv file1 /tmp/", or both "mv file1 /tmp/file2". pine Full featured graphical mail reader/sender. "pine" will read your mail, "pine username" will prepare a message to "username". printers Shows available printers and current status. ps {options}

"ps" reports that status of some or all of the processes currently running on the system. With no command line parameters, "ps" only shows processes that belong to you and that are attached to a controlling terminal. pwd Shows current working directory path. quota -v Shows current disk usage and limits. rm filename(s) Removes files. Careful with this one - it is irreversible. It is usually aliased ( in a user"s .cshrc file ) to "rm -i" which insures that "rm" asks you if you are sure that you want to remove the named file. rmdir dirname Removes the directory "dirname". rupall Reports that status of local compute servers. rwho Similar to "who", but shows who is logged onto all emba machines as well as the local machine. Without "-a", rwho shows all the people with under one hour idle time. With the "-a", rwho shows everybody that is logged on.

setenv Sets environment variables. Most frequently used to tell X which display you are on with "setenv DISPLAY displayname:0". Also used in .cshrc file to set "EDITOR" and "PRINTER" environment variables. This tells programs

which editor you prefer, and which printer you want your output to be printed on. spell {filename} Checks the spelling of the words in the standard input by default, checks words in "filename" if a name is supplied on the command line. If a word is misspelled it is printed to stdout ( usually the screen ). trn Threaded, full page network news reader. Quicker than vn. tin Threaded, full page network news reader. Easier to use than trn. vi {filename} Runs the screen oriented text editor named "vi". If a filename is specified, you will be editing that file. Type "[ESC]:q!" to exit without making any changes. vn Runs the screen oriented network news program. Old and slow - maybe try "trn" or "tin".

whereis {command} Reports the directory in which the {command} binary redides. which {command} Reports the directory from which the {command} would be run if it was given as a command line argument. who

Shows who is currently logged on the system. The "w" command does the same thing, but gives slightly different info. write loginname Send a message to another user. Each line will be sent to the other person as you hit the carriage-return. Press <CTRL>-D to end the message. Write won"t work if the other user has typed "mesg n". xbiff X mailbox flag. The xbiff program displays a little image of a mailbox. When there is no mail, the flag on the mailbox is down. When mail arrives, the flag goes up and the mailbox beeps. This program must be started on one of the machines that you receive mail on. This will be one of the Suns ( griffin, sadye, newton, etc ) for most people. xcalc X scientific calculator. xcalendar X calendar. Interactive calendar program with a notebook capability. xclock X clock. xforecast X interface to national weather forecast. xgdb X interface to the gdb debugger. xman

X interface to the online manual pages. yppasswd Interactively changes your password. DOS attrib backup dir cls copy del deltree edit format UNIX chmod tar ls clear cp rm rm -R rmdir vi pico fdformat mount umount mv less <file> cd chdir more file mkdir startx DOS VS. UNIX If you are able to navigate through MSDOS. You will be able to pick up on the navigation of Linux and Unix in the following

move / rename type cd more < file md win

INDEX

Category:
Software

Companies:
See Network

chart we have listed several of the various similarities of DOS and Unix. DOS attrib backup dir cls copy del deltree edit format UNIX chmod tar ls clear cp rm rm -R rmdir vi pico fdformat mount umount mv less <file> cd chdir more file mkdir startx

Related Pages:
Operating Systems

RESOLVED
Were you able to locate the answer to your questions?

Yes No

move / rename type cd more < file md win

LINUX / UNIX COMMANDS * See our our complete overview page for a brief description on each of the below commands.

A a2p | alias | ac | ar | arch | as | at | awk B basename | bash | bc | bdiff | bfs | bg | biff | break | bs | bye cal | calendar | cancel | cat | cc | cd | chdir | checkeq | checknr | chfn | chgrp | chkey | chmod | chown | chsh | cksum | clear | cls C | cmp | col | comm | compress | continue | copy | cp | cpio | crontab | csh | csplit | ctags | cu | cut D date | dc | df | deroff | diff | dircmp | dpost | du echo | ed | edit | egrep | elm | emacs | enable | env | eqn | ex | E exit | expand | expr F fc | fg | fgrep | file | find | finger | fmt | fold | for | foreach | ftp getfacl | gprof | grep | groupadd | groupdel | groupmod | gunzip G | gview | gvim | gzip H halt | hash | hashstat | head | help | history | hostname I id | ifconfig | isalist J jobs | join K keylogin | kill | ksh ld | ldd | less | lex | ln | lo | locate | login | logname | logout | lp | L lpadmin | lpc | lpq | lpr | lprm | lpstat | ls mach | mail | mailcompat | mailx | make | man | mesg | mkdir | M more | mount | mt | mv neqn | netstat | newalias | newform | newgrp | nice | niscat | N nischmod | nischown | nischttl | nisdefaults | nisgrep | nismatch | nispasswd | nistbladm | nohup | nroff | nslookup O on | onintr | optisa pack | pagesize | passwd | paste | pax | pcat | perl | pg | pgrep | P pico | ping | pkill | poweroff | pr | priocntl | printf | ps | pvs | pwd Q quit rcp | reboot | red | rehash | remsh | repeat | rgview | rgvim | R rlogin | rm | rmail | rmdir | rn | rpcinfo | rsh | rview | rvim s2p | sag | sar | script | sdiff | sed | sendmail | set | setenv | S setfacl | settime | sh | shutdown | sleep | sort | spell | split | stop |

stty | su | sysinfo tabs | tail | tar | tbl | tcopy | tee | telnet | time | timex | touch | T tput | tr | traceroute | troff ul | umask | unalias | unhash | uname | uncompress | uniq | U unmount | unpack | untar | until | useradd | userdel | usermod V vacation | vedit | vgrind | vi | view | vim W wait | wc | whereis | while | which | who | whois X X | xfd | xlsfonts | xset | xterm | xrdb Y yacc | yppasswd Z zcat [Next] [Previous] [Up] [Top] [Contents] CHAPTER 11 Unix Command Summary

11.1 Unix Commands


In the table below we summarize the more frequently used commands on a Unix system. In this table, as in general, for most Unix commands, file, could be an actual file name, or a list of file names, or input/output could be redirected to or from the command. Unix Commands Command/Syntax What it will do awk/nawk [options] scan for patterns in a file and process the file results cat [options] file concatenate (list) a file cd [directory] change directory chgrp [options] group change the group of the file file change file or directory access chmod [options] file permissions

chown [options] owner file chsh (passwd -e/-s) username login_shell cmp [options] file1 file2 compress [options] file

change the ownership of a file; can only be done by the superuser change the user's login shell (often only by the superuser) compare two files and list where differences occur (text or binary files) compress file and save it as file.Z copy file1 into file2; file2 shouldn't cp [options] file1 file2 already exist. This command creates or overwrites file2. cut specified field(s)/character(s) from cut (options) [file(s)] lines in file(s) date [options] report the current date and time dd [if=infile] copy a file, converting between ASCII [of=outfile] and EBCDIC or swapping byte order, as [operand=value] specified compare the two files and display the diff [options] file1 file2 differences (text files only) report the summary of disk blocks and df [options] [resource] inodes free and in use du [options] [directory report amount of disk space in use or file] echo [text string] echo the text string to stdout ed or ex [options] file Unix line editors emacs [options] file full-screen editor evaluate the arguments. Used to do expr arguments arithmetic, etc. in the shell. file [options] file classify the file type find directory find files matching a type or pattern [options] [actions]

finger [options] report information about users on local user[@hostname] and remote machines ftp [options] host transfer file(s) using file transfer protocol grep [options] 'search string' argument search the argument (in this case egrep [options] 'search probably a file) for all occurrences of the string' argument search string, and list them. fgrep [options] 'search string' argument gzip [options] file compress or uncompress a file. gunzip [options] file Compressed files are stored with a .gz ending zcat [options] file display the first 10 (or number of) lines head [-number] file of a file display or set (super-user only) the name hostname of the current machine send a signal to the process with the kill [options] [process id number (pid#) or job control SIGNAL] [pid#] number (%n). The default signal is to kill [%job] the process. ln [options] source_file link the source_file to the target target lpq [options] show the status of print jobs lpstat [options] lpr [options] file print to defined printer lp [options] file lprm [options] remove a print job from the print queue

cancel [options] ls [options] [directory list directory contents or file permissions or file] mail [options] [user] simple email utility available on Unix systems. Type a period as the first mailx [options] [user] character on a new line to send message Mail [options] [user] out, question mark for help. man [options] show the manual (man) page for a command command mkdir [options] make a directory directory more [options] file less [options] file page through a text file

pg [options] file mv [options] file1 file2 move file1 into file2 octal dump a binary file, in octal, ASCII, od [options] file hex, decimal, or character mode. passwd [options] set or change your password paste [options] file paste field(s) onto the lines in file pr [options] file filter the file and print it on the terminal ps [options] show status of active processes print working (current) directory pwd remotely copy files from this machine to rcp [options] hostname another machine rlogin [options] login remotely to another machine hostname remove (delete) a file or directory (-r rm [options] file recursively deletes the directory and its

contents) (-i prompts before removing files) rmdir [options] remove a directory directory rsh [options] hostname remote shell to run on another machine saves everything that appears on the script file screen to file until exit is executed stream editor for editing files from a sed [options] file script or from the command line sort the lines of the file according to the sort [options] file options chosen read commands from the file and execute source file them in the current shell. source: C shell, . file .: Bourne shell. report any sequence of 4 or more printable characters ending in <NL> or strings [options] file <NULL>. Usually used to search binary files for ASCII strings. stty [options] set or display terminal control options display the last few lines (or parts) of a tail [options] file file tape archiver--refer to man pages for tar key[options] details on creating, listing, and retrieving [file(s)] from archive files. Tar files can be stored on tape or disk. tee [options] file copy stdout to one or more files communicate with another host using telnet [host [port]] telnet protocol touch [options] [date] create an empty file, or update the access file time of an existing file tr [options] string1 translate the characters in string1 from

string2 uncompress file.Z uniq [options] file uudecode [file] uuencode [file] new_name vi [options] file wc [options] [file(s)] whereis [options] command which command who or w zcat file.Z

stdin into those in string2 in stdout uncompress file.Z and save it as a file remove repeated lines in a file decode a uuencoded file, recreating the original file encode binary file to 7-bit ASCII, useful when sending via email, to be decoded as new_name at destination visual, full-screen editor display word (or character or line) count for file(s) report the binary, source, and man page locations for the command named reports the path to the command or the shell alias in use report who is logged in and what processes are running concatenate (list) uncompressed file to screen, leaving file compressed on disk

Introduction to Unix - 14 AUG 1996 [Next] [Previous] [Up] [Top] [Contents]

Here's a command reference card for some regularly used unix commands, teste linux but should hopefully work on most unix command shells. Any additional ( obscure) commands you think should be added,or corrections please email me.T Windows 2000 command pocket reference (O'Reilly) is a good book to get if yo to learn the equivalent commands for Windows - and most of the below are poss

windows, although the resource kit is usually required.

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 'fi 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 sa (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 head [filename] - Shows the first 10 lines of file, or use -n tail [filename] - Shows the last 10 lines of file, or use -n 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 othe options. killall -HUP [command name] - kill a process, running the command specified, name. killall -9 [command] - similar to the above xkill - kills a frozen application in X (gnome,kde etc. desktops), you just click o 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 a

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 destinatio df - how much disk space is available, more options available.

- zipping/taring tar -cvzf mytar.tar.gz sourcefilesordir - creates a new tar file, verbose options runs it through gnuzip,f is the filename tar -xvf mytar.tar.gz destination - extracts a tar file (this example is compresse 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 tar does.

Searching

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 s slower. find /directory -atime +30 -print - searches for files not used in the past 30 day

Setting up links

ln -s target linkname - creates a symbolic link, like a shortcut to the target direc filename. ln target linkname - creates the default hard link. Deleting this will delete the ta file or directory.

Network commands

dig domainname - retrieves information about a domain, such as name servers, records

whois domainname - whois info on a domain finger user - gives info about a user, their group status, but can also be used ove network netstat -ape - lots of info about whos connected to your machine, what processe doing what with sockets

Piping
Piping to another command is straight forward enough:

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

| runs one application via another, and can be used multiple times e.g. cat /usr/gr more | grep root | sort > creates a new file if once doesn't already exist, overwrites the contents of the f 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 databasena mysqldump.sql

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 password. chsh [user] - changes the shell for a user. userdel [user] - removes a user from the system, use -r to remove their home di too. newgrp [group id] - log into a new group. useradd -d /home/groupname -g groupname - add a new user with the d being 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: username password denoted by x (use cat /etc/shadow | sort to list the shadow password f 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 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

You might also like