Você está na página 1de 35

3/20/2014

50 Most Frequently Used UNIX / Linux Commands (With Examples)

50 Most Frequently Used UNIX / Linux Commands (With Examples)


by RA M E S H NA T A RA JA N on NO V E M B E R 8 , 2 0 1 0

311

Like

455

This article provides practical examples for 50 most frequently used commands in Linux / UNIX. This is not a comprehensive list by any means, but this should give you a jumpstart on some of the common Linux commands. Bookmark this article for your future reference. Did I miss any frequently used Linux commands? Leave a comment and let me know.

1. tar command examples


Create a new tar archive.

$t a rc v fa r c h i v e _ n a m e . t a rd i r n a m e /

Extract from an existing tar archive.

$t a rx v fa r c h i v e _ n a m e . t a r
http://www.thegeekstuff.com/2010/11/50-linux-commands/ 1/35

3/20/2014

50 Most Frequently Used UNIX / Linux Commands (With Examples)

View an existing tar archive.

$t a rt v fa r c h i v e _ n a m e . t a r

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

2. grep command examples


Search for a given string in a file (case in-sensitive search).

$g r e pi" t h e "d e m o _ f i l e

Print the matched line, along with the 3 lines after it.

$g r e pA3i" e x a m p l e "d e m o _ t e x t

http://www.thegeekstuff.com/2010/11/50-linux-commands/

2/35

3/20/2014

50 Most Frequently Used UNIX / Linux Commands (With Examples)

Search for a given string in all files recursively

$g r e pr" r a m e s h "*

More grep examples: Get a Grip on the Grep! 15 Practical Grep Command Examples

3. find command examples


Find files using file-name ( case in-sensitve find)

#f i n di n a m e" M y C P r o g r a m . c "

Execute commands on files found by the find command

$f i n di n a m e" M y C P r o g r a m . c "e x e cm d 5 s u m{ }\ ;

Find all empty files in home directory

#f i n d~e m p t y

More find examples: Mommy, I found it! 15 Practical Linux Find Command Examples
http://www.thegeekstuff.com/2010/11/50-linux-commands/ 3/35

3/20/2014

50 Most Frequently Used UNIX / Linux Commands (With Examples)

4. ssh command examples


Login to remote host

s s hlj s m i t hr e m o t e h o s t . e x a m p l e . c o m

Debug ssh client

s s hvlj s m i t hr e m o t e h o s t . e x a m p l e . c o m

Display ssh client version

$s s hV O p e n S S H _ 3 . 9 p 1 ,O p e n S S L0 . 9 . 7 aF e b1 92 0 0 3

More ssh examples: 5 Basic Linux SSH Client Commands

5. sed command examples


When you copy a DOS file to Unix, you could find \r\n in the end of each line. This example converts the DOS file format to Unix file format using sed command.

$ s e d' s / . $ / / 'f i l e n a m e
http://www.thegeekstuff.com/2010/11/50-linux-commands/ 4/35

3/20/2014

50 Most Frequently Used UNIX / Linux Commands (With Examples)

Print file content in reverse order

$s e dn' 1 ! G ; h ; $ p 't h e g e e k s t u f f . t x t

Add line number for all non-empty-lines in a file

$s e d' / . / = 't h e g e e k s t u f f . t x t|s e d' N ;s / \ n // '

More sed examples: Advanced Sed Substitution Examples

6. awk command examples


Remove duplicate lines using awk

$a w k' ! ( $ 0i na r r a y ){a r r a y [ $ 0 ] ;p r i n t} 't e m p

Print all lines from /etc/passwd that has the same uid and gid

$ a w kF' : '' $ 3 = = $ 4 'p a s s w d . t x t

Print only specific field from a file.

$a w k' { p r i n t$ 2 , $ 5 ; } 'e m p l o y e e . t x t
http://www.thegeekstuff.com/2010/11/50-linux-commands/ 5/35

3/20/2014

50 Most Frequently Used UNIX / Linux Commands (With Examples)

More awk examples: 8 Powerful Awk Built-in Variables FS, OFS, RS, ORS, NR, NF, FILENAME, FNR

7. vim command examples


Go to the 143rd line of file

$v i m+ 1 4 3f i l e n a m e . t x t

Go to the first match of the specified

$v i m+ / s e a r c h t e r mf i l e n a m e . t x t

Open the file in read only mode.

