Play and learn 300 000+ tabs online

Friday, July 30, 2010

Unix Basic Interview questions and commands

Frequently used UNIX commands




lists files in current working directory

ls *.out

lists all files in current directory that end in .out

ls -l

lists files giving details including file size


displays full-path name of your current working directory on screen (stands for “present working directory”)

cd dirname

changes directory to dirname

cd ..

changes directory to one above the current directory


with no argument, takes you to your home directory

mkdir dirname

creates new directory dirname

rmdir dirname

removes empty directory dirname

cp filename newname

makes a copy of filename with the name newname

cp ../filename .

copies filename in directory one tier above to current directory giving it the same name

mv filename newname

renames filename to newname (mv stands for “move”)

cat filename

displays contents of filename on screen

more filename

displays filename contents one screen at a time (Enter key scrolls through file by line; space bar scrolls through by screen)

head filename

displays first 10 lines of filename on screen

tail filename

displays last 10 lines of filename on screen

rm filename

deletes filename without double check (rm stands for “remove”)

grep string filename

displays lines from filename containing string on screen

./ filename &

runs job filename in the background

qsub filename

sends job filename to queue (where qsub is a submission script file in your bin directory)


lists jobs running on queue

qstat -a

lists only your jobs

qdel job#

deletes job with number job# from queue


lists processes you have running

ps -ef

lists all processes

kill pid#

kills process with ID number pid#

kill -9 pid#

kills (with the “sure kill” signal) process with ID number pid#

kill -kill 0

kills all processes you have running and logs you off

man commandname

displays manual page for command commandname

man -k keyword

lists manual pages for commands related to keyword

lp filename

prints filename on printer in room 4241

chmod ### filename

changes “read, write, execute” mode of filename

Example: to set the privileges for filename so that the owner has the ability to read, overwrite and execute the file, the group has the ability to read and execute the file, and everyone else has no access to the file, use the command chmod 750 filename.







4 2 1

4 2 1

4 2 1

sum numbers for each of the three categories of user


kills current operation


delete (always works even when delete key doesn’t)



Frequently used Vi Editor commands



vi filename

opens file (vi with no argument opens new file)

Two modes in vi editor: insert and command (default is command mode when file is opened)


change to insert mode - in this mode you can add text


return to command mode

in command mode →


quit file


quit file without saving any changes


save file (write)


save and quit file (write and quit)


delete character


search forward for string (n key finds next)


search backwards for string (n key finds previous)


substitute string with string2 globally


jump to line# in file


jump to last line of file


delete from current line to end of file


delete from current line through next 20

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.