18 July 2010

Basic UNIX Commands

         You must first logon to a UNIX machine. The method(s) to do this vary, so check with the facility you are aton how to logon.Once logged on, these commands are essential to learn. More information about them (and other commands)can be obtained by entering man command (short for manual). For example, to obtain a manual about the command cat, you would type man cat.

cat - List a file
USAGE: cat [ -n ] file...
OPTIONS: -n display line numbers.
EXAMPLES: cat myprog.c

cat -n myprog.c
cd - Change directory
USAGE: cd [ directory ]

cd mysource
NOTE: The command cd with no arguments will take you to your home directory ( i.e.
the directory you start in when you first login to the system ).
The command cd .. will take you to the directory above the one you are in.

cp - Copy a file
USAGE: cp file1 file2
cp file1 ...directory
EXAMPLE: cp myprog.c myprog.1.save
NOTE: Suppose your instructor tells you to get a copy of the file firstprog.p that is in the
directory /u/mathcs/fs/ravi. The complete command to copy this file to the directory
you are in is:
cp /u/mathcs/fs/ravi/firstprog.p firstprog.p
It is important to note that the forward slash "/" is used to specify path names.

logout - Exit unix
USAGE: logout
NOTE: Where you are returned to when you logout is depending on the method used to login
to the unix system. If you try to logout and you get an error message
“there are stopped jobs”, then type a fg command to go back to that job, then
you can properly exit the session and logout.

ls - List the contents of the current directory
USAGE: ls [ file1... ]
ls *.exe (this lists only files that end with the extension .exe)
ls pkzip.* (this lists only files that begin with pkzip and has any extension)

mkdir - Create a new directory
USAGE: mkdir directory...
EXAMPLE: mkdir junkdir

more - List a long file
USAGE: more file ...
EXAMPLES: more myprog.c
more a.c b.c c.c
NOTE: You can also use this with other unix commands that involves listing data.
EXAMPLES: finger |more
cat file |more

mv - Rename or move a file
USAGE: mv file1 file2
mv file1 ... directory
EXAMPLE: mv a.out myfirst

passwd - Change login passwd
USAGE: passwd
NOTE: As you type in the passwords, the characters are not displayed on the screen.

pwd - Display the current directory
USAGE: pwd
NOTE: pwd tells you which directory you are in.

rm - Remove file(s)
USAGE: rm file...
EXAMPLE: rm myfirst.old

rmdir - Remove an empty directory
USAGE: rmdir directory ...
EXAMPLE: rmdir junkdir
NOTE: In order to remove a directory that contains files, you must first remove the files with
rm and then remove the directory with rmdir.

finger - display information about local and remote users.
USAGE: finger
NOTE: If you use this command followed by a user’s login name, it will give some information
about that’s user’s account; directory route, last time he or she logged in, etc.
USAGE: finger user...
EXAMPLE: finger stsc

who - Identifies who is currently logged on the unix machine, but displays less information than
with the “finger” command.

USAGE: who
spell - It checks your documents for spelling errors using an online dictionary.
USAGE: spell file
EXAMPLE: spell commands.txt


  1. plz also write different switches of those command & their use.......

  2. @kanisha, about which command u want to know?


Popular Posts