$v i mR/ e t c / p a s s w d

More vim examples: How To Record and Play in Vim Editor

8. diff command examples


Ignore white space while comparing.

#d i f fwn a m e _ l i s t . t x tn a m e _ l i s t _ n e w . t x t
http://www.thegeekstuff.com/2010/11/50-linux-commands/ 6/35

3/20/2014

50 Most Frequently Used UNIX / Linux Commands (With Examples)

2 c 2 , 3 <J o h nD o e->J o h nMD o e >J a s o nB o u r n e

More diff examples: Top 4 File Difference Tools on UNIX / Linux Diff, Colordiff, Wdiff, Vimdiff

9. sort command examples


Sort a file in ascending order

$s o r tn a m e s . t x t

Sort a file in descending order

$s o r trn a m e s . t x t

Sort passwd file by 3rd field.

$s o r tt :k3 n/ e t c / p a s s w d|m o r e

10. export command examples


http://www.thegeekstuff.com/2010/11/50-linux-commands/ 7/35

3/20/2014

50 Most Frequently Used UNIX / Linux Commands (With Examples)

To view oracle related environment variables.

$e x p o r t|g r e pO R A C L E d e c l a r exO R A C L E _ B A S E = " / u 0 1 / a p p / o r a c l e " d e c l a r exO R A C L E _ H O M E = " / u 0 1 / a p p / o r a c l e / p r o d u c t / 1 0 . 2 . 0 " d e c l a r exO R A C L E _ S I D = " m e d " d e c l a r exO R A C L E _ T E R M = " x t e r m "

To export an environment variable:

$e x p o r tO R A C L E _ H O M E = / u 0 1 / a p p / o r a c l e / p r o d u c t / 1 0 . 2 . 0

11. xargs command examples


Copy all images to external hard-drive

#l s* . j p g|x a r g sn 1ic p{ }/ e x t e r n a l h a r d d r i v e / d i r e c t o r y

Search all jpg images in the system and archive it.

#f i n d/n a m e* . j p gt y p efp r i n t|x a r g st a rc v z fi m a g e s . t a r . g z

Download all the URLs mentioned in the url-list.txt file


http://www.thegeekstuff.com/2010/11/50-linux-commands/ 8/35

3/20/2014

50 Most Frequently Used UNIX / Linux Commands (With Examples)

#c a tu r l l i s t . t x t|x a r g sw g e t c

12. ls command examples


Display filesize in human readable format (e.g. KB, MB etc.,)

$l sl h r w r -1r a m e s ht e a m d e v8 . 9 MJ u n1 21 5 : 2 7a r c h l i n u x . t x t . g z

Order Files Based on Last Modified Time (In Reverse Order) Using ls ltr

$l sl t r

Visual Classification of Files With Special Characters Using ls -F

$l sF

More ls examples: Unix LS Command: 15 Practical Examples

13. pwd command


pwd is Print working directory. What else can be said about the good old pwd who has been printing the current directory name for ages.
http://www.thegeekstuff.com/2010/11/50-linux-commands/ 9/35

3/20/2014

50 Most Frequently Used UNIX / Linux Commands (With Examples)

14. cd command examples


Use cd - to toggle between the last two directories Use shopt -s cdspell to automatically correct mistyped directory names on cd More cd examples: 6 Awesome Linux cd command Hacks

15. gzip command examples


To create a *.gz compressed file:

$g z i pt e s t . t x t

To uncompress a *.gz file:

$g z i pdt e s t . t x t . g z

Display compression ratio of the compressed file using gzip -l

$g z i pl* . g z c o m p r e s s e d 2 3 7 0 9

u n c o m p r e s s e d r a t i ou n c o m p r e s s e d _ n a m e 9 7 9 7 5 7 5 . 8 %a s p p a t c h r p m s . t x t

http://www.thegeekstuff.com/2010/11/50-linux-commands/

10/35

3/20/2014

50 Most Frequently Used UNIX / Linux Commands (With Examples)

16. bzip2 command examples


To create a *.bz2 compressed file:

$b z i p 2t e s t . t x t

To uncompress a *.bz2 file:

b z i p 2dt e s t . t x t . b z 2

More bzip2 examples: BZ is Eazy! bzip2, bzgrep, bzcmp, bzdiff, bzcat, bzless, bzmore examples

17. unzip command examples


