Upload
shaik-naseeruddin
View
249
Download
0
Embed Size (px)
Citation preview
7/24/2019 Linux Some Commands
1/79
Linux command line attracts most of the Linux Enthusiastic. A normal Linux user
generally posses a vocabulary of roughly 50-60 commands to carry out their day-to-
day task. Linux commands and their switches remains the most valuable treasure for
a Linux-user, Shell-script programmer and Administrator. There are some Linux
Commandswhich are lesser Known, yet very useful and handy irrespective of the fact
whether you are a Novice or an Advanced User.
Lesser Known Linux Commands
This very article aims at throwing light on some of the lesser known Linux commands which
surely will help you to handle your Desktop/Server more efficiently.
1. sudo !! commandRunning the command without specifying sudo commandwill give you permission denied
error. So, you dont need to rewrite the whole command again just put !! will grab the last
command.
$ apt-get update
E: Could not open lock file /var/lib/apt/lists/lock -open (13: Permission denied)
E: Unable to lock directory /var/lib/apt/lists/
E: Could not open lock file /var/lib/dpkg/lock - open
(13: Permission denied)
http://www.tecmint.com/60-commands-of-linux-a-guide-from-newbies-to-system-administrator/http://www.tecmint.com/60-commands-of-linux-a-guide-from-newbies-to-system-administrator/http://www.tecmint.com/wp-content/uploads/2013/10/Lesser-Known-Commands.pnghttp://www.tecmint.com/wp-content/uploads/2013/10/Lesser-Known-Commands.pnghttp://www.tecmint.com/60-commands-of-linux-a-guide-from-newbies-to-system-administrator/7/24/2019 Linux Some Commands
2/79
E: Unable to lock the administration directory(/var/lib/dpkg/), are you root?
$ sudo !!
sudo apt-get update
[sudo] password for server:
..
Fetched 474 kB in 16s (28.0 kB/s)
Reading package lists... Done
server@localhost:~$
2. python commandThe below command generates a simple web page over HTTP for the directory structure
tree and can be accessed at port 8000in browser till interrupt signal is sent.
# python -m SimpleHTTPServer
7/24/2019 Linux Some Commands
3/79
Directory Structure Tree
3. mtr CommandMost of us are familiar with pingand traceroute. How about combining the functionality of
both the command into one with mtr command. In case mtr is not installed into your
machine, aptor yumthe required package.
$ sudo apt-get install mtr (On Debianbased Systems)# yum install mtr (On Red Hatbased Systems)Now run mtr commandto start investigating the network connection between the host mtr
runson and google.com.
# mtr google.com
http://www.tecmint.com/wp-content/uploads/2013/10/Python-m.pnghttp://www.tecmint.com/wp-content/uploads/2013/10/Python-m.pnghttp://www.tecmint.com/wp-content/uploads/2013/10/Python-m.png7/24/2019 Linux Some Commands
4/79
mtr command
4. Ctrl+x+e CommandThis command is very much useful for administrator and developers. To Automate day-to-day task an administrator needs to open editor by typing vi, vim, nano, etc. How about
firing instant editor (from terminal).
Just Press Ctrl-x-efrom the terminal prompt and start working in editor.
Download Linux Command Line Cheat Sheet
5. nl Command
http://www.tecmint.com/wp-content/uploads/2013/10/mtr-command.pnghttp://tecmint.tradepub.com/free/w_makb09/prgm.cgihttp://tecmint.tradepub.com/free/w_makb09/prgm.cgihttp://tecmint.tradepub.com/free/w_makb09/prgm.cgihttp://www.tecmint.com/wp-content/uploads/2013/10/mtr-command.pnghttp://tecmint.tradepub.com/free/w_makb09/prgm.cgihttp://tecmint.tradepub.com/free/w_makb09/prgm.cgihttp://www.tecmint.com/wp-content/uploads/2013/10/mtr-command.png7/24/2019 Linux Some Commands
5/79
The nl command number the lines of a file. Number the lines of a file say one.txt with
lines say (Fedora, Debian, Arch, Slackand Suse). First list the content of a file one.txt
usingcat command.
# cat one.txt
fedora
debian
arch
slack
suse
Now run nl command to list them in a numbered fashion.
# nl one.txt
1 fedora
2 debian
3 arch
4 slack
5 suse
6. shuf CommandThe shuf command randomly select lines/files/folder from a file/folder. First list thecontents of a folder usingls command.
# ls
Desktop Documents Downloads Music PicturesPublic Templates Videos
# ls | shuf (shuffle Input)
http://www.tecmint.com/13-basic-cat-command-examples-in-linux/http://www.tecmint.com/13-basic-cat-command-examples-in-linux/http://www.tecmint.com/13-basic-cat-command-examples-in-linux/http://www.tecmint.com/15-basic-ls-command-examples-in-linux/http://www.tecmint.com/15-basic-ls-command-examples-in-linux/http://www.tecmint.com/15-basic-ls-command-examples-in-linux/http://www.tecmint.com/15-basic-ls-command-examples-in-linux/http://www.tecmint.com/13-basic-cat-command-examples-in-linux/7/24/2019 Linux Some Commands
6/79
Music
Documents
Templates
Pictures
Public
Desktop
Downloads
Videos
# ls | shuf -n1 (pick on random selection)
Public
# ls | shuf -n1
Videos
# ls | shuf -n1
Templates
# ls | shuf -n1
Downloads
Note: You can always replace n1 with n2 to pick two random selection or any other
number of random selection using n3, n4.
7. ss Command
7/24/2019 Linux Some Commands
7/79
The ss stands for socket statistics. The command investigates the socket and shows
information similar tonetstat command.It can display more TCPand state informations
than other tools.
# ss
State Recv-Q Send-Q Local Address:PortPeer Address:Port
ESTAB 0 0 192.168.1.198:41250*.*.*.*:http
CLOSE-WAIT 1 0 127.0.0.1:8000
127.0.0.1:41393
ESTAB 0 0 192.168.1.198:36239*.*.*.*:http
ESTAB 310 0 127.0.0.1:8000127.0.0.1:41384
ESTAB 0 0 192.168.1.198:41002*.*.*.*:http
ESTAB 0 0 127.0.0.1:41384127.0.0.1:8000
8. last CommandThe last command show the history of last logged in users. This command searches
through the file /var/log/wtmp and shows a list oflogged-inand logged-outusers along
withttys.
# last
server pts/0 :0 Tue Oct 2212:03 still logged in
server tty8 :0 Tue Oct 2212:02 still logged in
...
http://www.tecmint.com/20-netstat-commands-for-linux-network-management/http://www.tecmint.com/20-netstat-commands-for-linux-network-management/http://www.tecmint.com/20-netstat-commands-for-linux-network-management/http://www.tecmint.com/20-netstat-commands-for-linux-network-management/7/24/2019 Linux Some Commands
8/79
(unknown tty8 :0 Tue Oct 2212:02 - 12:02 (00:00)
server pts/0 :0 Tue Oct 2210:33 - 12:02 (01:29)
server tty7 :0 Tue Oct 2210:05 - 12:02 (01:56)
(unknown tty7 :0 Tue Oct 2210:04 - 10:05 (00:00)
reboot system boot 3.2.0-4-686-pae Tue Oct 2210:04 - 12:44 (02:39)
wtmp begins Fri Oct 4 14:43:17 2007
9. curl ifconfig.meSo how do you obtain your External IP address? Using google?. Well the command output
your external IP address right into your terminal.
# curl ifconfig.me
Note:You might dont have curl package installed, you have toapt/yumto install package.
10. tree commandGet the current directory structure in tree like format.
# tree
.
|-- Desktop
|-- Documents
| `-- 37.odt
|-- Downloads
| |-- attachments.zip
7/24/2019 Linux Some Commands
9/79
| |-- ttf-indic-fonts_0.5.11_all.deb
| |-- ttf-indic-fonts_1.1_all.deb
| `-- wheezy-nv-install.sh
|-- Music
|-- Pictures
| |-- Screenshot from 2013-10-22 12:03:49.png
| `-- Screenshot from 2013-10-22 12:12:38.png
|-- Public
|-- Templates
`-- Videos
10 directories, 23 files
11. pstreeThis commands shows all the processes running currently along with associated child
process, in a tree like format similar to tree command output.
# pstree
initNetworkManager{NetworkManager}
accounts-daemon{accounts-daemon}
acpi_fakekeyd
acpid
apache210*[apache2]
at-spi-bus-laun2*[{at-spi-bus-laun}]
atd
avahi-daemonavahi-daemon
7/24/2019 Linux Some Commands
10/79
bluetoothd
colord{colord}
colord-sane2*[{colord-sane}]
console-kit-dae64*[{console-kit-dae}]
cron
cupsd
2*[dbus-daemon]
dbus-launch
dconf-service2*[{dconf-service}]
dovecotanvil
config
log
exim4
gconfd-2
gdm3gdm-simple-slavXorg
gdm-session-worx-session-managevolution-a+
gdu-notific+
gnome-scree+
gnome-setti+
gnome-shell+++
nm-applet+++
7/24/2019 Linux Some Commands
11/79
ssh-agent
tracker-min+
tracker-sto+
3*[{x-sessi+
2*[{gdm-session-wor}]
{gdm-simple-slav}
{gdm3}
6*[getty]
gnome-keyring-d9*[{gnome-keyring-d}]
gnome-shell-cal2*[{gnome-shell-cal}]
goa-daemon{goa-daemon}
gsd-printer{gsd-printer}
gvfs-afc-volume{gvfs-afc-volume}
Thats all for now. In the next article of mine I would cover certain other lesser known Linux
commands which would be fun. Till then stay tuned and connected to Tecmint. Like and
share us and help us get spread.
12. CommandEvery piece of command you type in terminal gets recorded in the historyand can be
retried using historycommand.
How about cheatinghistory command? Yeah you can do it and its very easy. Just put
one or more white space before typing a command in terminal and your command wont be
recorded.
Lets give it a try, we will try five common Linux commands (say ls, pwd, uname, echo
hiand who) in terminal after one white space and check if these commands are docked
in history or not.
avi@localhost:~$ ls
http://www.tecmint.com/history-command-examples/http://www.tecmint.com/history-command-examples/http://www.tecmint.com/history-command-examples/7/24/2019 Linux Some Commands
12/79
avi@localhost:~$ pwd
avi@localhost:~$ uname
avi@localhost:~$ echo hi
avi@localhost:~$ who
Now run history command to see whether these above executed commands are
recorded or not.
avi@localhost:~$ history
40 cd /dev/
41 ls
42 dd if=/dev/cdrom1of=/home/avi/Desktop/squeeze.iso
43 ping www.google.com
44 su
You see our last executed commands are not logged. we can also cheat history by using
an alternate command cat | bash of-course without quotes, in the same way as above.
13. stat CommandThe stat command in Linux displays the status information of a file or filesystem.
The statshows a whole lot of information about the file which name is passed as argument.
Status Information includes file Size, Blocks, Access Permission, Date-timeof file last
access,Modify, change, etc.
avi@localhost:~$ stat 34.odt
File: `34.odt'
Size: 28822 Blocks: 64 IO Block:4096 regular file
Device: 801h/2049d Inode: 5030293 Links: 1
7/24/2019 Linux Some Commands
13/79
Access: (0644/-rw-r--r--) Uid: ( 1000/ avi)Gid: ( 1000/ avi)
Access: 2013-10-14 00:17:40.000000000 +0530
Modify: 2013-10-01 15:20:17.000000000 +0530
Change: 2013-10-01 15:20:17.000000000 +0530
14. . and .The above key combination is not actually a command but a tweak which put the last
command argument at prompt, in the order of last entered command to previous entered
command. Just press and hold Alt or Esc and continue pressing ..
Download Linux Command Line Cheat Sheet
15. pv commandYou might have seen simulating text in Moviesspecially Hollywood Movies, where the
text appears as if it is being typed in the Real time. You can echo any kind of text and
output in simulating fashion using pv command, as pipelined above. Thepvcommand
might not be installed in your system, and you have to aptor yumthe required packages
to install pv into your box.
root@localhost:# echo "Tecmint [dot] com is theworld's best website for qualitative Linux article" |pv -qL 20
Sample Outpit
Tecmint [dot] com is the world's best website forqualitative Linux article
16. mount | column -t
http://tecmint.tradepub.com/free/w_makb09/prgm.cgihttp://tecmint.tradepub.com/free/w_makb09/prgm.cgihttp://tecmint.tradepub.com/free/w_makb09/prgm.cgihttp://tecmint.tradepub.com/free/w_makb09/prgm.cgihttp://tecmint.tradepub.com/free/w_makb09/prgm.cgi7/24/2019 Linux Some Commands
14/79
The above command shows the list of all the mounted filesystem in a nice formatting with
specification.
avi@localhost:~$ mount | column -t
Sample Outpit
/dev/sda1 on / type ext3(rw,errors=remount-ro)
tmpfs on /lib/init/rw typetmpfs (rw,nosuid,mode=0755)
proc on /proc type proc(rw,noexec,nosuid,nodev)
sysfs on /sys typesysfs (rw,noexec,nosuid,nodev)
udev on /dev typetmpfs (rw,mode=0755)
tmpfs on /dev/shm typetmpfs (rw,nosuid,nodev)
devpts on /dev/pts typedevpts (rw,noexec,nosuid,gid=5,mode=620)
fusectl on /sys/fs/fuse/connections typefusectl (rw)
binfmt_misc on /proc/sys/fs/binfmt_misc typebinfmt_misc (rw,noexec,nosuid,nodev)
nfsd on /proc/fs/nfsd type nfsd(rw)
17. Ctr+l commandBefore going further, let me ask you how you clear your terminal. Hmmm! You type clear
at prompt. Well the above command perform the action of cleaning your terminal all at a
once. Just press Ctr+l and see how it clears your terminal all at once.
18. curl commandHow about checking your unread mailfrom the command line. This command is very
useful for those who work on headless server. Again it asks for password at run time and
you need not hard code your password in the above line, which is otherwise a security risk.
7/24/2019 Linux Some Commands
15/79
avi@localhost:~$ curl -u [email protected] --silent "https://mail.google.com/mail/feed/atom" |perl -ne 'print "\t" if //; print "$2\n" if/(.*)/;'
Sample Outpit
Enter host password for user '[email protected]':
Gmail - Inbox for [email protected]
People offering cars in Delhi - Oct 26
Quikr Alerts
another dependency question
Chris Bannister
Ralf Mardorf
Reco
Brian
Franois Patte
Curt
Siard
berenger.morel
Hi Avishek - Download your Free MBA Brochure Now...
Diya
Top Best Sellers Of The Week, Take Your Pick
Timesdeal
aptitude misconfigure?
Glenn English
7/24/2019 Linux Some Commands
16/79
Choosing Debian version or derivative to run Winewhen resource poor
Chris Bannister
Zenaan Harkness
Curt
Tom H
Richard Owlett
Ralf Mardorf
Rob Owens
19. screen CommandThe screencommand makes it possible to detach a long running process from a session
that can again be reattached, as and when required which provides flexibility in command
execution.
To run a process (long) we generally execute as
avi@localhost:~$ ./long-unix-script.sh
Which lacks flexibility and needs the user to continue with the current session, however if
we execute the above command as.
avi@localhost:~$ screen ./long-unix-script.sh
It can be de-attachedor re-attachedin different sessions. When a command is executing
press Ctrl + A and then d tode-attach. To attach run.
avi@localhost:~$ screen -r 4980.pts-0.localhost
Note: Here, the later part of this command is screen id, which you can get using screen
-ls command. To know more about screen command and their usage, please read our
article that shows some useful10 screen commands with examples.
20. fileNo! the above command is not a typo. file is a command which gives you information
about the type of file.
avi@localhost:~$ file 34.odt
http://www.tecmint.com/screen-command-examples-to-manage-linux-terminals/http://www.tecmint.com/screen-command-examples-to-manage-linux-terminals/http://www.tecmint.com/screen-command-examples-to-manage-linux-terminals/http://www.tecmint.com/screen-command-examples-to-manage-linux-terminals/7/24/2019 Linux Some Commands
17/79
34.odt: OpenDocument Text
21. idThe above command print real and effective userand groupids.
avi@localhost:~$ id
Sample Output
uid=1000(avi) gid=1000(avi)
groups=1000(avi),24(cdrom),25(floppy),29(audio),30(dip),44(video),46(plugdev),109(netdev),111(bluetooth),117(scanner)
Thats all for now. Seeing the success of last article of this series and this very article, Ill
be coming with another part of this article containing several other Lesser Known
Linuxcommands very soon. Till then Stay Tunedand connected to Tecmint. Dont Forget
to provide us with your value-able Feedbackin Comments.
22. ^foo^bar Command
Run the last command with modification, in a single instance. Suppose I need to run acommand ls -l to long list the content of a directory say Desktop. Accidentally, you type
lls -l. So now you will have to retype the whole command or edit the previous command
using navigation key. That is painful when the command is long.
avi@localhost:~/Desktop$ lls -l
bash: lls: command not found
avi@localhost:~/Desktop$ ^lls^ls
ls -l
total 7489440
7/24/2019 Linux Some Commands
18/79
drwxr-xr-x 2 avi avi 36864 Nov 13 2012101MSDCF
-rw-r--r-- 1 avi avi 206833 Nov 5 15:27 1.jpg
-rw-r--r-- 1 avi avi 158951 Nov 5 15:27 2.jpg
-rw-r--r-- 1 avi avi 90624 Nov 5 12:59Untitled 1.doc
Note: In the above replacement we used ^typo(to be replaced)^original_command.
This command may be very dangerous if you knowingly or unknowingly replaced the typo
with system command or anything risky say rm -rf.
23. > file.txt Command
This command flush the contents of a file without the need of removing and creating thesame file again. This command is very useful in scripting language when we need an output
or log on the same file again and again.
I have a file say test.txton my Desktop with a lot of text.
avi@localhost:~/Desktop$ cat test.txt
Linux
GNU
Debian
Fedora
kali
ubuntu
git
Linus
Torvalds
avi@localhost:~/Desktop$ > test.txt
avi@localhost:~/Desktop$ cat test.txt
7/24/2019 Linux Some Commands
19/79
Note: Again, this command can be dangerous, dont ever try to flush the contents of a
system file or configuration file. If you do so, you will be in serious trouble.
24. at CommandThe at command is similar tocron commandand can be used for scheduling a task or
command to run at specified time.
avi@localhost:~/Desktop$ echo "ls -l > /dev/pts/0" |at 14:012
OR
avi@localhost:~/Desktop$ echo "ls -l > /dev/pts/0" |at 2:12 PM
Sample Output
-rw-r--r-- 1 avi avi 220492 Nov 1 13:49Screenshot-1.png
-rw-r--r-- 1 root root 358 Oct 17 10:11
sources.list
-rw-r--r-- 1 avi avi 4695982080 Oct 10 20:29squeeze.iso
..
..
-rw-r--r-- 1 avi avi 90624 Nov 5 12:59
Untitled 1.doc
-rw-r--r-- 1 avi avi 96206 Nov 5 12:56Untitled 1.odt
-rw-r--r-- 1 avi avi 9405 Nov 12 23:22Untitled.png
Note: echo ls -l : This string echos the command (herels -l) on standard terminal. You
can replace ls -l with any command of your need and choice.
> : redirects the output
http://www.tecmint.com/11-cron-scheduling-task-examples-in-linux/http://www.tecmint.com/11-cron-scheduling-task-examples-in-linux/http://www.tecmint.com/11-cron-scheduling-task-examples-in-linux/http://www.tecmint.com/11-cron-scheduling-task-examples-in-linux/7/24/2019 Linux Some Commands
20/79
The /dev/pts/0: This is the output device and/or file, where output is sought, here the
output is at terminal.
In my case, my tty is at /dev/pts/0, at that time. You can check your tty by running
commandtty.
avi@localhost:~/Desktop$ tty
/dev/pts/0
Note: The at command execute the task as soon as the system clock matches the
specified time.
25. du -hmax-depth=1 Command
The below command outputs the size of sub-folders within the current directory, in humanreadable format.
avi@localhost:/home/avi/Desktop# du -h --max-depth=1
38M ./test
1.1G ./shivji
42M ./drupal
6.9G ./101MSDCF
16G .
Note: The above command can be very much useful inchecking system disk usage.
Download Linux Command Line Cheat Sheet
http://www.tecmint.com/check-linux-disk-usage-of-files-and-directories/http://www.tecmint.com/check-linux-disk-usage-of-files-and-directories/http://www.tecmint.com/check-linux-disk-usage-of-files-and-directories/http://tecmint.tradepub.com/free/w_makb09/prgm.cgihttp://tecmint.tradepub.com/free/w_makb09/prgm.cgihttp://tecmint.tradepub.com/free/w_makb09/prgm.cgihttp://www.tecmint.com/check-linux-disk-usage-of-files-and-directories/7/24/2019 Linux Some Commands
21/79
26. expr CommandThe expr command is not that much lesser known command. This command is very much
useful in carrying out simple mathematical calculation in terminal.
avi@localhost:/home/avi/Desktop# expr 2 + 3
5
avi@localhost:/home/avi/Desktop# expr 6 3
3
avi@localhost:/home/avi/Desktop# expr 12 / 3
4
avi@localhost:/home/avi/Desktop# expr 2 \* 9
18
27. look CommandCheck for words from English dictionary in case of confusion, from the terminal itself. Viz.,
I am a bit confused if the spelling is carrier or carieer.
avi@localhost:/home/avi/Documents# look car
Cara
Cara's
http://tecmint.tradepub.com/free/w_makb09/prgm.cgihttp://tecmint.tradepub.com/free/w_makb09/prgm.cgihttp://tecmint.tradepub.com/free/w_makb09/prgm.cgi7/24/2019 Linux Some Commands
22/79
...
carps
carpus
carpus's
carrel
carrel's
carrels
carriage
carriage's
carriages
carriageway
carriageway's
carried
carriercarrier'scarrierscarries...caryatids
The above command showed all the words from dictionary starting with string car. I gotwhat I was searching for.
28. yes CommandAnother command which is not used frequently on regular basis, normally but is very useful
in scripting language and for system Administrators.
This command continues to print a given string, till interrupt instruction is given by you.
avi@localhost:~/Desktop$ yes "Tecmint is one of thebest site dedicated to Linux, how to"
7/24/2019 Linux Some Commands
23/79
Tecmint is one of the best site dedicated to Linux,how to
Tecmint is one of the best site dedicated to Linux,how to
Tecmint is one of the best site dedicated to Linux,how to
Tecmint is one of the best site dedicated to Linux,how to
...
Tecmint is one of the best site dedicated to Linux,how to
Tecmint is one of the best site dedicated to Linux,how to
Tecmint is one of the best site dedicated to Linux,
how to
29. factor CommandThe factor command is actually a command of mathematical origin. This command outputs
all the factors of a given number.
avi@localhost:~/Desktop$ factor 22
22: 2 11
avi@localhost:~/Desktop$ factor 21
21: 3 7
avi@localhost:~/Desktop$ factor 11
11: 11
30. ping -i 60 -a IP_address
7/24/2019 Linux Some Commands
24/79
All of us use ping command to check is server is live or not. And I usually ping google, to
check if I am connected to internet or not.
It is sometimes irritating, when you wait and keep watching your terminal to get reply of
ping command or say, wait for server to get connected.
How about an audible sound as soon as the server comes live.
avi@localhost:~/Desktop$ ping -i 60 -a www.google.com
PING www.google.com (74.125.200.103) 56(84) bytes ofdata.
64 bytes from www.google.com (74.125.200.103):icmp_req=1 ttl=44 time=105 ms
64 bytes from 74.125.200.103: icmp_req=2 ttl=44time=281 ms
Let me tell you one thing, before you report that the command didnt return any audible
sound. Make sure your system audio is not mute, sound theme must be enabled in sound
preferences and make sure Enable window and window sound is checked.
31. tac CommandThis command is very interesting which prints the content of a text file in reverse
order,i.e., from last line to first line.
I have a text file 35.txt in my Documents directory, under home folder. Checking its content
usingcat command.
avi@localhost:~/Documents$ cat 35.txt
Sample Output
1. Linux is built with certain powerful tools, whichare unavailable in windows.
2. One of such important tool is Shell Scripting.Windows however comes with such a tool but as usualit is much weak as compared to it's LinuxCounterpart.
http://www.tecmint.com/13-basic-cat-command-examples-in-linux/http://www.tecmint.com/13-basic-cat-command-examples-in-linux/http://www.tecmint.com/13-basic-cat-command-examples-in-linux/http://www.tecmint.com/13-basic-cat-command-examples-in-linux/7/24/2019 Linux Some Commands
25/79
3.Shell scripting/programming makes it possible toexecute command(s), piped to get desired output inorder to automate day-to-day usages.
Now reverse the content of file using tac command.
avi@localhost:~/Documents$ tac 35.txt
Sample Output
3.Shell scripting/programming makes it possible toexecute command(s), piped to get desired output inorder to automate day-to-day usages.
2. One of such important tool is Shell Scripting.Windows however comes with such a tool but as usualit is much weak as compared to it's LinuxCounterpart.
1. Linux is built with certain powerful tools, whichare unavailable in windows.
Thats all for now. If you are aware of other lesser known Linux commands, you can put a
comment, so that we can include those in our future articles.
Dont forget to provide us with your value-able comment. Ill be soon coming with another
interesting article, very soon. Till then stay tuned and connected to Tecmint.
42. lsb_releaseThe command lsb_release print distribution-specific information. If lsb_release is not
installed, you can apt lsb-core onDebianor yum redhat-lsb onRed Hatthe package.
# lsb_release -a
LSB Version: :base-4.0-ia32:base-4.0-noarch:core-4.0-ia32:core-4.0-noarch:graphics-4.0-ia32:
Distributor ID: CentOS
Description: CentOS release 6.3 (Final)
7/24/2019 Linux Some Commands
26/79
Release: 6.3
Codename: Final
Note: Option -a, shows all the available information in respect
of version, id, description,releaseand codename.
43. nc -zv localhost 80Check if port 80is open or not. We can replace 80 with any other port number to check if
it is opened or closed.
$ nc -zv localhost 80
Connection to localhost 80 port [tcp/http] succeeded!
Check if port 8080is open or not.
$ nc -zv localhost 8080
nc: connect to localhost port 8080 (tcp) failed:Connection refused
44. curl ipinfo.ioThe below command will output the Geographical Location of theIP address, provided.
$ curl ipinfo.io
"ip": "xx.xx.xx.xx",
"hostname": "triband-del-aa.bbb.cc.ddd.bol.net.in",
"city": null,
"region": null,
"country": "IN",
"loc": "20,77",
"org": "AS17813 Mahanagar Telephone Nigam Ltd."
7/24/2019 Linux Some Commands
27/79
45. find . -user rootThe below command output the files with respect of the user (root) owned files. All the files
owned by user root in the current directory.
# find . -user root
./.recently-used.xbel
./.mysql_history
./.aptitude
./.aptitude/config
./.aptitude/cache
./.bluefish
./.bluefish/session-2.0
./.bluefish/autosave
./.bash_history
All the files owned by user avi in the current directory.
# find . -user avi
./.cache/chromium/Cache/f_002b66
./.cache/chromium/Cache/f_001719
./.cache/chromium/Cache/f_001262
./.cache/chromium/Cache/f_000544
./.cache/chromium/Cache/f_002e40
./.cache/chromium/Cache/f_00119a
./.cache/chromium/Cache/f_0014fc
7/24/2019 Linux Some Commands
28/79
./.cache/chromium/Cache/f_001b52
./.cache/chromium/Cache/f_00198d
./.cache/chromium/Cache/f_003680
46. sudo apt-get build-dep ffmpegThe below command will build the dependency, automatically during the corresponding
package installation. Hence the process of package installation is very much fluent and
easy.
# apt-get build-dep ffmpeg
libxinerama-dev libxml-namespacesupport-perl libxml-sax-expat-perl
libxml-sax-perl libxml-simple-perl libxrandr-devlibxrender-dev
x11proto-render-dev x11proto-xinerama-dev xulrunner-dev
The following packages will be upgraded:
libpixman-1-0
1 upgraded, 143 newly installed, 0 to remove and 6not upgraded.
Need to get 205 MB of archives.
After this operation, 448 MB of additional disk space
will be used.
Do you want to continue [Y/n]?
47. lsof -iTCP:80 -sTCP:LISTENThe below command outputs, name of process/serviceusing a specific port 80. To better
understand run the following command on port 80, it will list all services/processesrunning
on port.
root@localhost:/home/avi# lsof -iTCP:80 -sTCP:LISTEN
7/24/2019 Linux Some Commands
29/79
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
apache2 1566 root 5u IPv6 5805 0t0 TCP *:www (LISTEN)
apache2 1664 www-data 5u IPv6 5805 0t0 TCP *:www(LISTEN)
apache2 1665 www-data 5u IPv6 5805 0t0 TCP *:www(LISTEN)
apache2 1666 www-data 5u IPv6 5805 0t0 TCP *:www(LISTEN)
apache2 1667 www-data 5u IPv6 5805 0t0 TCP *:www(LISTEN)
apache2 1668 www-data 5u IPv6 5805 0t0 TCP *:www(LISTEN)
Same way, you can also check the running services/processes of port 22.
root@localhost:/home/avi# lsof -iTCP:22 -sTCP:LISTEN
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
sshd 2261 root 3u IPv4 8366 0t0 TCP *:ssh (LISTEN)
sshd 2261 root 4u IPv6 8369 0t0 TCP *:ssh (LISTEN)
48. find -size +100MThe find command lists all the files in the current directory above the specified size
(here 100 MB), recursively.
# find -size +100M
./.local/share/Trash/files/linuxmint-15-cinnamon-dvd-32bit.iso
./Downloads/Fedora-Live-Desktop-i686-19-1.iso
./Downloads/Ant Videos/shakira 2.avi
7/24/2019 Linux Some Commands
30/79
./Downloads/Deewar.avi
./Desktop/101MSDCF/MOV02224.AVI
./Desktop/101MSDCF/MOV02020.AVI
./Desktop/101MSDCF/MOV00406.MP4
./Desktop/squeeze.iso
Listing all the files whose size if more than 1000 MB, within current directory, recursively.
root@localhost:/home/avi# find -size +1000M
./Downloads/The Dark Knight 2008 hindi BRRip 720p/TheDark Knight.mkv.part
./Downloads/Saudagar - (1991) - DVDRiP - x264 - AAC5.1 - Chapters - Esubs - [DDR]/Saudagar
- (1991) - DVDRiP - x264 - AAC 5.1 - Chapters - Esubs- [DDR].mkv
./Downloads/Deewar.avi
./Desktop/squeeze.iso
49. pdftkThe pdftk command merges several pdf files into one. You must have
installed pdftkprogram. If not, do apt or yum to get the required package.
$ pdftk 1.pdf 2.pdf 3.pdf . 10.pdf cat output
merged.pdf
50. ps -LF -u user_nameThe below command outputs processes and threads of a user. The option L (list threads)
and -F (Full Format Listing).
$ ps -LF -u avi
7/24/2019 Linux Some Commands
31/79
avi 21645 3717 21766 0 5 66168 117164 1 18:58 ?00:00:00 /usr/
avi 21645 3717 21768 0 5 66168 117164 1 18:58 ?00:00:00 /usr/
avi 22314 3717 22314 0 2 42797 50332 0 19:00 ?00:00:40 /usr/
avi 22314 3717 22316 0 2 42797 50332 1 19:00 ?00:00:00 /usr/
avi 22678 24621 22678 0 1 969 1060 1 21:05 pts/100:00:00 ps -L
avi 23051 3717 23051 0 2 37583 45444 1 19:03 ?00:00:52 /usr/
avi 23051 3717 23053 0 2 37583 45444 0 19:03 ?00:00:03 /usr/
avi 23652 1 23652 0 2 22092 12520 0 19:06 ? 00:00:22gnome
avi 23652 1 23655 0 2 22092 12520 0 19:06 ? 00:00:00
gnome
51. Startx :1Sharing Xsession, means frequently logging in and out, this is where the Startxcommand
comes to rescue. The command creates a new session thus no need to login and logout
frequently from a session. In order to switch between the two Xsession, we need to switch
between ctrl+Alt+F7 and ctrl+Alt+F8.
Note: The keys ctrl+Alt+F1, ctrl+Alt+F6 is for console session, and ctrl+Alt+F7,
ctrl+Alt+F12 is for X session. Hence6console session and 6X session, without frequent
logging-in and out. The above sequence works on most of the distro, however differentdistro may have implemented it differently. I have checked it on Debian, and it works
perfectly fine.
Thats all for now. We will be keep coming up with other lesser know commands and one
liner script as required, in future articles. Do not forget to give your valueable feedback
about our article and series LesserKnown Linux Commands. I am coming with my next
article very soon, till then, stay healthy, tuned and connected to Tecmint.
32. strace Command
7/24/2019 Linux Some Commands
32/79
The straceis a debugging tool which is used primarily for troubleshooting purpose in Linux.
It might not be installed by default in your system and you may need to aptor yum the
required package.
Trace a command execution using stracecommand:
root@tecmint [~]# strace pwd
Sample Output
execve("/bin/pwd", ["pwd"], [/* 29 vars */]) = 0
brk(0) = 0x728000
mmap(NULL, 4096, PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f29b0df2000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT(No such file or directory)
open("/etc/ld.so.cache", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=38427, ...})= 0
mmap(NULL, 38427, PROT_READ, MAP_PRIVATE, 3, 0) =0x7f29b0de8000
close(3) = 0
open("/lib64/libc.so.6", O_RDONLY) = 3
read(3,"\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\360\355\1I;\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1922152,...}) = 0
mmap(0x3b49000000, 3745960, PROT_READ|PROT_EXEC,MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x3b49000000
mprotect(0x3b4918a000, 2093056, PROT_NONE) = 0
mmap(0x3b49389000, 20480, PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x189000) =
0x3b49389000
7/24/2019 Linux Some Commands
33/79
mmap(0x3b4938e000, 18600, PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) =0x3b4938e000
close(3) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f29b0de7000
mmap(NULL, 4096, PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f29b0de6000
mmap(NULL, 4096, PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f29b0de5000
....
The stracecommand accepts a lot of arguments and have many options. Refer to man
page for detailed information.
33. disown -a && exit CommandMost of the system administrators use screen command to control jobs running in the
terminal background. Lets say if you having a long running job and want to detachfrom
the terminal, you use screencommand to do it. But what if you dont know how to use
screen, here comes disown command to rescue.
The disown command is used to run the jobs continuously in the background even afteryou closing the terminal session. The syntax of the disown command is:
root@tecmint [~]# Command; disown -a && exit
To detach again the long running job in the terminal, use thejobscommand to find the job
number and then use disown %nwhere nis the job number. To verify actually the job is
running use psortop command.The nohupcommand is an alternative to the disown
command.
34. getconf LONG_BIT Command
The above command shows your machine architecture if it is 32bit or 64bit?
root@tecmint [~]# getconf LONG_BIT
32
Download Linux Command Line Cheat Sheet
http://www.tecmint.com/screen-command-examples-to-manage-linux-terminals/http://www.tecmint.com/screen-command-examples-to-manage-linux-terminals/http://www.tecmint.com/12-top-command-examples-in-linux/http://www.tecmint.com/12-top-command-examples-in-linux/http://www.tecmint.com/12-top-command-examples-in-linux/http://tecmint.tradepub.com/free/w_makb09/prgm.cgihttp://tecmint.tradepub.com/free/w_makb09/prgm.cgihttp://tecmint.tradepub.com/free/w_makb09/prgm.cgihttp://www.tecmint.com/12-top-command-examples-in-linux/http://www.tecmint.com/screen-command-examples-to-manage-linux-terminals/7/24/2019 Linux Some Commands
34/79
35. Display Date on the TerminalThe below command is a combination of several commands, better say it a script. For a
person working at shell or terminal, without GUI seeing current system date is tedious job.
You have to type date command to check todays date.
Just execute the below command on you prompt and see the dateand timeon the above
right corner of terminal.
root@tecmint [~]# while sleep 1;do tput sc;tput cup 0$(($(tput cols)-29));date;tput rc;done &
Show Date in Terminal
36. convert CommandWhile writing tutorial, I usually need to produce output, many a times in image format. The
above command combination does this for me. Say I need the output of tree command (for
/etc/x11directory) in image format. What I did at terminal was:
root@tecmint:/etc/X11# tree | convert label:@-
/home/avi/tree.png
http://tecmint.tradepub.com/free/w_makb09/prgm.cgihttp://www.tecmint.com/wp-content/uploads/2013/11/Date.jpghttp://tecmint.tradepub.com/free/w_makb09/prgm.cgihttp://www.tecmint.com/wp-content/uploads/2013/11/Date.jpghttp://tecmint.tradepub.com/free/w_makb09/prgm.cgi7/24/2019 Linux Some Commands
35/79
The output of the above command can be seen at the specified location (here, home
directory of mine) with the file name specified as tree.png.
37. watch -t -n1 date +%T|figletRemember our description of figlet command in our earlier article 20 Funny
Commands of Linux. This command was very cool, this time we will be pipelining figletto show animated digital clock in the terminal.
Just check-out yourself, remember you must have figlet installed on the system,
do aptoryumto install the required package.
root@tecmint [~]# watch -t -n1 "date +%T|figlet"
Sample Output
_ ___ ____ ___ _____ _ _
Fri Nov 29 10:29:34 GMT
/ |/ _ \ _|___ \ / _ \ _|___ /| || |
| | | | (_) __) | (_) (_) |_ \| || |_
| | |_| |_ / __/ \__, |_ ___) |__ _|
|_|\___/(_)_____| /_/(_)____/ |_|
38. host and dig CommandsAlthough host and dig command is not that much lesser known, still not very frequently
used. The host command is DNSlookup utility.
root@tecmint [~]# host www.google.com
www.google.com has address 173.194.66.147
www.google.com has address 173.194.66.105
www.google.com has address 173.194.66.99
www.google.com has address 173.194.66.104
www.google.com has address 173.194.66.106
www.google.com has address 173.194.66.103
http://www.tecmint.com/20-funny-commands-of-linux-or-linux-is-fun-in-terminal/http://www.tecmint.com/20-funny-commands-of-linux-or-linux-is-fun-in-terminal/http://www.tecmint.com/20-funny-commands-of-linux-or-linux-is-fun-in-terminal/http://www.tecmint.com/20-funny-commands-of-linux-or-linux-is-fun-in-terminal/http://www.tecmint.com/20-funny-commands-of-linux-or-linux-is-fun-in-terminal/http://www.tecmint.com/20-funny-commands-of-linux-or-linux-is-fun-in-terminal/7/24/2019 Linux Some Commands
36/79
www.google.com has IPv6 address2a00:1450:400c:c03::68
root@tecmint [~]# dig www.google.com
; DiG 9.8.2rc1-RedHat-9.8.2-0.17.rc1.el6_4.6 www.google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADERprompt.
[root@tecmint ~]# sftp [email protected]
Connecting to 27.48.137.6...
http://www.tecmint.com/scp-commands-examples/http://www.tecmint.com/scp-commands-examples/http://www.tecmint.com/scp-commands-examples/http://www.tecmint.com/5-best-practices-to-secure-and-protect-ssh-server/http://www.tecmint.com/5-best-practices-to-secure-and-protect-ssh-server/http://www.tecmint.com/10-wget-command-examples-in-linux/http://www.tecmint.com/10-wget-command-examples-in-linux/http://www.tecmint.com/wp-content/uploads/2014/02/sftp-commands.pnghttp://www.tecmint.com/10-wget-command-examples-in-linux/http://www.tecmint.com/5-best-practices-to-secure-and-protect-ssh-server/http://www.tecmint.com/scp-commands-examples/http://www.tecmint.com/wp-content/uploads/2014/02/sftp-commands.png7/24/2019 Linux Some Commands
40/79
[email protected]'s password:
sftp>
2. Getting Help
Once, you in the sftp prompt, check the available commands by typing ? or help at commandprompt.
sftp> ?
Available commands:
cd path Change remote directoryto 'path'
lcd path Change local directoryto 'path'
chgrp grp path Change group of file'path' to 'grp'
chmod mode path Change permissions offile 'path' to 'mode'
chown own path Change owner of file
'path' to 'own'
help Display this help text
get remote-path [local-path] Download file
lls [ls-options [path]] Display local directorylisting
ln oldpath newpath Symlink remote file
lmkdir path Create local directory
lpwd Print local workingdirectory
ls [path] Display remotedirectory listing
lumask umask Set local umask to
'umask'
7/24/2019 Linux Some Commands
41/79
mkdir path Create remote directory
put local-path [remote-path] Upload file
pwd Display remote workingdirectory
exit Quit sftp
quit Quit sftp
rename oldpath newpath Rename remote file
rmdir path Remove remote directory
rm path Delete remote file
symlink oldpath newpath Symlink remote file
version Show SFTP version
!command Execute 'command' inlocal shell
! Escape to local shell
? Synonym for help
3. Check Present Working DirectoryThe command lpwd is used to check the Localpresent working directory, whereas pwd
command is used to check Remoteworking directory.
sftp> lpwd
Local working directory: /
sftp> pwd
Remote working directory: /tecmint/
o lpwdprint the current directory on your system
o pwdprint the current directory on the ftp server
4. Listing FilesListing files and directories in local as well as remote system.
On Remote
7/24/2019 Linux Some Commands
42/79
sftp> ls
On Local
sftp> lls
5. Upload FilePut single or multiple files in remote system.
sftp> put local.profile
Uploading local.profile to /tecmint/local.profile
6. Upload Mutiple FilesPutting multiple files on in remote system.
sftp> mput *.xls
6. Download FilesGetting single or multiple files in local system.
sftp> get SettlementReport_1-10th.xls
Fetching /tecmint/SettlementReport_1-10th.xls toSettlementReport_1-10th.xls
Get multiple files on a local system.
sftp> mget *.xls
Note: As we can see by default with get commanddownload file in local system with same name.
We can download remote file with different name specifying the name at the end. (This applies only
while downloading single file).
7. Switching DirectoriesSwitching from one directory to another directory in local and remote locations.
On Remote
sftp> cd test
sftp>
On Local
sftp> lcd Documents
7/24/2019 Linux Some Commands
43/79
8. Create DirectoriesCreating new directories on local and remote locations.
sftp> mkdir test
sftp> lmkdir Documents
9. Remove DirectoriesRemove directory or file in remote system.
sftp> rm Report.xls
sftp> rmdir sub1
Note: To remove/delete any directory from remote location, the directory must be empty.
10. Exist sFTP ShellThe ! command drop us in local shell from where we can execute Linux commands. Type exit
command where we can see sftp>prompt return.
sftp> !
[root@sftp ~]# exit
Shell exited with status 1
sftp>
ConclusionThe SFTP is a very useful tool for administrating servers and transferring files to and from
(Localand Remote). We hope this tuts will help you to understand the usage of SFTPin some
extent.
7/24/2019 Linux Some Commands
44/79
20 Linux System Monitoring Tools EverySysAdmin Should KnowbyNIX CRAFT on JUNE 27, 2009 342 COMMENTSLAST UPDATED JANUARY 1, 2014
inCENTOS,DEBIAN LINUX, FEDORA LINUX
Need to monitor Linux server performance? Trythese built-in commands and a few add-on tools. MostLinux distributions are equipped with tons ofmonitoring. These tools provide metrics which can beused to get information about system activities. Youcan use these tools to find the possible causes of a
performance problem. The commands discussedbelow are some of the most basic commands when itcomes to system analysis and debugging serverissues such as:1. Finding out bottlenecks.2. Disk (storage) bottlenecks.3. CPU and memory bottlenecks.4. Network bottlenecks.
#1: top - Process Activity Command
The top program provides a dynamic real-time view ofa running system i.e. actual process activity. Bydefault, it displays the most CPU-intensive tasks
running on the server and updates the list every fiveseconds.
http://www.cyberciti.biz/tips/about-ushttp://www.cyberciti.biz/tips/about-ushttp://www.cyberciti.biz/tips/about-ushttp://www.cyberciti.biz/tips/top-linux-monitoring-tools.html#commentshttp://www.cyberciti.biz/tips/top-linux-monitoring-tools.html#commentshttp://www.cyberciti.biz/tips/top-linux-monitoring-tools.html#commentshttp://www.cyberciti.biz/tips/category/centoshttp://www.cyberciti.biz/tips/category/centoshttp://www.cyberciti.biz/tips/category/debian-linuxhttp://www.cyberciti.biz/tips/category/fedora-linuxhttp://www.cyberciti.biz/tips/category/fedora-linuxhttp://www.cyberciti.biz/tips/category/linuxhttp://www.cyberciti.biz/tips/category/fedora-linuxhttp://www.cyberciti.biz/tips/category/debian-linuxhttp://www.cyberciti.biz/tips/category/centoshttp://www.cyberciti.biz/tips/top-linux-monitoring-tools.html#commentshttp://www.cyberciti.biz/tips/about-us7/24/2019 Linux Some Commands
45/79
Fig.01: Linux top command
Commonly Used Hot Keys
The top command provides several useful hot keys:
Hot
KeyUsage
t Displays summary information off and on.m Displays memory information off and on.
ASorts the display by top consumers of various system resources. Useful for
quick identification of performance-hungry tasks on a system.
fEnters an interactive configuration screen for top. Helpful for setting up top
for a specific task.
o Enables you to interactively select the ordering within top.
r Issues renice command.
k Issues kill command.
z Turn on or off color/mono
=> Related:How do I Find Out Linux CPU Utilization?
#2: vmstat - System Activity, Hardwareand System Information
The command vmstat reports information about
processes, memory, paging, block IO, traps, and cpuactivity.
http://www.cyberciti.biz/tips/how-do-i-find-out-linux-cpu-utilization.htmlhttp://www.cyberciti.biz/tips/how-do-i-find-out-linux-cpu-utilization.htmlhttp://www.cyberciti.biz/tips/how-do-i-find-out-linux-cpu-utilization.htmlhttp://www.cyberciti.biz/tips/top-linux-monitoring-tools.html/top-outputhttp://www.cyberciti.biz/tips/how-do-i-find-out-linux-cpu-utilization.html7/24/2019 Linux Some Commands
46/79
# vmstat 3
Sample Outputs:
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
r b swpd free buff cache si so bibo in cs us sy id wa st
0 0 0 2540988 522188 5130400 0 0 232 4 2 4 1 96 0 0
1 0 0 2540988 522188 5130400 0 0 0720 1199 665 1 0 99 0 0
0 0 0 2540956 522188 5130400 0 0 00 1151 1569 4 1 95 0 0
0 0 0 2540956 522188 5130500 0 0 0
6 1117 439 1 0 99 0 0
0 0 0 2540940 522188 5130512 0 0 0536 1189 932 1 0 98 0 0
0 0 0 2538444 522188 5130588 0 0 00 1187 1417 4 1 96 0 0
0 0 0 2490060 522188 5130640 0 0 018 1253 1123 5 1 94 0 0
Display Memory Utilization Slabinfo
# vmstat -m
7/24/2019 Linux Some Commands
47/79
Get Information About Active / InactiveMemory Pages
# vmstat -a => Related:How do I find out Linux Resourceutilization to detect system bottlenecks?
#3: w - Find Out Who Is Logged on AndWhat They Are Doing
w command displays information about the userscurrently on the machine, and their processes.
# w username
# w vivek
Sample Outputs:
17:58:47 up 5 days, 20:28, 2 users, load average:
0.36, 0.26, 0.24
USER TTY FROM LOGIN@ IDLEJCPU PCPU WHAT
root pts/0 10.1.3.145 14:55 5.00s0.04s 0.02s vim /etc/resolv.conf
root pts/1 10.1.3.145 17:43 0.00s0.03s 0.00s w
#4: uptime - Tell How Long The SystemHas Been Running
The uptime command can be used to see how long the
server has been running. The current time, how long
http://www.cyberciti.biz/tips/linux-resource-utilization-to-detect-system-bottlenecks.htmlhttp://www.cyberciti.biz/tips/linux-resource-utilization-to-detect-system-bottlenecks.htmlhttp://www.cyberciti.biz/tips/linux-resource-utilization-to-detect-system-bottlenecks.htmlhttp://www.cyberciti.biz/tips/linux-resource-utilization-to-detect-system-bottlenecks.htmlhttp://www.cyberciti.biz/tips/linux-resource-utilization-to-detect-system-bottlenecks.htmlhttp://www.cyberciti.biz/tips/linux-resource-utilization-to-detect-system-bottlenecks.html7/24/2019 Linux Some Commands
48/79
the system has been running, how many users arecurrently logged on, and the system load averages forthe past 1, 5, and 15 minutes.
# uptime Output:
18:02:41 up 41 days, 23:42, 1 user, load average:0.00, 0.00, 0.00
1 can be considered as optimal load value. The load
can change from system to system. For a single CPUsystem 1 - 3 and SMP systems 6-10 load value mightbe acceptable.
#5: ps - Displays The Processes
ps command will report a snapshot of the currentprocesses. To select all processes use the -A or -e
option:# ps -A
Sample Outputs:
PID TTY TIME CMD
1 ? 00:00:02 init
2 ? 00:00:02 migration/0
3 ? 00:00:01 ksoftirqd/0
4 ? 00:00:00 watchdog/0
5 ? 00:00:00 migration/1
7/24/2019 Linux Some Commands
49/79
6 ? 00:00:15 ksoftirqd/1
....
.....
4881 ? 00:53:28 java
4885 tty1 00:00:00 mingetty
4886 tty2 00:00:00 mingetty
4887 tty3 00:00:00 mingetty
4888 tty4 00:00:00 mingetty
4891 tty5 00:00:00 mingetty
4892 tty6 00:00:00 mingetty
4893 ttyS1 00:00:00 agetty
12853 ? 00:00:00 cifsoplockd
12854 ? 00:00:00 cifsdnotifyd
14231 ? 00:10:34 lighttpd
14232 ? 00:00:00 php-cgi
54981 pts/0 00:00:00 vim
55465 ? 00:00:00 php-cgi
7/24/2019 Linux Some Commands
50/79
55546 ? 00:00:00 bind9-snmp-stat
55704 pts/1 00:00:00 ps
ps is just like top but provides more information.
Show Long Format Output
# ps -Al
To turn on extra full mode (it will show command linearguments passed to process):
# ps -AlF
To See Threads ( LWP and NLWP)
# ps -AlFH
To See Threads After Processes
# ps -AlLm
Print All Process On The Server
# ps ax
# ps axu
Print A Process Tree
7/24/2019 Linux Some Commands
51/79
# ps -ejH
# ps axjf
# pstree
Print Security Information
# ps -eo euser,ruser,suser,fuser,f,comm,label
# ps axZ
# ps -eM
See Every Process Running As UserVivek
# ps -U vivek -u vivek u
Set Output In a User-Defined Format
# ps -eo
pid,tid,class,rtprio,ni,pri,psr,pcpu,stat,wchan:1
4,comm
# ps axo
stat,euid,ruid,tty,tpgid,sess,pgrp,ppid,pid,pcpu,
comm
# ps -eopid,tt,user,fname,tmout,f,wchan
7/24/2019 Linux Some Commands
52/79
Display Only The Process IDs of Lighttpd
# ps -C lighttpd -o pid=
OR# pgrep lighttpd
OR
# pgrep -u vivek php-cgi
Display The Name of PID 55977
# ps -p 55977 -o comm=
Find Out The Top 10 Memory ConsumingProcess
# ps -auxf | sort -nr -k 4 | head -10
Find Out top 10 CPU Consuming Process
# ps -auxf | sort -nr -k 3 | head -10
#6: free - Memory Usage
The command free displays the total amount of freeand used physical and swap memory in the system, aswell as the buffers used by the kernel.
# free
Sample Output:
total used free shared
buffers cached
7/24/2019 Linux Some Commands
53/79
Mem: 12302896 9739664 2563232 0523124 5154740
-/+ buffers/cache: 4061800 8241096
Swap: 1052248 0 1052248
=> Related::1.Linux Find Out Virtual Memory PAGESIZE2.Linux Limit CPU Usage Per Process
3. How much RAM does my Ubuntu / Fedora Linuxdesktop PC have?
#7: iostat - Average CPU Load, DiskActivity
The command iostat report Central Processing Unit(CPU) statistics and input/output statistics for devices,partitions and network filesystems (NFS).
# iostat
Sample Outputs:
Linux 2.6.18-128.1.14.el5 (www03.nixcraft.in)06/26/2009
avg-cpu: %user %nice %system %iowait %steal%idle
3.50 0.09 0.51 0.03 0.0095.86
Device: tps Blk_read/s Blk_wrtn/sBlk_read Blk_wrtn
http://www.cyberciti.biz/faq/linux-check-the-size-of-pagesize/http://www.cyberciti.biz/faq/linux-check-the-size-of-pagesize/http://www.cyberciti.biz/faq/linux-check-the-size-of-pagesize/http://www.cyberciti.biz/faq/cpu-usage-limiter-for-linux/http://www.cyberciti.biz/faq/cpu-usage-limiter-for-linux/http://www.cyberciti.biz/faq/cpu-usage-limiter-for-linux/http://www.cyberciti.biz/tips/how-much-ram-does-my-linux-system.htmlhttp://www.cyberciti.biz/tips/how-much-ram-does-my-linux-system.htmlhttp://www.cyberciti.biz/tips/how-much-ram-does-my-linux-system.htmlhttp://www.cyberciti.biz/tips/how-much-ram-does-my-linux-system.htmlhttp://www.cyberciti.biz/tips/how-much-ram-does-my-linux-system.htmlhttp://www.cyberciti.biz/tips/how-much-ram-does-my-linux-system.htmlhttp://www.cyberciti.biz/faq/cpu-usage-limiter-for-linux/http://www.cyberciti.biz/faq/linux-check-the-size-of-pagesize/7/24/2019 Linux Some Commands
54/79
sda 22.04 31.88 512.0316193351 260102868
sda1 0.00 0.00 0.002166 180
sda2 22.04 31.87 512.0316189010 260102688
sda3 0.00 0.00 0.001615 0
=> Related::Linux Track NFS Directory / Disk I/OStats
#8: sar - Collect and Report SystemActivity
The sar command is used to collect, report, and savesystem activity information. To see network counter,enter:
# sar -n DEV | more
To display the network counters from the 24th:
# sar -n DEV -f /var/log/sa/sa24 | more
You can also display real time usage using sar:
# sar 4 5
Sample Outputs:
Linux 2.6.18-128.1.14.el5 (www03.nixcraft.in)06/26/2009
06:45:12 PM CPU %user %nice %system%iowait %steal %idle
http://www.cyberciti.biz/faq/howto-linux-track-nfs-client-disk-metrics/http://www.cyberciti.biz/faq/howto-linux-track-nfs-client-disk-metrics/http://www.cyberciti.biz/faq/howto-linux-track-nfs-client-disk-metrics/http://www.cyberciti.biz/faq/howto-linux-track-nfs-client-disk-metrics/http://www.cyberciti.biz/faq/howto-linux-track-nfs-client-disk-metrics/7/24/2019 Linux Some Commands
55/79
06:45:16 PM all 2.00 0.00 0.220.00 0.00 97.78
06:45:20 PM all 2.07 0.00 0.380.03 0.00 97.52
06:45:24 PM all 0.94 0.00 0.280.00 0.00 98.78
06:45:28 PM all 1.56 0.00 0.220.00 0.00 98.22
06:45:32 PM all 3.53 0.00 0.250.03 0.00 96.19
Average: all 2.02 0.00 0.270.01 0.00 97.70
=> Related::How to collect Linux system utilizationdata into a file
#9: mpstat - Multiprocessor Usage
The mpstat command displays activities for eachavailable processor, processor 0 being the first one.mpstat -P ALL to display average CPU utilization per
processor:
# mpstat -P ALL
Sample Output:
Linux 2.6.18-128.1.14.el5 (www03.nixcraft.in)06/26/2009
06:48:11 PM CPU %user %nice %sys %iowait%irq %soft %steal %idle intr/s
http://www.cyberciti.biz/tips/howto-write-system-utilization-data-to-file.htmlhttp://www.cyberciti.biz/tips/howto-write-system-utilization-data-to-file.htmlhttp://www.cyberciti.biz/tips/howto-write-system-utilization-data-to-file.htmlhttp://www.cyberciti.biz/tips/howto-write-system-utilization-data-to-file.htmlhttp://www.cyberciti.biz/tips/howto-write-system-utilization-data-to-file.htmlhttp://www.cyberciti.biz/tips/howto-write-system-utilization-data-to-file.html7/24/2019 Linux Some Commands
56/79
06:48:11 PM all 3.50 0.09 0.34 0.030.01 0.17 0.00 95.86 1218.04
06:48:11 PM 0 3.44 0.08 0.31 0.020.00 0.12 0.00 96.04 1000.31
06:48:11 PM 1 3.10 0.08 0.32 0.090.02 0.11 0.00 96.28 34.93
06:48:11 PM 2 4.16 0.11 0.36 0.020.00 0.11 0.00 95.25 0.00
06:48:11 PM 3 3.77 0.11 0.38 0.030.01 0.24 0.00 95.46 44.80
06:48:11 PM 4 2.96 0.07 0.29 0.040.02 0.10 0.00 96.52 25.91
06:48:11 PM 5 3.26 0.08 0.28 0.030.01 0.10 0.00 96.23 14.98
06:48:11 PM 6 4.00 0.10 0.34 0.010.00 0.13 0.00 95.42 3.75
06:48:11 PM 7 3.30 0.11 0.39 0.030.01 0.46 0.00 95.69 76.89
=> Related::Linux display each multiple SMP CPUprocessors utilization individually.
#10: pmap - Process Memory Usage
The command pmap report memory map of a process.
Use this command to find out causes of memorybottlenecks.
http://www.cyberciti.biz/faq/linux-mpstat-command-report-processors-related-statistics/http://www.cyberciti.biz/faq/linux-mpstat-command-report-processors-related-statistics/http://www.cyberciti.biz/faq/linux-mpstat-command-report-processors-related-statistics/http://www.cyberciti.biz/faq/linux-mpstat-command-report-processors-related-statistics/http://www.cyberciti.biz/faq/linux-mpstat-command-report-processors-related-statistics/7/24/2019 Linux Some Commands
57/79
# pmap -d PID
To display process memory information for pid #47394, enter:
# pmap -d 47394
Sample Outputs:
47394: /usr/bin/php-cgi
Address Kbytes Mode OffsetDevice Mapping
0000000000400000 2584 r-x-- 0000000000000000008:00002 php-cgi
0000000000886000 140 rw--- 0000000000286000008:00002 php-cgi
00000000008a9000 52 rw--- 00000000008a9000
000:00000 [ anon ]
0000000000aa8000 76 rw--- 00000000002a8000008:00002 php-cgi
000000000f678000 1980 rw--- 000000000f678000000:00000 [ anon ]
000000314a600000 112 r-x-- 0000000000000000008:00002 ld-2.5.so
000000314a81b000 4 r---- 000000000001b000008:00002 ld-2.5.so
000000314a81c000 4 rw--- 000000000001c000
008:00002 ld-2.5.so
7/24/2019 Linux Some Commands
58/79
000000314aa00000 1328 r-x-- 0000000000000000008:00002 libc-2.5.so
000000314ab4c000 2048 ----- 000000000014c000008:00002 libc-2.5.so
.....
......
..
00002af8d48fd000 4 rw--- 0000000000006000008:00002 xsl.so
00002af8d490c000 40 r-x-- 0000000000000000008:00002 libnss_files-2.5.so
00002af8d4916000 2044 ----- 000000000000a000008:00002 libnss_files-2.5.so
00002af8d4b15000 4 r---- 0000000000009000008:00002 libnss_files-2.5.so
00002af8d4b16000 4 rw--- 000000000000a000008:00002 libnss_files-2.5.so
00002af8d4b17000 768000 rw-s- 0000000000000000000:00009 zero (deleted)
00007fffc95fe000 84 rw--- 00007ffffffea000000:00000 [ stack ]
ffffffffff600000 8192 ----- 0000000000000000000:00000 [ anon ]
7/24/2019 Linux Some Commands
59/79
mapped: 933712K writeable/private: 4304Kshared: 768000K
The last line is very important:
mapped: 933712Ktotal amount of memory mappedto files
writeable/private: 4304Kthe amount of privateaddress space
shared: 768000Kthe amount of address space this
process is sharing with others=> Related::Linux find the memory used by aprogram / process using pmap command
#11 and #12: netstat and ss - NetworkStatistics
The command netstat displays network connections,
routing tables, interface statistics, masqueradeconnections, and multicast memberships. ss commandis used to dump socket statistics. It allows showinginformation similar to netstat. See the followingresources about ss and netstat commands:
ss: Display Linux TCP / UDP Network and Socket
Information Get Detailed Information About Particular IP address
Connections Using netstat Command
#13: iptraf - Real-time NetworkStatistics
The iptraf command is interactive colorful IP LAN
monitor. It is an ncurses-based IP LAN monitor that
http://www.cyberciti.biz/tips/howto-find-memory-used-by-program.htmlhttp://www.cyberciti.biz/tips/howto-find-memory-used-by-program.htmlhttp://www.cyberciti.biz/tips/howto-find-memory-used-by-program.htmlhttp://www.cyberciti.biz/tips/howto-find-memory-used-by-program.htmlhttp://www.cyberciti.biz/tips/linux-investigate-sockets-network-connections.htmlhttp://www.cyberciti.biz/tips/linux-investigate-sockets-network-connections.htmlhttp://www.cyberciti.biz/tips/linux-investigate-sockets-network-connections.htmlhttp://www.cyberciti.biz/tips/linux-investigate-sockets-network-connections.htmlhttp://www.cyberciti.biz/tips/linux-investigate-sockets-network-connections.htmlhttp://www.cyberciti.biz/tips/netstat-command-tutorial-examples.htmlhttp://www.cyberciti.biz/tips/netstat-command-tutorial-examples.htmlhttp://www.cyberciti.biz/tips/netstat-command-tutorial-examples.htmlhttp://www.cyberciti.biz/tips/netstat-command-tutorial-examples.htmlhttp://www.cyberciti.biz/tips/netstat-command-tutorial-examples.htmlhttp://www.cyberciti.biz/tips/netstat-command-tutorial-examples.htmlhttp://www.cyberciti.biz/tips/netstat-command-tutorial-examples.htmlhttp://www.cyberciti.biz/tips/linux-investigate-sockets-network-connections.htmlhttp://www.cyberciti.biz/tips/linux-investigate-sockets-network-connections.htmlhttp://www.cyberciti.biz/tips/howto-find-memory-used-by-program.htmlhttp://www.cyberciti.biz/tips/howto-find-memory-used-by-program.html7/24/2019 Linux Some Commands
60/79
generates various network statistics including TCPinfo, UDP counts, ICMP and OSPF information,Ethernet load info, node stats, IP checksum errors, and
others. It can provide the following info in easy to readformat:
Network traffic statistics by TCP connection IP traffic statistics by network interface Network traffic statistics by protocol Network traffic statistics by TCP/UDP port and by
packet size Network traffic statistics by Layer2 address
Fig.02: General interface statistics: IP traffic statistics by network
interface
http://www.cyberciti.biz/tips/top-linux-monitoring-tools.html/iptraf37/24/2019 Linux Some Commands
61/79
Fig.03 Network traffic statistics by TCP connection
#14: tcpdump - Detailed Network TrafficAnalysis
The tcpdump is simple command that dump traffic on anetwork. However, you need good understanding ofTCP/IP protocol to utilize this tool. For.e.g to displaytraffic info about DNS, enter:
# tcpdump -i eth1 'udp port 53'
To display all IPv4 HTTP packets to and from port 80,i.e. print only packets that contain data, not, forexample, SYN and FIN packets and ACK-only packets,enter:
# tcpdump 'tcp port 80 and (((ip[2:2] -
((ip[0]&0xf)2)) != 0)'
To display all FTP session to 202.54.1.5, enter:
http://www.cyberciti.biz/tips/top-linux-monitoring-tools.html/iptraf27/24/2019 Linux Some Commands
62/79
# tcpdump -i eth1 'dst 202.54.1.5 and (port 21 or
20'
To display all HTTP session to 192.168.1.5:
# tcpdump -ni eth0 'dst 192.168.1.5 and tcp and
port http'
Usewireshark to view detailedinformation about files,enter:
# tcpdump -n -i eth1 -s 0 -w output.txt src or
dst port 80
#15: strace - System Calls
Trace system calls and signals. This is useful fordebugging webserver and other server problems. See
how to use totrace the process andsee What it isdoing.
#16: /Proc file system - Various KernelStatistics
/proc file system provides detailed information aboutvarious hardware devices and other Linux kernel
information. SeeLinux kernel /procdocumentations forfurther details. Common /proc examples:
# cat /proc/cpuinfo
# cat /proc/meminfo
# cat /proc/zoneinfo
# cat /proc/mounts
http://www.cyberciti.biz/faq/linux-unix-bsd-apache-tcpdump-http-packets-sniffing/http://www.cyberciti.biz/faq/linux-unix-bsd-apache-tcpdump-http-packets-sniffing/http://www.cyberciti.biz/tips/linux-strace-command-examples.htmlhttp://www.cyberciti.biz/tips/linux-strace-command-examples.htmlhttp://www.cyberciti.biz/tips/linux-strace-command-examples.htmlhttp://www.cyberciti.biz/files/linux-kernel/Documentation/filesystems/proc.txthttp://www.cyberciti.biz/files/linux-kernel/Documentation/filesystems/proc.txthttp://www.cyberciti.biz/files/linux-kernel/Documentation/filesystems/proc.txthttp://www.cyberciti.biz/tips/linux-strace-command-examples.htmlhttp://www.cyberciti.biz/faq/linux-unix-bsd-apache-tcpdump-http-packets-sniffing/7/24/2019 Linux Some Commands
63/79
17#: Nagios - Server And NetworkMonitoring
Nagiosis a popular open source computer system andnetwork monitoring application software. You caneasily monitor all your hosts, network equipment andservices. It can send alert when things go wrong andagain when they get better.FAN is"Fully AutomatedNagios". FAN goals are to provide a Nagios installationincluding most tools provided by the NagiosCommunity. FAN provides a CDRom image in the
standard ISO format, making it easy to easilly install aNagios server. Added to this, a wide bunch of tools areincluding to the distribution, in order to improve theuser experience around Nagios.
18#: Cacti - Web-based Monitoring Tool
Cacti is a complete network graphing solution
designed to harness the power of RRDTool's datastorage and graphing functionality. Cacti provides afast poller, advanced graph templating, multiple dataacquisition methods, and user management featuresout of the box. All of this is wrapped in an intuitive,easy to use interface that makes sense for LAN-sizedinstallations up to complex networks with hundreds of
devices. It can provide data about network, CPU,memory, logged in users, Apache, DNS servers andmuch more. See how to install and configure Cactinetwork graphingtool under CentOS / RHEL.
#19: KDE System Guard - Real-timeSystems Reporting and Graphing
http://www.nagios.org/http://www.nagios.org/http://fannagioscd.sourceforge.net/drupal/http://fannagioscd.sourceforge.net/drupal/http://fannagioscd.sourceforge.net/drupal/http://www.cyberciti.biz/faq/fedora-rhel-install-cacti-monitoring-rrd-software/http://www.cyberciti.biz/faq/fedora-rhel-install-cacti-monitoring-rrd-software/http://www.cyberciti.biz/faq/fedora-rhel-install-cacti-monitoring-rrd-software/http://www.cyberciti.biz/faq/fedora-rhel-install-cacti-monitoring-rrd-software/http://www.cyberciti.biz/faq/fedora-rhel-install-cacti-monitoring-rrd-software/http://fannagioscd.sourceforge.net/drupal/http://www.nagios.org/7/24/2019 Linux Some Commands
64/79
KSysguard is a network enabled task and systemmonitor application for KDE desktop. This tool can berun over ssh session. It provides lots of features such
as a client/server architecture that enables monitoringof local and remote hosts. The graphical front end usesso-called sensors to retrieve the information it displays.
A sensor can return simple values or more complexinformation like tables. For each type of information,one or more displays are provided. Displays areorganized in worksheets that can be saved and loadedindependently from each other. So, KSysguard is not
only a simple task manager but also a very powerfultool to control large server farms.
Fig.05 KDE System Guard {Image credit: Wikipedia}
Seethe KSysguard handbookfor detailed usage.
http://docs.kde.org/stable/en/kdebase-workspace/ksysguard/index.htmlhttp://docs.kde.org/stable/en/kdebase-workspace/ksysguard/index.htmlhttp://docs.kde.org/stable/en/kdebase-workspace/ksysguard/index.htmlhttp://www.cyberciti.biz/tips/top-linux-monitoring-tools.html/kde-systemguard-screenshothttp://docs.kde.org/stable/en/kdebase-workspace/ksysguard/index.html7/24/2019 Linux Some Commands
65/79
#20: Gnome System Monitor - Real-time Systems Reporting and Graphing
The System Monitor application enables you to displaybasic system information and monitor systemprocesses, usage of system resources, and filesystems. You can also use System Monitor to modifythe behavior of your system. Although not as powerfulas the KDE System Guard, it provides the basicinformation which may be useful for new users:
Displays various basic information about thecomputer's hardware and software.
Linux Kernel version GNOME version Hardware Installed memory Processors and speeds System Status Currently available disk space Processes Memory and swap space Network usage File Systems Lists all mounted filesystems along with basic
information about each.
7/24/2019 Linux Some Commands
66/79
Fig.06 The Gnome System Monitor application
Bonus: Additional Tools
A few more tools:
nmap- scan your server for open ports. lsof- list open files, network connections and much
more. ntopweb based tool - ntop is the best tool to see
network usage in a way similar to what topcommand does for processes i.e. it is network trafficmonitoring software. You can see network status,protocol wise distribution of traffic for UDP, TCP,DNS, HTTP and other protocols.
Conky- Another good monitoring tool for the XWindow System. It is highly configurable and is able
to monitor many system variables including the
http://www.cyberciti.biz/tips/linux-scanning-network-for-open-ports.htmlhttp://www.cyberciti.biz/tips/linux-scanning-network-for-open-ports.htmlhttp://www.cyberciti.biz/tips/tag/lsof-commandhttp://www.cyberciti.biz/tips/tag/lsof-commandhttp://www.cyberciti.biz/faq/debian-ubuntu-install-ntop-network-traffic-monitoring-software/http://www.cyberciti.biz/faq/debian-ubuntu-install-ntop-network-traffic-monitoring-software/http://conky.sourceforge.net/http://conky.sourceforge.net/http://www.cyberciti.biz/tips/top-linux-monitoring-tools.html/gnome-system-monitorhttp://conky.sourceforge.net/http://www.cyberciti.biz/faq/debian-ubuntu-install-ntop-network-traffic-monitoring-software/http://www.cyberciti.biz/tips/tag/lsof-commandhttp://www.cyberciti.biz/tips/linux-scanning-network-for-open-ports.html7/24/2019 Linux Some Commands
67/79
status of the CPU, memory, swap space, diskstorage, temperatures, processes, networkinterfaces, battery power, system messages, e-mail
inboxes etc. GKrellM- It can be used to monitor the status of
CPUs, main memory, hard disks, network interfaces,local and remote mailboxes, and many other things.
vnstat- vnStat is a console-based network trafficmonitor. It keeps a log of hourly, daily and monthlynetwork traffic for the selected interface(s).
htop- htop is an enhanced version of top, the
interactive process viewer, which can display the listof processes in a tree form.
mtr- mtr combines the functionality of the tracerouteand ping programs in a single network diagnostictool.
Did I miss something? Please add your favorite systemmotoring tool in the comments.
How do I Find Out Linux CPU Utilization?byNIX CRAFT on APRIL 6, 2006 148 COMMENTSLAST UPDATED DECEMBER 18, 2008
inLINUX,SYS ADMIN, TIPS
Whenever a Linux system CPU is occupied by aprocess, it is unavailable for processing other requests.Rest of pending requests must wait till CPU is free.This becomes a bottleneck in the system. Following
command will help you to identify CPU utilization, so
http://members.dslextreme.com/users/billw/gkrellm/gkrellm.htmlhttp://members.dslextreme.com/users/billw/gkrellm/gkrellm.htmlhttp://www.cyberciti.biz/tips/keeping-a-log-of-daily-network-traffic-for-adsl-or-dedicated-remote-linux-box.htmlhttp://www.cyberciti.biz/tips/keeping-a-log-of-daily-network-traffic-for-adsl-or-dedicated-remote-linux-box.htmlhttp://htop.sourceforge.net/http://htop.sourceforge.net/http://www.cyberciti.biz/tips/finding-out-a-bad-or-simply-overloaded-network-link-with-linuxunix-oses.htmlhttp://www.cyberciti.biz/tips/finding-out-a-bad-or-simply-overloaded-network-link-with-linuxunix-oses.htmlhttp://www.cyberciti.biz/tips/about-ushttp://www.cyberciti.biz/tips/about-ushttp://www.cyberciti.biz/tips/about-ushttp://www.cyberciti.biz/tips/how-do-i-find-out-linux-cpu-utilization.html#commentshttp://www.cyberciti.biz/tips/how-do-i-find-out-linux-cpu-utilization.html#commentshttp://www.cyberciti.biz/tips/how-do-i-find-out-linux-cpu-utilization.html#commentshttp://www.cyberciti.biz/tips/category/linuxhttp://www.cyberciti.biz/tips/category/linuxhttp://www.cyberciti.biz/tips/category/sys-adminhttp://www.cyberciti.biz/tips/category/tipshttp://www.cyberciti.biz/tips/category/tipshttp://www.cyberciti.biz/tips/category/linux/http://www.cyberciti.biz/tips/category/tipshttp://www.cyberciti.biz/tips/category/sys-adminhttp://www.cyberciti.biz/tips/category/linuxhttp://www.cyberciti.biz/tips/how-do-i-find-out-linux-cpu-utilization.html#commentshttp://www.cyberciti.biz/tips/about-ushttp://www.cyberciti.biz/tips/finding-out-a-bad-or-simply-overloaded-network-link-with-linuxunix-oses.htmlhttp://htop.sourceforge.net/http://www.cyberciti.biz/tips/keeping-a-log-of-daily-network-traffic-for-adsl-or-dedicated-remote-linux-box.htmlhttp://members.dslextreme.com/users/billw/gkrellm/gkrellm.html7/24/2019 Linux Some Commands
68/79
that you can troubleshoot CPU related performanceproblems.
Finding CPU utilization is one of the important tasks.Linux comes with various utilities to report CPUutilization. With these commands, you will be able tofind out:
* CPU utilization* Display the utilization of each CPU individually (SMPcpu)
* Find out your system's average CPU utilization sincethe last reboot etc* Determine which process is eating the CPU(s)
Old good top command to find out Linuxcpu load
The top program provides a dynamic real-time view ofa running system. It can display system summaryinformation as well as a list of tasks currently beingmanaged by the Linux kernel.The top command monitors CPU utilization, processstatistics, and memory utilization. The top sectioncontains information related to overall system status -uptime, load average, process counts, CPU status,
and utilization statistics for both memory and swapspace.Top command to find out Linux cpu usageType the top command:
$ top
7/24/2019 Linux Some Commands
69/79
Output:
You can see Linux CPU utilization under CPU stats.The tasks share of the elapsed CPU time since the
last screen update, expressed as a percentage of totalCPU time. In a true SMP environment (multipleCPUS), top will operate in number of CPUs. Pleasenote that you need to type q key to exit the topcommand display.
The top command produces a frequently-updated listof processes. By default, the processes are ordered by
percentage of CPU usage, with only the "top" CPUconsumers shown. The top command shows howmuch processing power and memory are being used,as well as other information about the runningprocesses.
Find Linux CPU utilization using mpstat
and other tools
http://www.cyberciti.biz/nixcraft/vivek/blogger/uploaded_images/linux-cpu-utilization-780043.png7/24/2019 Linux Some Commands
70/79
Please note that you need to install special packagecalled sysstatto take advantage of followingcommands. This package includes system
performance tools for Linux (Red Hat Linux / RHELincludes these tools by default).
# apt-get install sysstat
Use up2date command if you are using RHEL:
# up2date sysstat
Display the utilization of each CPUindividually using mpstat
If you are using SMP (Multiple CPU) system, usempstat command to display the utilization of each CPUindividually. It report processors related statistics. Forexample, type command:
# mpstat Output:
Linux 2.6.15.4 (debian) Thursday 06 April2006
05:13:05 IST CPU %user %nice %sys %iowait%irq %soft %steal %idle intr/s
05:13:05 IST all 16.52 0.00 2.87 1.090.07 0.02 0.00 79.42 830.06
The mpstat command display activities for eachavailable processor, processor 0 being the first one.Global average activities among all processors arealso reported. The mpstat command can be used bothon SMP and UP machines, but in the latter, only globalaverage activities will be printed.:
7/24/2019 Linux Some Commands
71/79
# mpstat -P ALL
Output:
Linux 2.6.15.4 (wwwportal1.xxxx.co.in)Thursday 06 April 2006
05:14:58 IST CPU %user %nice %sys %iowait%irq %soft %steal %idle intr/s
05:14:58 IST all 16.46 0.00 2.88 1.080.07 0.02 0.00 79.48 835.96
05:14:58 IST 0 16.46 0.00 2.88 1.080.07 0.02 0.00 79.48 835.96
05:14:58 IST 1 15.77 2.70 3.17 2.010.05 0.03 0.00 81.44 822.54
Another output from my HP Dual Opteron 64 bitserver: # mpstat -P ALL Output:
Linux 2.6.5-7.252-smp (ora9.xxx.in) 04/07/06
07:44:18 CPU %user %nice %system %iowait%irq %soft %idle intr/s
07:44:18 all 3.01 57.31 0.36 0.130.01 0.00 39.19 1063.46
07:44:18 0 5.87 69.47 0.44 0.050.01 0.01 24.16 262.11
07:44:18 1 1.79 48.59 0.36 0.23
0.00 0.00 49.02 268.92
7/24/2019 Linux Some Commands
72/79
07:44:18 2 2.19 42.63 0.28 0.160.01 0.00 54.73 260.96
07:44:18 3 2.17 68.56 0.34 0.060.03 0.00 28.83 271.47
Report CPU utilization using sar command
You can display todays CPU activity, with sarcommand:
# sar Output:
Linux 2.6.9-42.0.3.ELsmp (dellbox.xyz.co.in)01/13/2007
12:00:02 AM CPU %user %nice %system%iowait %idle
12:10:01 AM all 1.05 0.00 0.280.04 98.64
12:20:01 AM all 0.74 0.00 0.340.38 98.54
12:30:02 AM all 1.09 0.00 0.28
0.10 98.53
12:40:01 AM all 0.76 0.00 0.210.03 99.00
12:50:01 AM all 1.25 0.00 0.320.03 98.40
7/24/2019 Linux Some Commands
73/79
01:00:01 AM all 0.80 0.00 0.240.03 98.92
...
.....
..
04:40:01 AM all 8.39 0.00 33.170.06 58.38
04:50:01 AM all 8.68 0.00 37.510.04 53.78
05:00:01 AM all 7.10 0.00 30.480.04 62.39
05:10:01 AM all 8.78 0.00 37.740.03 53.44
05:20:02 AM all 8.30 0.00 35.450.06 56.18
Average: all 3.09 0.00 9.140.09 87.68
Comparison of CPU utilizationThe sar command writes to standard output thecontents of selected cumulative activity counters in theoperating system. The accounting system, based onthe values in the count and interval parameters. Forexample display comparison of CPU utilization; 2
seconds apart; 5 times, use:
7/24/2019 Linux Some Commands
74/79
# sar -u 2 5
Output (for each 2 seconds. 5 lines are displayed):
Linux 2.6.9-42.0.3.ELsmp (www1lab2.xyz.ac.in)01/13/2007
05:33:24 AM CPU %user %nice %system%iowait %idle
05:33:26 AM all 9.50 0.00 49.000.00 41.50
05:33:28 AM all 16.79 0.00 74.690.00 8.52
05:33:30 AM all 17.21 0.00 80.300.00 2.49
05:33:32 AM all 16.75 0.00 81.00
0.00 2.25
05:33:34 AM all 14.29 0.00 72.430.00 13.28
Average: all 14.91 0.00 71.490.00 13.61
Where,
-u 12 5: Report CPU utilization. The followingvalues are displayed: %user: Percentage of CPU utilization that
occurred while executing at the user level
(application).
7/24/2019 Linux Some Commands
75/79
%nice: Percentage of CPU utilization thatoccurred while executing at the user level withnice priority.
%system: Percentage of CPU utilization thatoccurred while executing at the system level(kernel).
%iowait: Percentage of time that the CPU orCPUs were idle during which the system had anoutstanding disk I/O request.
%idle: Percentage of time that the CPU or CPUswere idle and the system did not have an
outstanding disk I/O request.To get multiple samples and multiple reports set anoutput file for the sar command. Run the sar commandas a background process using.
# sar -o output.file 12 8 >/dev/null 2>&1 &
Better use nohup command so that you can logout andcheck back report later on:
# nohup sar -o output.file 12 8 >/dev/null 2>&1 &
All data is captured in binary form and saved to a file(data.file). The data can then be selectively displayedith the sar command using the -f option.
# sar -f data.file
Task: Find out who is monopolizing oreating the CPUs
Finally, you need to determine which process ismonopolizing or eating the CPUs. Following commandwill displays the top 10 CPU users on the Linuxsystem.
# ps -eo pcpu,pid,user,args | sort -k 1 -r | head
7/24/2019 Linux Some Commands
76/79
-10
OR
# ps -eo pcpu,pid,user,args | sort -r -k1 | less Output:
%CPU PID USER COMMAND
96 2148 vivek /usr/lib/vmware/bin/vmware-vmx -C /var/lib/vmware/Virtual Machines/Ubuntu 64-bit/Ubuntu 64-bit.vmx -@ ""
0.7 3358 mysql /usr/libexec/mysqld --defaults-file=/etc/my.cnf --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --skip-locking --socket=/var/lib/mysql/mysql.sock
0.4 29129 lighttpd /usr/bin/php
0.4 29128 lighttpd /usr/bin/php
0.4 29127 lighttpd /usr/bin/php
0.4 29126 lighttpd /usr/bin/php
0.2 2177 vivek [vmware-rtc]
0.0 9 root [kacpid]
0.0 8 root [khelper]
Now you know vmware-vmx process is eating up lots
of CPU power. ps command displays every process (-e) with a user-defined format (-o pcpu). First field is
7/24/2019 Linux Some Commands
77/79
pcpu (cpu utilization). It is sorted in reverse order todisplay top 10 CPU eating process.
iostat commandYou can also use iostat command which report CentralProcessing Unit (CPU) statistics and input/outputstatistics for devices and partitions. It can be use tofind out your system's average CPU utilization sincethe last reboot.
# iostat Output:
Linux 2.6.15.4 (debian) Thursday 06 April2006
avg-cpu: %user %nice %system %iowait %steal%idle
16.36 0.00 2.99 1.06 0.00 79.59
Device: tps Blk_read/s Blk_wrtn/sBlk_read Blk_wrtn
hda 0.00 0.00 0.0016 0
hdb 6.43 85.57 166.74875340 1705664
hdc 0.03 0.16 0.001644 0
sda 0.00 0.00 0.0024 0
7/24/2019 Linux Some Commands
78/79
You may want to use following command, which givesyou three outputs every 5 seconds (as previous
command gives information since the last reboot): $
iostat -xtc 5 3
GUI tools for your laptops/desktops
Above tools/commands are quite useful on remoteserver. For local system with X GUI installed you cantry out gnome-system-monitor. It allows you to view
and control the processes running on your system.You can access detailed memory maps, send signals,and terminate the processes.
$ gnome-system-monitor
(Click to enlarge image)
http://www.cyberciti.biz/tips/wp-content/uploads/2007/01/linux-gui-info-2.jpg7/24/2019 Linux Some Commands
79/79
In addition, the gnome-system-monitor provides anoverall view of the resource usage on your system,including memory and CPU allocation.
Printenv | less
Printenv | more
Printenv
Set | more
Set
http://www.cyberciti.biz/tips/wp-content/uploads/2007/01/linux-gui-info.jpg