Вы находитесь на странице: 1из 16

1.

tar command examples


Create a new tar archive.
$ tar cvf archive_name.tar dirname/

Extract from an existing tar archive.


$ tar xvf archive_name.tar

View an existing tar archive.


$ tar tvf archive_name.tar

More tar examples: The Ultimate Tar Command Tutorial with 10 ractical Examples

2. grep command examples


!earch for a given string in a file "case in#sensitive search$.
$ grep -i "the" demo_file

rint the matched line% along with the & lines after it.
$ grep -A 3 -i "example" demo_text

!earch for a given string in all files recursivel'


$ grep -r "ramesh" *

More grep examples: (et a (rip on the (rep) * 1+ ractical (rep Command Examples

3. find command examples


,ind files using file#name " case in#sensitve find$
# find -iname "My !rogram.c"

Execute commands on files found -' the find command


$ find -iname "My !rogram.c" -exec md"s#m $% &'

,ind all empt' files in home director'


# find ( -empty

More find examples: Momm'% . found it) / 1+ ractical 0inux ,ind Command Examples

4. ssh command examples


0ogin to remote host

ssh -l )smith remotehost.example.com

1e-ug ssh client


ssh -v -l )smith remotehost.example.com

1ispla' ssh client version


$ ssh -* +pen,,-_3..p/0 +pen,,1 2...3a 4e5 /. 6223

More ssh examples: + 2asic 0inux !!3 Client Commands

5. sed command examples


4hen 'ou cop' a 15! file to Unix% 'ou could find 6r6n in the end of each line. This example converts the 15! file format to Unix file format using sed command.
$sed 7s/.$//7 filename

rint file content in reverse order


$ sed -n 7/89'h'$p7 thegee:st#ff.txt

7dd line num-er for all non#empt'#lines in a file


$ sed 7/./;7 thegee:st#ff.txt < sed 7=' s/&n/ /7

More sed examples: 7dvanced !ed !u-stitution Examples

6. awk command examples


8emove duplicate lines using aw9
$ a>: 78?$2 in array@ $ arrayA$2B' print %7 temp

rint all lines from :etc:passwd that has the same uid and gid
$a>: -4 7C7 7$3;;$D7 pass>d.txt

rint onl' specific field from a file.


$ a>: 7$print $60$"'%7 employee.txt

More aw9 examples: ; owerful 7w9 2uilt#in Varia-les * ,!% 5,!% 8!% 58!% <8% <,% ,.0E<7ME% ,<8

7. vim command examples


(o to the 1=&rd line of file

$ vim E/D3 filename.txt

(o to the first match of the specified


$ vim E/search-term filename.txt

5pen the file in read onl' mode.


$ vim -F /etc/pass>d

More vim examples: 3ow To 8ecord and la' in Vim Editor

8. diff command examples


.gnore white space while comparing.
# diff -> name_list.txt name_list_ne>.txt 6c603 G Hohn Ioe --- J Hohn M Ioe J Hason Ko#rne

More diff examples: Top = ,ile 1ifference Tools on U<.> : 0inux * 1iff% Colordiff% 4diff% Vimdiff

9. sort command examples


!ort a file in ascending order
$ sort names.txt

!ort a file in descending order


$ sort -r names.txt

!ort passwd file -' &rd field.


$ sort -tC -: 3n /etc/pass>d < more

1 . export command examples


To view oracle related environment varia-les.
$ export < declare -x declare -x declare -x declare -x grep +FA 1L +FA 1L_KA,L;"/#2//app/oracle" +FA 1L_-+ML;"/#2//app/oracle/prod#ct//2.6.2" +FA 1L_,MI;"med" +FA 1L_NLFM;"xterm"

To export an environment varia-le:


$ export +FA 1L_-+ML;/#2//app/oracle/prod#ct//2.6.2

11. xargs command examples


Cop' all images to external hard#drive
# ls *.)pg < xargs -n/ -i cp $% /external-hard-drive/directory

!earch all ?pg images in the s'stem and archive it.


# find / -name *.)pg -type f -print < xargs tar -cvOf images.tar.gO

1ownload all the U80s mentioned in the url#list.txt file


# cat #rl-list.txt < xargs >get Pc

12. ls command examples


1ispla' filesi@e in human reada-le format "e.g. A2% M2 etc.%$
$ ls -lh -r>-r----- / ramesh team-dev Q..M H#n /6 /"C63 arch-lin#x.txt.gO

5rder ,iles 2ased on 0ast Modified Time ".n 8everse 5rder$ Using ls #ltr
$ ls -ltr

Visual Classification of ,iles 4ith !pecial Characters Using ls #,


$ ls -4

More ls examples: Unix 0! Command: 1+ ractical Examples

13. pwd command


pwd is rint wor9ing director'. 4hat else can -e said a-out the good old pwd who has -een printing the current director' name for ages.

14. cd command examples


Use Bcd #C to toggle -etween the last two directories Use Bshopt #s cdspellC to automaticall' correct mist'ped director' names on cd More cd examples: D 7wesome 0inux cd command 3ac9s

15. g!ip command examples


To create a E.g@ compressed file:
$ gOip test.txt

To uncompress a E.g@ file:

$ gOip -d test.txt.gO

1ispla' compression ratio of the compressed file using g@ip #l


$ gOip -l *.gO compressed 6332. #ncompressed .3.3" ratio #ncompressed_name 3".QR asp-patch-rpms.txt

16. "!ip2 command examples


To create a E.-@F compressed file:
$ 5Oip6 test.txt

To uncompress a E.-@F file:


5Oip6 -d test.txt.5O6

More -@ipF examples: 2G is Ea@') -@ipF% -@grep% -@cmp% -@diff% -@cat% -@less% -@more examples

17. #n!ip command examples


To extract a E.@ip compressed file:
$ #nOip test.Oip

View the contents of E.@ip file "4ithout un@ipping it$:


$ #nOip -l )asper.Oip ArchiveC )asper.Oip 1ength Iate Nime -------------D2.." //-32-.Q 63C"2 36/S. 2Q-6"-.Q 6/C23 /".SD 2Q-6"-.Q 6/C23 /2"D6 2Q-6"-.Q 6/C23

=ame ---MLNA-M=4/MA=M4L,N.M4 classes_ classes_names classes_ncomp

18. sh#tdown command examples


!hutdown the s'stem and turn the power off immediatel'.
# sh#tdo>n -h no>

!hutdown the s'stem after 10 minutes.


# sh#tdo>n -h E/2

8e-oot the s'stem using shutdown command.


# sh#tdo>n -r no>

,orce the files'stem chec9 during re-oot.

# sh#tdo>n -4r no>

19. ftp command examples


2oth ftp and secure ftp "sftp$ has similar commands. To connect to a remote server and download multiple files% do the following.
$ ftp M!/hostname ftpJ mget *.html

To view the file names located on the remote server -efore downloading% mls ftp command as shown -elow.
ftpJ mls *.html /ftptest/feat#res.html /ftptest/index.html /ftptest/othertools.html /ftptest/samplereport.html /ftptest/#sage.html

More ftp examples: ,T and !,T 2eginners (uide with 10 Examples

2 . cronta" command examples


View cronta- entr' for a specific user
# cronta5 -# )ohn -l

!chedule a cron ?o- ever' 10 minutes.


*//2 * * * * /home/ramesh/chec:-dis:-space

More cronta- examples: 0inux Cronta-: 1+ 7wesome Cron Ho- Examples

21. service command examples


!ervice command is used to run the s'stem V init scripts. i.e .nstead of calling the scripts located in the :etc:init.d: director' with their full path% 'ou can use the service command. Chec9 the status of a service:
# service ssh stat#s

Chec9 the steatus of all the services.


service --stat#s-all

8estart a service.
# service ssh restart

22. ps command examples

ps command is used to displa' information a-out the processes that are running in the s'stem. 4hile there are lot of arguments that could -e passed to a ps command% following are some of the common ones. To view current running processes.
$ ps -ef < more

To view current running processes in a tree structure. 3 option stands for process hierarch'.
$ ps -ef- < more

23. free command examples


This command is used to displa' the free% used% swap memor' availa-le in the s'stem. T'pical free command output. The output is displa'ed in -'tes.
$ free total MemC 3"SSD2Q -/E 5#ffers/cacheC ,>apC D222/3S #sed /"Q2662 D33636 2 free /.QS/QQ 32.3/3S D222/3S shared 2 5#ffers 623.QQ cached .26.S2

.f 'ou want to Iuic9l' chec9 how man' (2 of 87M 'our s'stem has use the #g option. #option displa's in -'tes% #9 in 9ilo -'tes% #m in mega -'tes.
$ free -g total MemC 3 -/E 5#ffers/cacheC ,>apC 3 #sed / 2 2 free / 6 3 shared 2 5#ffers 2 cached 2

.f 'ou want to see a total memor' " including the swap$% use the #t switch% which will displa' a total line as shown -elow.
rameshTramesh-laptopC($ free -t total #sed MemC 3"SSD2Q /".6/DQ -/E 5#ffers/cacheC D3"336 ,>apC D222/3S 2 NotalC 3"SS"QD /".6/DQ free /.3D6S2 32./23S D222/3S ".3DD3S shared 2 5#ffers 62D6S2 cached ./6""S

24. top command examples


top command displa's the top processes in the s'stem " -' default sorted -' cpu usage $. To sort top output -' an' column% ress 5 "upper#case 5$ % which will displa' all the possi-le columns that 'ou can sort -' as shown -elow.
#rrent ,ort 4ieldC ! for >indo> /CIef ,elect sort field via field letter0 type any other :ey to ret#rn

aC !MI dC UMI 4#nction eC U,LF ........

; !rocess Md ; User Md ; User =ame

vC nIFN yC V -A= OC 4lags

; Iirty !ages co#nt ; ,leeping in ; Nas: 4lags

To displa's onl' the processes that -elong to a particular user use #u option. The following will show onl' the top processes that -elongs to oracle user.
$ top -# oracle

More top examples: Can Jou Top ThisK 1+ ractical 0inux Top Command Examples

25. df command examples


1ispla's the file s'stem dis9 space usage. 2' default df #9 displa's output in -'tes.
$ df -: 4ilesystem /dev/sda/ /dev/sda6 /W-5loc:s 6."32D22 /623S3..6 Used Availa5le UseR Mo#nted on 3633/2D 6D3.3636 /6R / "2/3/".S SD2Q62S2 DDR /home

df #h displa's output in human reada-le form. i.e si@e will -e displa'ed in (2Ls.
rameshTramesh-laptopC($ df -h 4ilesystem ,iOe Used Avail UseR Mo#nted on /dev/sda/ 6.9 3./9 6D9 /6R / /dev/sda6 //"9 DQ9 S69 DDR /home

Use #T option to displa' what t'pe of file s'stem.


rameshTramesh-laptopC($ df -N 4ilesystem Nype /W-5loc:s /dev/sda/ extD 6."32D22 /dev/sda6 extD /623S3..6 Used Availa5le UseR Mo#nted on 3633/62 6D3.36/S /6R / "2/3/".S SD2Q62S2 DDR /home

26. kill command examples


Use 9ill command to terminate a process. ,irst get the process id using ps #ef command% then use 9ill #M to 9ill the running 0inux process as shown -elow. Jou can also use 9illall% p9ill% x9ill to terminate a unix process.
$ ps -ef < grep vim ramesh 36D3 3666 $ :ill -. 36D3 . 66CD3 pts/6 22C22C22 vim

More 9ill examples: = 4a's to Aill a rocess * 9ill% 9illall% p9ill% x9ill

27. rm command examples


(et confirmation -efore removing the file.
$ rm -i filename.txt

.t is ver' useful while giving shell metacharacters in the file name argument. rint the filename and get confirmation -efore removing the file.
$ rm -i file*

,ollowing example recursivel' removes all files and directories under the example director'. This also removes the example director' itself.
$ rm -r example

28. cp command examples


Cop' file1 to fileF preserving the mode% ownership and timestamp.
$ cp -p file/ file6

Cop' file1 to fileF. if fileF exists prompt for confirmation -efore overwritting it.
$ cp -i file/ file6

29. mv command examples


8ename file1 to fileF. if fileF exists prompt for confirmation -efore overwritting it.
$ mv -i file/ file6

<ote: mv #f is ?ust the opposite% which will overwrite fileF without prompting. mv #v will print what is happening during file rename% which is useful while specif'ing shell metacharacters in the file name argument.
$ mv -v file/ file6

3 . cat command examples


Jou can view multiple files at the same time. ,ollowing example prints the content of file1 followed -' fileF to stdout.
$ cat file/ file6

4hile displa'ing the file% following cat #n command will prepend the line num-er to each line of the output.
$ cat -n /etc/logrotate.conf / /var/log/5tmp $ 6 missingo: 3 monthly D create 2SS2 root #tmp " rotate / S %

31. mo#nt command examples


To mount a file s'stem% 'ou should first create a director' and mount it as shown -elow.
# m:dir /#2/ # mo#nt /dev/sd5/ /#2/

Jou can also add this to the fsta- for automatic mounting. i.e 7n'time s'stem is restarted% the files'stem will -e mounted.
/dev/sd5/ /#2/ ext6 defa#lts 2 6

32. chmod command examples


chmod command is used to change the permissions for a file or director'. (ive full access to user and group "i.e read% write and execute $ on a specific file.
$ chmod #gEr>x file.txt

8evo9e all access for the group "i.e read% write and execute $ on a specific file.
$ chmod g-r>x file.txt

7ppl' the file permissions recursivel' to all the files in the su-#directories.
$ chmod -F #gEr>x file.txt

More chmod examples: N Chmod Command Examples for 2eginners

33. chown command examples


chown command is used to change the owner and group of a file. 6 To change owner to oracle and group to d- on a file. i.e Change -oth owner and group at the same time.
$ cho>n oracleCd5a d5ora.sh

Use #8 to change the ownership recursivel'.


$ cho>n -F oracleCd5a /home/oracle

34. passwd command examples


Change 'our password from command line using passwd. This will prompt for the old password followed -' the new password.
$ pass>d

!uper user can use passwd command to reset others password. This will not prompt for current password of the user.
# pass>d U,LF=AML

8emove password for a specific user. 8oot user can disa-le password for a specific user. 5nce the password is disa-led% the user can login without entering the password.
# pass>d -d U,LF=AML

35. mkdir command examples


,ollowing example creates a director' called temp under 'our home director'.
$ m:dir (/temp

Create nested directories using one m9dir command. .f an' of these directories exist alread'% it will not displa' an' error. .f an' of these directories doesnLt exist% it will create them.
$ m:dir -p dir//dir6/dir3/dirD/

36. ifconfig command examples


Use ifconfig command to view or configure a networ9 interface on the 0inux s'stem. View all the interfaces along with status.
$ ifconfig -a

!tart or stop a specific interface using up and down command as shown -elow.
$ ifconfig eth2 #p $ ifconfig eth2 do>n

More ifconfig examples: .fconfig: N Examples To Configure <etwor9 .nterface

37. #name command examples


Uname command displa's important information a-out the s'stem such as / Aernel name% 3ost name% Aernel release num-er% rocessor t'pe% etc.% !ample uname output from a U-untu laptop is shown -elow.
$ #name -a 1in#x )ohn-laptop 6.S.36-6D-generic #D/-U5#nt# ,M! Nh# A#g /. 2/C/6C"6 UN 62/2 iSQS 9=U/1in#x

38. whereis command examples

4hen 'ou want to find out where a specific Unix command exists "for example% where does ls command existsK$% 'ou can execute the following command.
$ >hereis ls lsC /5in/ls /#sr/share/man/man//ls./.gO /#sr/share/man/man/p/ls./p.gO

4hen 'ou want to search an executa-le from a path other than the whereis default path% 'ou can use #2 option and give path as argument to it. This searches for the executa-le lsm9 in the :tmp director'% and displa's it% if it is availa-le.
$ >hereis -# -K /tmp -f lsm: lsm:C /tmp/lsm:

39. whatis command examples


4hatis command displa's a single line description a-out a command.
$ >hatis ls ls ?/@ - list directory contents - config#re a net>or: interface

$ >hatis ifconfig ifconfig ?Q@

4 . locate command examples


Using locate command 'ou can Iuic9l' search for the location of a specific file "or group of files$. 0ocate command uses the data-ase created -' updated-. The example -elow shows all files in the s'stem that contains the word cronta- in it.
$ locate cronta5 /etc/anacronta5 /etc/cronta5 /#sr/5in/cronta5 /#sr/share/doc/cron/examples/cronta56english.pl.gO /#sr/share/man/man//cronta5./.gO /#sr/share/man/man"/anacronta5.".gO /#sr/share/man/man"/cronta5.".gO /#sr/share/vim/vim36/syntax/cronta5.vim

41. man command examples


1ispla' the man page of a specific command.
$ man cronta5

4hen a man page for a command is located under more than one section% 'ou can view the man page for that command from a specific section as shown -elow.
$ man ,L NM+=-=UMKLF commandname

,ollowing ; sections are availa-le in the man page.

1. (eneral commands F. !'stem calls &. C li-rar' functions =. !pecial files "usuall' devices% those found in :dev$ and drivers +. ,ile formats and conventions D. (ames and screensavers N. Miscellaneous ;. !'stem administration commands and daemons ,or example% when 'ou do whatis cronta-% 'ouLll notice that cronta- has two man pages "section 1 and section +$. To view section + of cronta- man page% do the following.
$ >hatis cronta5 cronta5 ?/@ cronta5 ?"@ $ man " cronta5 - maintain cronta5 files for individ#al #sers ?*3@ - ta5les for driving cron

42. tail command examples


rint the last 10 lines of a file -' default.
$ tail filename.txt

rint < num-er of lines from the file named filename.txt


$ tail -n = filename.txt

View the content of the file in real time using tail #f. This is useful to view the log files% that 9eeps growing. The command can -e terminated using CT80#C.
$ tail -f log-file

More tail examples: & Methods To View tail #f output of Multiple 0og ,iles in 5ne Terminal

43. less command examples


less is ver' efficient while viewing huge log files% as it doesnLt need to load the full file while opening.
$ less h#ge-log-file.log

5ne 'ou open a file using less command% following two 9e's are ver' helpful.
NF1E4 P for>ard one >indo> NF1EK P 5ac:>ard one >indo>

More less examples: Unix 0ess Command: 10 Tips for Effective <avigation

44. s# command examples


!witch to a different user account using su command. !uper user can switch to an' other user without entering their password.
$ s# - U,LF=AML

Execute a single command from a different account name. .n the following example% ?ohn can execute the ls command as ra? username. 5nce the command is executed% it will come -ac9 to ?ohnLs account.
A)ohnTdev-serverB$ s# - ra) -c 7ls7 A)ohnTdev-serverB$

0ogin to a specified user account% and execute the specified shell instead of the default shell.
$ s# -s 7,-L11=AML7 U,LF=AML

45. m$s%l command examples


m'sIl is pro-a-l' the most widel' used open source data-ase on 0inux. Even if 'ou donLt run a m'sIl data-ase on 'our server% 'ou might end#up using the m'sIl command " client $ to connect to a m'sIl data-ase running on the remote server. To connect to a remote m'sIl data-ase. This will prompt for a password.
$ mysXl -# root -p -h /.6./SQ./.6

To connect to a local m'sIl data-ase.


$ mysXl -# root -p

.f 'ou want to specif' the m'sIl root password in the command line itself% enter it immediatel' after #p "without an' space$.

46. $#m command examples


To install apache using 'um.
$ y#m install httpd

To upgrade apache using 'um.


$ y#m #pdate httpd

To uninstall:remove apache using 'um.


$ y#m remove httpd

47. rpm command examples


To install apache using rpm.
# rpm -ivh httpd-6.6.3-66.2./.el".i3QS.rpm

To upgrade apache using rpm.


# rpm -#vh httpd-6.6.3-66.2./.el".i3QS.rpm

To uninstall:remove apache using rpm.


# rpm -ev httpd

More rpm examples: 8 M Command: 1+ Examples to .nstall% Uninstall% Upgrade% Ouer' 8 M ac9ages

48. ping command examples


ing a remote host -' sending onl' + pac9ets.
$ ping -c " gmail.com

More ping examples: ing Tutorial: 1+ Effective ing Command Examples

49. date command examples


!et the s'stem date:
# date -s "2//3//62/2 63C".C"3"

5nce 'ouLve changed the s'stem date% 'ou should s'ncroni@e the hardware cloc9 with the s'stem date as shown -elow.
# h>cloc: Psystohc # h>cloc: --systohc P#tc

5 . wget command examples


The Iuic9 and effective method to download software% music% video from internet is using wget command.
$ >get httpC//prdo>nloads.so#rceforge.net/so#rceforge/nagios/nagios3.6./.tar.gO

1ownload and store it with a different name.


$ >get -+ taglist.Oip httpC//>>>.vim.org/scripts/do>nload_script.phpY src_id;332/

More wget examples: The Ultimate 4get 1ownload (uide 4ith 1+ 7wesome Examples 1id . miss an' freIuentl' used 0inux commandsK 0eave a comment and let me 9now

Вам также может понравиться