To extract a *.zip compressed file:

$u n z i pt e s t . z i p

View the contents of *.zip file (Without unzipping it):

$u n z i plj a s p e r . z i p A r c h i v e : j a s p e r . z i p L e n g t h D a t e T i m e - http://www.thegeekstuff.com/2010/11/50-linux-commands/

N a m e 11/35

3/20/2014

50 Most Frequently Used UNIX / Linux Commands (With Examples)

4 0 9 9 5 3 2 1 6 9 1 5 9 6 4 1 0 5 4 2

1 1 3 0 9 82 3 : 5 0 0 8 2 5 9 82 1 : 0 7 0 8 2 5 9 82 1 : 0 7 0 8 2 5 9 82 1 : 0 7

M E T A I N F / M A N I F E S T . M F c l a s s e s _ c l a s s e s _ n a m e s c l a s s e s _ n c o m p

18. shutdown command examples


Shutdown the system and turn the power off immediately.

#s h u t d o w nhn o w

Shutdown the system after 10 minutes.

#s h u t d o w nh+ 1 0

Reboot the system using shutdown command.

#s h u t d o w nrn o w

Force the filesystem check during reboot.

#s h u t d o w nF rn o w

http://www.thegeekstuff.com/2010/11/50-linux-commands/

12/35

3/20/2014

50 Most Frequently Used UNIX / Linux Commands (With Examples)

19. ftp command examples


Both ftp and secure ftp (sftp) has similar commands. To connect to a remote server and download multiple files, do the following.

$f t pI P / h o s t n a m e f t p >m g e t* . h t m l

To view the file names located on the remote server before downloading, mls ftp command as shown below.

f t p >m l s* . h t m l/ f t p t e s t / f e a t u r e s . h t m l / f t p t e s t / i n d e x . h t m l / f t p t e s t / o t h e r t o o l s . h t m l / f t p t e s t / s a m p l e r e p o r t . h t m l / f t p t e s t / u s a g e . h t m l

More ftp examples: FTP and SFTP Beginners Guide with 10 Examples

20. crontab command examples


View crontab entry for a specific user

#c r o n t a buj o h nl

http://www.thegeekstuff.com/2010/11/50-linux-commands/

13/35

3/20/2014

50 Most Frequently Used UNIX / Linux Commands (With Examples)

Schedule a cron job every 10 minutes.

* / 1 0****/ h o m e / r a m e s h / c h e c k d i s k s p a c e

More crontab examples: Linux Crontab: 15 Awesome Cron Job Examples

21. service command examples


Service command is used to run the system V init scripts. i.e Instead of calling the scripts located in the /etc/init.d/ directory with their full path, you can use the service command. Check the status of a service:

#s e r v i c es s hs t a t u s

Check the status of all the services.

s e r v i c es t a t u s a l l

Restart a service.

#s e r v i c es s hr e s t a r t
http://www.thegeekstuff.com/2010/11/50-linux-commands/ 14/35

3/20/2014

50 Most Frequently Used UNIX / Linux Commands (With Examples)

22. ps command examples


ps command is used to display information about the processes that are running in the system. While there are lot of arguments that could be passed to a ps command, following are some of the common ones. To view current running processes.

$p se f|m o r e

To view current running processes in a tree structure. H option stands for process hierarchy.

$p se f H|m o r e

23. free command examples


This command is used to display the free, used, swap memory available in the system. Typical free command output. The output is displayed in bytes.
http://www.thegeekstuff.com/2010/11/50-linux-commands/ 15/35

3/20/2014

50 Most Frequently Used UNIX / Linux Commands (With Examples)

$f r e e t o t a l M e m : 3 5 6 6 4 0 8 / +b u f f e r s / c a c h e : S w a p : 4 0 0 0 1 7 6 u s e d 1 5 8 0 2 2 0 4 7 3 2 7 2 0 f r e e 1 9 8 6 1 8 8 3 0 9 3 1 3 6 4 0 0 0 1 7 6 s h a r e d 0 b u f f e r s 2 0 3 9 8 8

c a c h 9 0 2 9

If you want to quickly check how many GB of RAM your system has use the -g option. -b option displays in bytes, -k in kilo bytes, -m in mega bytes.

$f r e eg t o t a l M e m : 3 / +b u f f e r s / c a c h e : S w a p : 3 u s e d 1 0 0 f r e e 1 2 3 s h a r e d 0 b u f f e r s 0

