You are on page 1of 4

Unix commands

Listing directory contents:


ls list a directory
ls -l list a directory in long ( detailed ) format
ls -lrt list a directory in long ( detailed ) format
ls -lart list the hidden files and directories
ls Fx will list files and directory names will be followed by slash.
ls R will lists all the files and files in the all the directories, recursively
ls -R | more will list all the files and files in all the directories, one age at a time
Viewing,editing files and creating directories:
!at view the contents of files (syn"-cat filename)
!at # create the file (syn "-cat # filename)
!at ## aend the file ( syn"-cat ##filename)
$ouch create an emty file(syn"-touch filename)
%i edit the file (syn"-vi filename)
&'dir create a directory(syn"-m'dir dirname)
!d change the directory(syn"-cd dirname)
!d ( change to the root dir(syn"-cd ()
!d ) switch to the home dir(syn"-cd ))
!d ..*.. switch out from the two dir(syn"-cd ..*..)
more dum a file to the screen" +,$+R - one line down
./0!+10R-age down,2-2uit(syn"more filename)
3ess 3i'e more, but you can use /age-4 too.,ot on all
systems.(syn"- less filename)
head .how the first few lines of a file.(syn"-head filename)
head -n .how the first n lines of a file.(syn"-head n filename)
tail .how the last few lines of a file.(syn"-tail filename)
tail -n .how the last n lines of a file.(syn"-tail n filename)
Information:
5ate show date and time
6istory list reviously executed cmds.
77 Reeats the reviously executed cmd
7 , list the , executed cmd (, is number)
&an .hows the manual age of the cmd ( syn"-man cmdname)
8hoami 5islays the username
6ostname shows the hostname(server name)
/wd .how the resent wor'ing directory
/s to see the rocess
Moving, renaming, copying files,removing
! coy the file (syn"-c r source destination * c r oldfile *tm*newfile)
&v file will rename (syn"- mv oldfile newfile.
mv -f will force the rename even if target file exists.
mv 9 *dir will move all the files in current directory to dir(syn"-mv 9 *user*dirname)
rm will delete file (syn"-rm filename).
rm -f will remove write-rotected files without romting.(syn"- rm f filename)
rm -r will delete the entire directory and all the subdirectories(syn"-rm r
filename)
rmdir to remove directory.(syn"-rmdir directoryname)
rmdir will remove directories and any arent directories that are emty.
Comparision and searching cmds :
5iff will comare the two files: rint the differences between(syn"-diff f; f<
o*"- f; abcd,f< ='lm)
!m will comare the two files (syn"- cm f; f<,o* "f; f< char >? line @)
5ircm will comare the two dir(syn"-dircm dir; dir<)
Are rints all the lines in a file that contain the string(syn"-gre string
filename)
Find . name Finds all the files in the current dir(syn"-find . name filename
cut -c selects a list of columns or fields from one or more files.(syn"-cut c ;,@
filename )
cut f will cut the fields identified in list.(syn"-cut f B filename)
/aste merge the lines of one or more files into vertical columns searated by tab
(syn"- aste testfile testfile< # oututfile)
sort sort the lines of a file or files, in alhabetical order.(syn"-sort filename)
wc l to count the number of lines in file(syn"-wc l filename)
wc m to count the number of character in file(syn"-wc m filename)
wc w to count the number of words in file(syn"-wc w filename)
File compression:-
ACi comress the file (syn"-ACi filename)
AunCi uncomress the file(syn"-gunCi filename)
$ar xvf to extract (syn"-tar xvf filename)
$ar cvf to create (syn"-tar cvf filename)
$ar tv to list the files without extracting(syn"-tar tv filename)
Dar xvf same as tar used in =ava as(syn"-=ar xvf filename)
Dar cvf to create file(syn"-=ar cvf filename)
Cpu utiliation and !am utiliation"-
$o*sar*vmstat "-to see the cu utiliCation
.yn"- to
.yn"-sar u ;< E (in ;< seconds it dislay the differ or cu utiliCation inE
.econds) system activity reort.
.yn"- vmstat (dislay the virtual memory)
/rtconf to see the ram utiliCation(syn"-rtconf |gre mem)
5u s' rint siCe in 'ilobytes of current directory
5u s'9 rint siCe in 'ilobytes of all files and subdirectories
5u s' file; rint siCe in 'ilobytes of file;
Changing file permissions and attributes
chmod FEE !hanges the ermissions of file to be rwx for the owner(u), and rx for
the grou(g) and the others(o). (syn"-chmod FEE filename)
chmod go-w to remove ermissions to grou and others(syn"-chmod go-w filename)
chmod ugoGrw to add ermissions to owner,grouand others(syn"-chmod ugoHrw
filename)
(read-@,write-<,execute-;)
"ransfer the file
4uencode $o encode the file(unix)on the local system and mail it to the user xyC on
another system called mysys(syn:uuencode unix unix | mail xyCImysys)
4uencode $o encode the file /usr/lib/boot/unix on your local system with the
name xyz.txt in the file /tmp/con
(syn"uuencode *usr*lib*boot*unix xyC.txt # *tm*con)
#i editor:-
vi filename
<escape> to invoke command mode from insert mode.
i for insert ,delete and edit
o J inserts text at the cursor
o i Jnsert before current cursor osition
o 0 aends text at the end of the line.
o a aends text after cursor.
o K oen a new line of text above the cursor
o o oen a new line of text below the cursor
o r Relace ; character
o R Relace mode
o x 5elete single character
o dd 5elete current line and ut in buffer
o ndd 5elete n lines (n is a number) and ut them in buffer
o u 4ndo last command
o yy coy current line into buffer
o nyy coy n lines into buffer
o /ut the contents of the buffer after the current line
o / /ut the contents of the buffer before the current line
o D =oin a line with the one below it.
o *string to search string in file.
o Lstring to search the in bac'ward direction
o n to search for next occurence of string
o , to search in the oosite direction
cursor positioning
^d Pae do!n
^u Pae up
:n Position cursor at line n
:" Position cursor at end of file
^ #isplay current line number
:. Print t$e current line number at t$e end of vi edito
A to go to last line in file.
;A to go to the first line in file.
"w27 .ave and 2uit
"27 to 2uit

You might also like