Play and learn 300 000+ tabs online

Friday, July 30, 2010

Unix Basic Interview questions and commands

Frequently used UNIX commands

Command

Result

ls

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

pwd

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

cd

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)

qstat

lists jobs running on queue

qstat -a

lists only your jobs

qdel job#

deletes job with number job# from queue

ps

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.

owner

group

all

rwx

rwx

rwx

4 2 1

4 2 1

4 2 1

sum numbers for each of the three categories of user

Ctrl+c

kills current operation

Ctrl+h

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

Ctrl+d

logout

Frequently used Vi Editor commands

Command

Result

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)

i

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

Esc

return to command mode

in command mode →

:q

quit file

:q!

quit file without saving any changes

:w

save file (write)

:wq

save and quit file (write and quit)

x

delete character

/string

search forward for string (n key finds next)

?string

search backwards for string (n key finds previous)

:g/string/s//string2/g

substitute string with string2 globally

:line#

jump to line# in file

:$

jump to last line of file

:.,$d

delete from current line to end of file

:.,.+20d

delete from current line through next 20

No comments:

Post a Comment

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