c a c h

If you want to see a total memory ( including the swap), use the -t switch, which will display a total line as shown below.

r a m e s h @ r a m e s h l a p t o p : ~ $f r e et t o t a l u s e d M e m : 3 5 6 6 4 0 8 1 5 9 2 1 4 8 / +b u f f e r s / c a c h e : 4 7 5 3 3 2 S w a p : 4 0 0 0 1 7 6 0 T o t a l : 7 5 6 6 5 8 4 1 5 9 2 1 4 8

f r e e 1 9 7 4 2 6 0 3 0 9 1 0 7 6 4 0 0 0 1 7 6 5 9 7 4 4 3 6

s h a r e d 0

b u f f e r s 2 0 4 2 6 0

c a c h 9 1 2 5

http://www.thegeekstuff.com/2010/11/50-linux-commands/

16/35

3/20/2014

50 Most Frequently Used UNIX / Linux Commands (With Examples)

24. top command examples


top command displays the top processes in the system ( by default sorted by cpu usage ). To sort top output by any column, Press O (upper-case O) , which will display all the possible columns that you can sort by as shown below.

C u r r e n tS o r tF i e l d : P f o rw i n d o w1 : D e f S e l e c ts o r tf i e l dv i af i e l dl e t t e r ,t y p ea n yo t h e rk e yt or e t u r n a :P I D d :U I D e :U S E R . . . . . . . . =P r o c e s sI d =U s e rI d =U s e rN a m e v :n D R T y :W C H A N z :F l a g s

=D i r t yP a g e sc =S l e e p i n gi nF =T a s kF l a g s

To displays only the processes that belong to a particular user use -u option. The following will show only the top processes that belongs to oracle user.

$t o puo r a c l e

More top examples: Can You Top This? 15 Practical Linux Top Command Examples

25. df command examples


http://www.thegeekstuff.com/2010/11/50-linux-commands/ 17/35

3/20/2014

50 Most Frequently Used UNIX / Linux Commands (With Examples)

Displays the file system disk space usage. By default df -k displays output in bytes.

$d fk F i l e s y s t e m / d e v / s d a 1 / d e v / s d a 2

1 K b l o c k s U s e dA v a i l a b l eU s e %M o u n t e do n 2 9 5 3 0 4 0 0 3 2 3 3 1 0 4 2 4 7 9 7 2 3 2 1 2 %/ 1 2 0 3 6 7 9 9 2 5 0 1 7 1 5 9 6 6 4 0 8 2 0 6 0 4 4 %/ h o m e

df -h displays output in human readable form. i.e size will be displayed in GBs.

r a m e s h @ r a m e s h l a p t o p : ~ $d fh F i l e s y s t e m S i z e U s e dA v a i lU s e %M o u n t e do n / d e v / s d a 1 2 9 G 3 . 1 G 2 4 G 1 2 %/ / d e v / s d a 2 1 1 5 G 4 8 G 6 2 G 4 4 %/ h o m e

Use -T option to display what type of file system.

r a m e s h @ r a m e s h l a p t o p : ~ $d fT F i l e s y s t e m T y p e 1 K b l o c k s U s e dA v a i l a b l eU s e %M o u n t e do n / d e v / s d a 1 e x t 4 2 9 5 3 0 4 0 0 3 2 3 3 1 2 0 2 4 7 9 7 2 1 6 1 2 %/ / d e v / s d a 2 e x t 4 1 2 0 3 6 7 9 9 2 5 0 1 7 1 5 9 6 6 4 0 8 2 0 6 0 4 4 %/ h o m e

26. kill command examples


http://www.thegeekstuff.com/2010/11/50-linux-commands/ 18/35

3/20/2014

50 Most Frequently Used UNIX / Linux Commands (With Examples)

Use kill command to terminate a process. First get the process id using ps -ef command, then use kill -9 to kill the running Linux process as shown below. You can also use killall, pkill, xkill to terminate a unix process.

$p se f|g r e pv i m r a m e s h 7 2 4 3 7 2 2 2 92 2 : 4 3p t s / 2 $k i l l97 2 4 3

0 0 : 0 0 : 0 0v i m

More kill examples: 4 Ways to Kill a Process kill, killall, pkill, xkill

27. rm command examples


Get confirmation before removing the file.

$r mif i l e n a m e . t x t

It is very useful while giving shell metacharacters in the file name argument. Print the filename and get confirmation before removing the file.

$r mif i l e *

http://www.thegeekstuff.com/2010/11/50-linux-commands/

19/35

3/20/2014

50 Most Frequently Used UNIX / Linux Commands (With Examples)

Following example recursively removes all files and directories under the example directory. This also removes the example directory itself.

$r mre x a m p l e

28. cp command examples


Copy file1 to file2 preserving the mode, ownership and timestamp.

$c ppf i l e 1f i l e 2

Copy file1 to file2. if file2 exists prompt for confirmation before overwritting it.

$c pif i l e 1f i l e 2

29. mv command examples


Rename file1 to file2. if file2 exists prompt for confirmation before overwritting it.

$m vif i l e 1f i l e 2

http://www.thegeekstuff.com/2010/11/50-linux-commands/

20/35

3/20/2014

50 Most Frequently Used UNIX / Linux Commands (With Examples)

Note: mv -f is just the opposite, which will overwrite file2 without prompting. mv -v will print what is happening during file rename, which is useful while specifying shell metacharacters in the file name argument.

$m vvf i l e 1f i l e 2

30. cat command examples


You can view multiple files at the same time. Following example prints the content of file1 followed by file2 to stdout.

$c a tf i l e 1f i l e 2

While displaying the file, following cat -n command will prepend the line number to each line of the output.

$c a tn/ e t c / l o g r o t a t e . c o n f 1 / v a r / l o g / b t m p{ 2 m i s s i n g o k 3 m o n t h l y 4 c r e a t e0 6 6 0r o o tu t m p 5 r o t a t e1 6 }
http://www.thegeekstuff.com/2010/11/50-linux-commands/ 21/35

3/20/2014

50 Most Frequently Used UNIX / Linux Commands (With Examples)

31. mount command examples


To mount a file system, you should first create a directory and mount it as shown below.

#m k d i r/ u 0 1 #m o u n t/ d e v / s d b 1/ u 0 1

You can also add this to the fstab for automatic mounting. i.e Anytime system is restarted, the filesystem will be mounted.

/ d e v / s d b 1/ u 0 1e x t 2d e f a u l t s02

32. chmod command examples


chmod command is used to change the permissions for a file or directory. Give full access to user and group (i.e read, write and execute ) on a specific file.

$c h m o du g + r w xf i l e . t x t

Revoke all access for the group (i.e read, write and execute ) on a
http://www.thegeekstuff.com/2010/11/50-linux-commands/ 22/35

3/20/2014

50 Most Frequently Used UNIX / Linux Commands (With Examples)

specific file.

$c h m o dg r w xf i l e . t x t

Apply the file permissions recursively to all the files in the subdirectories.

$c h m o dRu g + r w xf i l e . t x t

More chmod examples: 7 Chmod Command Examples for Beginners

33. chown command examples


chown command is used to change the owner and group of a file. \ To change owner to oracle and group to db on a file. i.e Change both owner and group at the same time.

$c h o w no r a c l e : d b ad b o r a . s h

Use -R to change the ownership recursively.

$c h o w nRo r a c l e : d b a/ h o m e / o r a c l e

http://www.thegeekstuff.com/2010/11/50-linux-commands/

23/35

3/20/2014

50 Most Frequently Used UNIX / Linux Commands (With Examples)

34. passwd command examples


Change your password from command line using passwd. This will prompt for the old password followed by the new password.

$p a s s w d

Super user can use passwd command to reset others password. This will not prompt for current password of the user.

#p a s s w dU S E R N A M E

Remove password for a specific user. Root user can disable password for a specific user. Once the password is disabled, the user can login without entering the password.

#p a s s w ddU S E R N A M E

35. mkdir command examples


Following example creates a directory called temp under your home directory.

$m k d i r~ / t e m p
http://www.thegeekstuff.com/2010/11/50-linux-commands/ 24/35

3/20/2014

50 Most Frequently Used UNIX / Linux Commands (With Examples)

Create nested directories using one mkdir command. If any of these directories exist already, it will not display any error. If any of these directories doesnt exist, it will create them.

$m k d i rpd i r 1 / d i r 2 / d i r 3 / d i r 4 /

36. ifconfig command examples


Use ifconfig command to view or configure a network interface on the Linux system. View all the interfaces along with status.

$i f c o n f i ga

Start or stop a specific interface using up and down command as shown below.

$i f c o n f i ge t h 0u p $i f c o n f i ge t h 0d o w n

More ifconfig examples: Ifconfig: 7 Examples To Configure Network Interface


http://www.thegeekstuff.com/2010/11/50-linux-commands/ 25/35

3/20/2014

50 Most Frequently Used UNIX / Linux Commands (With Examples)

37. uname command examples


Uname command displays important information about the system such as Kernel name, Host name, Kernel release number, Processor type, etc., Sample uname output from a Ubuntu laptop is shown below.

$u n a m ea L i n u xj o h n l a p t o p2 . 6 . 3 2 2 4 g e n e r i c# 4 1 U b u n t uS M PT h uA u g1 90 1 : 1 2 : 5 2

38. whereis command examples


When you want to find out where a specific Unix command exists (for example, where does ls command exists?), you can execute the following command.

$w h e r e i sl s l s :/ b i n / l s/ u s r / s h a r e / m a n / m a n 1 / l s . 1 . g z/ u s r / s h a r e / m a n / m a n 1 p / l s . 1 p . g z

When you want to search an executable from a path other than the whereis default path, you can use -B option and give path as argument to it. This searches for the executable lsmk in the /tmp directory, and displays it, if it is available.
http://www.thegeekstuff.com/2010/11/50-linux-commands/ 26/35

3/20/2014

50 Most Frequently Used UNIX / Linux Commands (With Examples)

$w h e r e i suB/ t m pfl s m k l s m k :/ t m p / l s m k

39. whatis command examples


Whatis command displays a single line description about a command.

$w h a t i sl s l s

( 1 ) -l i s td i r e c t o r yc o n t e n t s

$w h a t i si f c o n f i g i f c o n f i g( 8 )

-c o n f i g u r ean e t w o r ki n t e r f a c e

40. locate command examples


Using locate command you can quickly search for the location of a specific file (or group of files). Locate command uses the database created by updatedb. The example below shows all files in the system that contains the word crontab in it.

$l o c a t ec r o n t a b / e t c / a n a c r o n t a b / e t c / c r o n t a b / u s r / b i n / c r o n t a b
http://www.thegeekstuff.com/2010/11/50-linux-commands/ 27/35

3/20/2014

50 Most Frequently Used UNIX / Linux Commands (With Examples)

/ u s r / s h a r e / d o c / c r o n / e x a m p l e s / c r o n t a b 2 e n g l i s h . p l . g z / u s r / s h a r e / m a n / m a n 1 / c r o n t a b . 1 . g z / u s r / s h a r e / m a n / m a n 5 / a n a c r o n t a b . 5 . g z / u s r / s h a r e / m a n / m a n 5 / c r o n t a b . 5 . g z / u s r / s h a r e / v i m / v i m 7 2 / s y n t a x / c r o n t a b . v i m

41. man command examples


Display the man page of a specific command.

$m a nc r o n t a b

When a man page for a command is located under more than one section, you can view the man page for that command from a specific section as shown below.

$m a nS E C T I O N N U M B E Rc o m m a n d n a m e

Following 8 sections are available in the man page. 1. General commands 2. System calls 3. C library functions 4. Special files (usually devices, those found in /dev) and drivers 5. File formats and conventions
http://www.thegeekstuff.com/2010/11/50-linux-commands/ 28/35

3/20/2014

50 Most Frequently Used UNIX / Linux Commands (With Examples)

6. Games and screensavers 7. Miscellaneous 8. System administration commands and daemons For example, when you do whatis crontab, youll notice that crontab has two man pages (section 1 and section 5). To view section 5 of crontab man page, do the following.

$w h a t i sc r o n t a b c r o n t a b( 1 ) c r o n t a b( 5 ) $m a n5c r o n t a b

-m a i n t a i nc r o n t a bf i l e sf o ri n d i v i d u a lu s e r s( V 3 ) -t a b l e sf o rd r i v i n gc r o n

42. tail command examples


Print the last 10 lines of a file by default.

$t a i lf i l e n a m e . t x t

Print N number of lines from the file named filename.txt

$t a i lnNf i l e n a m e . t x t

http://www.thegeekstuff.com/2010/11/50-linux-commands/

29/35

3/20/2014

50 Most Frequently Used UNIX / Linux Commands (With Examples)

View the content of the file in real time using tail -f. This is useful to view the log files, that keeps growing. The command can be terminated using CTRL-C.

$t a i lfl o g f i l e

More tail examples: 3 Methods To View tail -f output of Multiple Log Files in One Terminal

43. less command examples


less is very efficient while viewing huge log files, as it doesnt need to load the full file while opening.

$l e s sh u g e l o g f i l e . l o g

One you open a file using less command, following two keys are very helpful.

C T R L + Ff o r w a r do n ew i n d o w C T R L + Bb a c k w a r do n ew i n d o w

More less examples: Unix Less Command: 10 Tips for Effective Navigation
http://www.thegeekstuff.com/2010/11/50-linux-commands/ 30/35

3/20/2014

50 Most Frequently Used UNIX / Linux Commands (With Examples)

44. su command examples


Switch to a different user account using su command. Super user can switch to any other user without entering their password.

$s u-U S E R N A M E

Execute a single command from a different account name. In the following example, john can execute the ls command as raj username. Once the command is executed, it will come back to johns account.

[ j o h n @ d e v s e r v e r ] $s u-r a jc' l s ' [ j o h n @ d e v s e r v e r ] $

Login to a specified user account, and execute the specified shell instead of the default shell.

$s us' S H E L L N A M E 'U S E R N A M E

45. mysql command examples


mysql is probably the most widely used open source database on Linux. Even if you dont run a mysql database on your server, you might end-up using the mysql command ( client ) to connect to a mysql
http://www.thegeekstuff.com/2010/11/50-linux-commands/ 31/35

3/20/2014

50 Most Frequently Used UNIX / Linux Commands (With Examples)

database running on the remote server. To connect to a remote mysql database. This will prompt for a password.

$m y s q lur o o tph1 9 2 . 1 6 8 . 1 . 2

To connect to a local mysql database.

$m y s q lur o o tp

If you want to specify the mysql root password in the command line itself, enter it immediately after -p (without any space).

46. yum command examples


To install apache using yum.

$y u mi n s t a l lh t t p d

To upgrade apache using yum.

$y u mu p d a t eh t t p d

http://www.thegeekstuff.com/2010/11/50-linux-commands/

32/35

3/20/2014

50 Most Frequently Used UNIX / Linux Commands (With Examples)

To uninstall/remove apache using yum.

$y u mr e m o v eh t t p d

47. rpm command examples


To install apache using rpm.

#r p mi v hh t t p d 2 . 2 . 3 2 2 . 0 . 1 . e l 5 . i 3 8 6 . r p m

To upgrade apache using rpm.

#r p mu v hh t t p d 2 . 2 . 3 2 2 . 0 . 1 . e l 5 . i 3 8 6 . r p m

To uninstall/remove apache using rpm.

#r p me vh t t p d

More rpm examples: RPM Command: 15 Examples to Install, Uninstall, Upgrade, Query RPM Packages

48. ping command examples


http://www.thegeekstuff.com/2010/11/50-linux-commands/ 33/35

3/20/2014

50 Most Frequently Used UNIX / Linux Commands (With Examples)

Ping a remote host by sending only 5 packets.

$p i n gc5g m a i l . c o m

More ping examples: Ping Tutorial: 15 Effective Ping Command Examples

49. date command examples


Set the system date:

#d a t es" 0 1 / 3 1 / 2 0 1 02 3 : 5 9 : 5 3 "

Once youve changed the system date, you should syncronize the hardware clock with the system date as shown below.

#h w c l o c k s y s t o h c #h w c l o c ks y s t o h c u t c

50. wget command examples


The quick and effective method to download software, music, video from internet is using wget command.
http://www.thegeekstuff.com/2010/11/50-linux-commands/ 34/35

3/20/2014

50 Most Frequently Used UNIX / Linux Commands (With Examples)

$w g e th t t p : / / p r d o w n l o a d s . s o u r c e f o r g e . n e t / s o u r c e f o r g e / n a g i o s / n a g i o s 3 . 2

Download and store it with a different name.

$w g e tOt a g l i s t . z i ph t t p : / / w w w . v i m . o r g / s c r i p t s / d o w n l o a d _ s c r i p t . p h p ? s r

http://www.thegeekstuff.com/2010/11/50-linux-commands/

35/35

Você também pode gostar