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-today task. Linux commands and their switches remains the most valuable treasure for
a Linux-user, Shell-script programmer and Administrator. There are some Linux
Commands which 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 !! command
Running the command without specifying sudo command will 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)
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 command
The below command generates a simple web page over HTTP for the directory structure
tree and can be accessed at port 8000 in browser till interrupt signal is sent.
# python -m SimpleHTTPServer
Directory Structure Tree
3. mtr Command
Most of us are familiar with ping and traceroute. How about combining the functionality of
both the command into one with mtr command. In case mtr is not installed into your
machine, apt or yum the required package.
$ sudo apt-get install mtr (On Debian based Systems)
# yum install mtr (On Red Hat based Systems)
Now run mtr command to start investigating the network connection between the host mtr
runs on and google.com.
# mtr google.com
mtr command
4. Ctrl+x+e Command
This command is very much useful for administrator and developers. To Automate day-today task an administrator needs to open editor by typing vi, vim, nano, etc. How about
firing instant editor (from terminal).
Just Press Ctrl-x-e from the terminal prompt and start working in editor.
Download Linux Command Line Cheat Sheet
5. nl Command
The nl command number the lines of a file. Number the lines of a file say one.txt with
lines say (Fedora, Debian, Arch, Slack and Suse). First list the content of a file one.txt
using cat 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 Command
The shuf command randomly select lines/files/folder from a file/folder. First list the
contents of a folder using ls command.
# ls
Desktop Documents Downloads
Public Templates Videos
#
ls | shuf (shuffle Input)
Music
Pictures
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
The ss stands for socket statistics. The command investigates the socket and shows
information similar to netstat command. It can display more TCP and state informations
than other tools.
# ss
State
Recv-Q Send-Q
Peer Address:Port
Local Address:Port
ESTAB
0
*.*.*.*:http
192.168.1.198:41250
CLOSE-WAIT 1
127.0.0.1:41393
ESTAB
0
*.*.*.*:http
ESTAB
310
127.0.0.1:41384
ESTAB
0
*.*.*.*:http
192.168.1.198:41002
ESTAB
0
127.0.0.1:8000
127.0.0.1:41384
127.0.0.1:8000
192.168.1.198:36239
127.0.0.1:8000
8. last Command
The last command show the history of last logged in users. This command searches
through the file /var/log/wtmp and shows a list of logged-in and logged-out users along
withttys.
last
server
12:03
pts/0
:0
still logged in
Tue Oct 22
server
12:02
tty8
:0
still logged in
Tue Oct 22
...
(unknown tty8
12:02 - 12:02
:0
Tue Oct 22
server
pts/0
:0
10:33 - 12:02 (01:29)
Tue Oct 22
server
tty7
10:05 - 12:02
:0
Tue Oct 22
(01:56)
(unknown tty7
10:04 - 10:05
:0
Tue Oct 22
(00:00)
(00:00)
reboot
system boot 3.2.0-4-686-pae
10:04 - 12:44 (02:39)
wtmp begins Fri Oct
Tue Oct 22
4 14:43:17 2007
9. curl ifconfig.me
So 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 to apt/yum to install package.
10. tree command
Get the current directory structure in tree like format.
# tree
.
|-- Desktop
|-- Documents
|
`-- 37.odt
|-- Downloads
|
|-- attachments.zip
|-- 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. pstree
This 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
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
session-managevolution-a+
gdm-session-worx-
gdu-notific+
gnome-scree+
gnome-setti+
gnome-shell+++
nm-applet+++
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. <space> Command
Every piece of command you type in terminal gets recorded in the history and can be
retried using history command.
How about cheating history 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
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/cdrom1
of=/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 Command
The 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-time of file last
access,Modify, change, etc.
avi@localhost:~$ stat 34.odt
File: `34.odt'
Size: 28822
4096
regular file
Blocks: 64
IO Block:
Device: 801h/2049d
Inode: 5030293
Links: 1
Access: (0644/-rw-r--r--)
Gid: ( 1000/
avi)
Uid: ( 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. <alt>. and <esc>.
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 command
You might have seen simulating text in Movies specially 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. The pv command
might not be installed in your system, and you have to apt or yum the required packages
to install pv into your box.
root@localhost:# echo "Tecmint [dot] com is the
world's best website for qualitative Linux article" |
pv -qL 20
Sample Outpit
Tecmint [dot] com is the world's best website for
qualitative Linux article
16. mount | column -t
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 /
(rw,errors=remount-ro)
type
tmpfs
tmpfs
type
on /lib/init/rw
(rw,nosuid,mode=0755)
proc
on /proc
(rw,noexec,nosuid,nodev)
type
sysfs
sysfs
on /sys
(rw,noexec,nosuid,nodev)
type
udev
tmpfs
on /dev
(rw,mode=0755)
type
tmpfs
tmpfs
on /dev/shm
(rw,nosuid,nodev)
type
devpts
devpts
on /dev/pts
type
(rw,noexec,nosuid,gid=5,mode=620)
fusectl
fusectl
on /sys/fs/fuse/connections
(rw)
type
binfmt_misc
binfmt_misc
on /proc/sys/fs/binfmt_misc
(rw,noexec,nosuid,nodev)
type
nfsd
(rw)
on
type
/proc/fs/nfsd
ext3
proc
nfsd
17. Ctr+l command
Before 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 command
How about checking your unread mail from 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.
avi@localhost:~$ curl -u avishek1210@gmail.com -silent "https://mail.google.com/mail/feed/atom" |
perl -ne 'print "\t" if //; print "$2\n" if
/<(title|name)>(.*)<\/\1>/;'
Sample Outpit
Enter host password for user 'avishek1210@gmail.com':
Gmail - Inbox for avishek1210@gmail.com
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
Choosing Debian version or derivative to run Wine
when resource poor
Chris Bannister
Zenaan Harkness
Curt
Tom H
Richard Owlett
Ralf Mardorf
Rob Owens
19. screen Command
The screen command 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-attached or re-attached in different sessions. When a command is executing
press Ctrl + A and then d to de-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 useful 10 screen commands with examples.
20. file
No! 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
34.odt: OpenDocument Text
21. id
The above command print real and effective user and group ids.
avi@localhost:~$ id
Sample Output
uid=1000(avi) gid=1000(avi)
groups=1000(avi),24(cdrom),25(floppy),29(audio),30(di
p),44(video),46(plugdev),109(netdev),111(bluetooth),1
17(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 Tuned and connected to Tecmint. Dont Forget
to provide us with your value-able Feedback in Comments.
22. ^foo^bar Command
Run the last command with modification, in a single instance. Suppose I need to run a
command 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
drwxr-xr-x 2 avi
101MSDCF
avi
36864 Nov 13
2012
-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
Untitled 1.doc
avi
90624 Nov
5 12:59
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 the
same 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.txt on 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
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 Command
The at command is similar to cron command and 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
Screenshot-1.png
avi
220492 Nov
-rw-r--r-- 1 root root
sources.list
-rw-r--r-- 1 avi
squeeze.iso
avi
1 13:49
358 Oct 17 10:11
4695982080 Oct 10 20:29
..
..
-rw-r--r-- 1 avi
Untitled 1.doc
avi
90624 Nov
5 12:59
-rw-r--r-- 1 avi
Untitled 1.odt
avi
96206 Nov
5 12:56
-rw-r--r-- 1 avi
Untitled.png
avi
9405 Nov 12 23:22
Note: echo ls -l : This string echos the command (here ls -l) on standard terminal. You
can replace ls -l with any command of your need and choice.
> : redirects the output
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 -h max-depth=1 Command
The below command outputs the size of sub-folders within the current directory, in human
readable 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 in checking system disk usage.
Download Linux Command Line Cheat Sheet
26. expr Command
The 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 Command
Check 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
...
carps
carpus
carpus's
carrel
carrel's
carrels
carriage
carriage's
carriages
carriageway
carriageway's
carried
carrier
carrier's
carriers
carries
...
caryatids
The above command showed all the words from dictionary starting with string car. I got
what I was searching for.
28. yes Command
Another 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 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
Tecmint is one of the best site dedicated to Linux,
how to
29. factor Command
The 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
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 of
data.
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=44
time=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 Command
This 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
using cat command.
avi@localhost:~/Documents$ cat 35.txt
Sample Output
1. Linux is built with certain powerful tools, which
are unavailable in windows.
2. One of such important tool is Shell Scripting.
Windows however comes with such a tool but as usual
it is much weak as compared to it's Linux
Counterpart.
3.Shell scripting/programming makes it possible to
execute command(s), piped to get desired output in
order 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 to
execute command(s), piped to get desired output in
order to automate day-to-day usages.
2. One of such important tool is Shell Scripting.
Windows however comes with such a tool but as usual
it is much weak as compared to it's Linux
Counterpart.
1. Linux is built with certain powerful tools, which
are 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_release
The command lsb_release print distribution-specific information. If lsb_release is not
installed, you can apt lsb-core on Debian or yum redhat-lsb on Red Hat the package.
# lsb_release -a
LSB Version:
:base-4.0-ia32:base-4.0-noarch:core4.0-ia32:core-4.0-noarch:graphics-4.0-ia32:
Distributor ID: CentOS
Description:
CentOS release 6.3 (Final)
Release:
6.3
Codename:
Final
Note:
Option
-a,
shows
all
the
available
of version, id, description,release and codename.
information
in
respect
43. nc -zv localhost 80
Check if port 80 is 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 8080 is open or not.
$ nc -zv localhost 8080
nc: connect to localhost port 8080 (tcp) failed:
Connection refused
44. curl ipinfo.io
The below command will output the Geographical Location of the IP 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."
45. find . -user root
The 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
./.cache/chromium/Cache/f_001b52
./.cache/chromium/Cache/f_00198d
./.cache/chromium/Cache/f_003680
46. sudo apt-get build-dep ffmpeg
The 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 libxmlsax-expat-perl
libxml-sax-perl libxml-simple-perl libxrandr-dev
libxrender-dev
x11proto-render-dev x11proto-xinerama-dev xulrunnerdev
The following packages will be upgraded:
libpixman-1-0
1 upgraded, 143 newly installed, 0 to remove and 6
not 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:LISTEN
The below command outputs, name of process/service using 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
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 +100M
The 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-dvd32bit.iso
./Downloads/Fedora-Live-Desktop-i686-19-1.iso
./Downloads/Ant Videos/shakira 2.avi
./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/The
Dark Knight.mkv.part
./Downloads/Saudagar - (1991) - DVDRiP - x264 - AAC
5.1 - Chapters - Esubs - [DDR]/Saudagar
- (1991) - DVDRiP - x264 - AAC 5.1 - Chapters - Esubs
- [DDR].mkv
./Downloads/Deewar.avi
./Desktop/squeeze.iso
49. pdftk
The pdftk command merges several pdf files into one. You
installed pdftkprogram. If not, do apt or yum to get the required package.
must
have
$ pdftk 1.pdf 2.pdf 3.pdf . 10.pdf cat output
merged.pdf
50. ps -LF -u user_name
The below command outputs processes and threads of a user. The option L (list threads)
and -F (Full Format Listing).
$ ps -LF -u avi
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/1
00: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:22
gnome
avi 23652 1 23655 0 2 22092 12520 0 19:06 ? 00:00:00
gnome
51. Startx :1
Sharing X session, means frequently logging in and out, this is where the Startx command
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 X session, 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. Hence 6 console session and 6 X session, without frequent
logging-in and out. The above sequence works on most of the distro, however different
distro 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 Lesser Known Linux Commands. I am coming with my next
article very soon, till then, stay healthy, tuned and connected to Tecmint.
32. strace Command
The strace is 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 apt or yum the
required package.
Trace a command execution using strace command:
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)
(No such file or directory)
= -1 ENOENT
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\3
55\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
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 strace command accepts a lot of arguments and have many options. Refer to man
page for detailed information.
33. disown -a && exit Command
Most 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 detach from
the terminal, you use screen command 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 after
you 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 the jobs command to find the job
number and then use disown %n where n is the job number. To verify actually the job is
running use ps or top command. The nohup command is an alternative to the disown
command.
34. getconf LONG_BIT Command
The above command shows your machine architecture if it is 32 bit or 64 bit?
root@tecmint [~]# getconf LONG_BIT
32
Download Linux Command Line Cheat Sheet
35. Display Date on the Terminal
The 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 date and time on 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 Command
While 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/x11 directory) in image format. What I did at terminal was:
root@tecmint:/etc/X11# tree | convert label:@/home/avi/tree.png
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|figlet
Remember 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 figlet
to show animated digital clock in the terminal.
Just check-out yourself, remember you must have figlet installed on the system,
do apt oryum to 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 Commands
Although host and dig command is not that much lesser known, still not very frequently
used. The host command is DNS lookup 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
www.google.com has IPv6 address
2a00: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:
;; ->>HEADER<
39. dstat Command
The dstat is a versatile tool, that generates statistics relating to system resource. By default
your system might not have dstat installed. Do a apt or yum to install dstat before using
this very colorful and description system resource generator.
root@tecmint [~]# dstat
dstat command
40. bind -p Command
The bind -p command will show all the shortcuts available for BASH shell.
root@tecmint [~]# bind -p
Sample Output
"\C-g": abort
"\C-x\C-g": abort
"\e\C-g": abort
"\C-j": accept-line
"\C-m": accept-line
# alias-expand-line (not bound)
# arrow-key-prefix (not bound)
# backward-byte (not bound)
"\C-b": backward-char
"\eOD": backward-char
"\e[D": backward-char
"\e!": complete-command
"\e/": complete-filename
"\e@": complete-hostname
"\e{": complete-into-braces
"\e~": complete-username
"\e$": complete-variable
# copy-backward-word (not bound)
# copy-forward-word (not bound)
# copy-region-as-kill (not bound)
....
....
41. touch /forcefsck
The above command will create an empty folder 'forcefsck', under root directory. This will
force Linux System to check the file system on the very next boot.
root@tecmint [~]# touch /forcefsck
Thats all for Now. You People are loving these Lesser Known Commands and hence
we are continuing the series, the next article of this series will be available very soon.
Till then stay tuned and connected to Tecmint. Dont forget to give your valuable feedback
in our comment section. Do a favor to us, Like and share us and help us spread.
File Transfer Protocol (FTP) was widely used protocol to transfer files or data remotely
in unencrypted format which is not secure way to communicate. As we all know that File
Transfer Protocol is not at all secure because all transmissions happens in clear text and
the data can be readable by anyone during sniffing the packets on the network.
10 sftp command examples
So, basically FTP can be used in limited cases or on the networks that you trust. Over the
period of time SCP and SSH addresses this security ambiguity and added an encrypted
secure layer while transferring data between remote computers.
SFTP (Secure File Transfer Protocol) runs over SSH protocol on standard port 22 by
default to establish a secure connection. SFTP has been integrated into many GUI tools
(FileZilla, WinSCP, FireFTP etc.).
Security Warnings: Please dont open SSH port (Secure SHell) globally as this would be
a security breaches. You can only open for specific IP from where you are going to transfer
or manage files on remote system or vice versa.
o 5 Best Practices to Secure and Protect SSH Server
o 10 Wget Command Examples in Linux
This article will guide you 10 sftp command examples to use it through interactive command-line
interface.
1. How to Connect to SFTP
By default, same SSH protocol is used to authenticate and establish a SFTP connection. To start an
SFTP session, enter the username and remote hostname or IP address at the command prompt. Once
authentication successful, you will see a shell with an sftp> prompt.
[root@tecmint ~]# sftp tecmint@27.48.137.6
Connecting to 27.48.137.6...
tecmint@27.48.137.6's password:
sftp>
2. Getting Help
Once, you in the sftp prompt, check the available commands by typing ? or help at command
prompt.
sftp> ?
Available commands:
cd path
to 'path'
Change remote directory
lcd path
to 'path'
Change local directory
chgrp grp path
'path' to 'grp'
Change group of file
chmod mode path
file 'path' to 'mode'
Change permissions of
chown own path
'path' to 'own'
Change owner of file
help
Display this help text
get remote-path [local-path]
Download file
lls [ls-options [path]]
listing
Display local directory
ln oldpath newpath
Symlink remote file
lmkdir path
Create local directory
lpwd
directory
Print local working
ls [path]
directory listing
Display remote
lumask umask
'umask'
Set local umask to
mkdir path
Create remote directory
put local-path [remote-path]
Upload file
pwd
directory
Display remote working
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
local shell
Execute 'command' in
Escape to local shell
Synonym for help
3. Check Present Working Directory
The command lpwd is used to check the Local present working directory, whereas pwd
command is used to check Remote working directory.
sftp> lpwd
Local working directory: /
sftp> pwd
Remote working directory: /tecmint/
o
o
lpwd print the current directory on your system
pwd print the current directory on the ftp server
4. Listing Files
Listing files and directories in local as well as remote system.
On Remote
sftp> ls
On Local
sftp> lls
5. Upload File
Put single or multiple files in remote system.
sftp> put local.profile
Uploading local.profile to /tecmint/local.profile
6. Upload Mutiple Files
Putting multiple files on in remote system.
sftp> mput *.xls
6. Download Files
Getting single or multiple files in local system.
sftp> get SettlementReport_1-10th.xls
Fetching /tecmint/SettlementReport_1-10th.xls to
SettlementReport_1-10th.xls
Get multiple files on a local system.
sftp> mget *.xls
Note: As we can see by default with get command download 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 Directories
Switching from one directory to another directory in local and remote locations.
On Remote
sftp> cd test
sftp>
On Local
sftp> lcd Documents
8. Create Directories
Creating new directories on local and remote locations.
sftp> mkdir test
sftp> lmkdir Documents
9. Remove Directories
Remove 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 Shell
The ! 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>
Conclusion
The SFTP is a very useful tool for administrating servers and transferring files to and from
(Local and Remote). We hope this tuts will help you to understand the usage of SFTP in some
extent.
20 Linux System Monitoring Tools Every
SysAdmin Should Know
by NI X CRAF T on JUNE 27, 2009 342 COM M ENTS LAST UPDATED J ANUARY 1, 2014
in CENTOS, DEBI AN LI NUX, FEDORA LI NUX
eed to monitor Linux server performance? Try
these built-in commands and a few add-on tools. Most
Linux distributions are equipped with tons of
monitoring. These tools provide metrics which can be
used to get information about system activities. You
can use these tools to find the possible causes of a
performance problem. The commands discussed
below are some of the most basic commands when it
comes to system analysis and debugging server
issues 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 of
a running system i.e. actual process activity. By
default, it displays the most CPU-intensive tasks
running on the server and updates the list every five
seconds.
Fig.01: Linux top command
Commonly Used Hot Keys
The top command provides several useful hot keys:
Hot
Key
t
m
A
f
o
r
k
z
Usage
Displays summary information off and on.
Displays memory information off and on.
Sorts the display by top consumers of various system resources. Useful for
quick identification of performance-hungry tasks on a system.
Enters an interactive configuration screen for top. Helpful for setting up top
for a specific task.
Enables you to interactively select the ordering within top.
Issues renice command.
Issues kill command.
Turn on or off color/mono
=> Related: How do I Find Out Linux CPU Utilization?
#2: vmstat - System Activity, Hardware
and System Information
The command vmstat reports information about
processes, memory, paging, block IO, traps, and cpu
activity.
# vmstat 3
Sample Outputs:
procs -----------memory---------- ---swap-- -----io--- --system-- -----cpu-----r
bo
0
32
swpd
free
buff cache
in
cs us sy id wa st
si
so
bi
0 2540988 522188 5130400
2 4 1 96 0 0
0 2540988 522188 5130400
665 1 0 99 0 0
0 0
0 2540956 522188 5130400
0 1151 1569 4 1 95 0 0
0 0
6 1117
0 2540940 522188 5130512
932 1 0 98 0 0
0 0
0 2538444 522188 5130588
0 1187 1417 4 1 96 0 0
0 0
0 2490060 522188 5130640
18 1253 1123 5 1 94 0 0
1 0
720 1199
0 2540956 522188 5130500
439 1 0 99 0 0
0 0
536 1189
Display Memory Utilization Slabinfo
# vmstat -m
Get Information About Active / Inactive
Memory Pages
# vmstat -a
=> Related: How do I find out Linux Resource
utilization to detect system bottlenecks?
#3: w - Find Out Who Is Logged on And
What They Are Doing
w command displays information about the users
currently on the machine, and their processes.
# w username
# w vivek
Sample Outputs:
17:58:47 up 5 days, 20:28,
0.36, 0.26, 0.24
2 users,
FROM
load average:
USER
JCPU
TTY
PCPU WHAT
root
0.04s
pts/0
10.1.3.145
0.02s vim /etc/resolv.conf
14:55
5.00s
root
0.03s
pts/1
0.00s w
17:43
0.00s
10.1.3.145
LOGIN@
IDLE
#4: uptime - Tell How Long The System
Has Been Running
The uptime command can be used to see how long the
server has been running. The current time, how long
the system has been running, how many users are
currently logged on, and the system load averages for
the past 1, 5, and 15 minutes.
# uptime
Output:
18:02:41 up 41 days, 23:42,
0.00, 0.00, 0.00
1 user,
load average:
1 can be considered as optimal load value. The load
can change from system to system. For a single CPU
system 1 - 3 and SMP systems 6-10 load value might
be acceptable.
#5: ps - Displays The Processes
ps command will report a snapshot of the current
processes. 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
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
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 line
arguments 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
# 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 User
Vivek
# 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
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 Consuming
Process
# 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 free
and used physical and swap memory in the system, as
well as the buffers used by the kernel.
# free
Sample Output:
buffers
total
cached
used
free
shared
Mem:
523124
12302896
5154740
9739664
2563232
-/+ buffers/cache:
4061800
8241096
1052248
Swap:
1052248
=> Related: :
1. Linux Find Out Virtual Memory PAGESIZE
2. Linux Limit CPU Usage Per Process
3. How much RAM does my Ubuntu / Fedora Linux
desktop PC have?
#7: iostat - Average CPU Load, Disk
Activity
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:
%idle
%user
3.50
%nice %system %iowait
0.09
0.51
0.03
%steal
0.00
95.86
Device:
Blk_read
tps
Blk_wrtn
Blk_read/s
Blk_wrtn/s
sda
16193351
22.04
260102868
31.88
512.03
0.00
0.00
0.00
22.04
260102688
31.87
512.03
0.00
0.00
0.00
sda1
2166
sda2
16189010
180
sda3
1615
=> Related: : Linux Track NFS Directory / Disk I/O
Stats
#8: sar - Collect and Report System
Activity
The sar command is used to collect, report, and save
system 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
%iowait
%steal
%idle
%nice
%system
06:45:16 PM
0.00
0.00
all
97.78
2.00
0.00
0.22
06:45:20 PM
0.03
0.00
all
97.52
2.07
0.00
0.38
06:45:24 PM
0.00
0.00
all
98.78
0.94
0.00
0.28
06:45:28 PM
0.00
0.00
all
98.22
1.56
0.00
0.22
06:45:32 PM
0.03
0.00
all
96.19
3.53
0.00
0.25
Average:
0.01
all
97.70
2.02
0.00
0.27
0.00
=> Related: : How to collect Linux system utilization
data into a file
#9: mpstat - Multiprocessor Usage
The mpstat command displays activities for each
available 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
06:48:11 PM all
3.50
0.09
0.34
0.01
0.17
0.00
95.86
1218.04
0.03
06:48:11 PM
0.00
0.12
3.44
0.08
0.31
0.00
96.04
1000.31
0.02
06:48:11 PM
0.02
0.11
3.10
0.08
0.32
0.00
96.28
34.93
0.09
06:48:11 PM
0.00
0.11
4.16
0.11
0.00
95.25
0.36
0.00
0.02
06:48:11 PM
0.01
0.24
3
3.77
0.11
0.38
0.00
95.46
44.80
0.03
06:48:11 PM
0.02
0.10
2.96
0.07
0.29
0.00
96.52
25.91
0.04
06:48:11 PM
0.01
0.10
3.26
0.08
0.28
0.00
96.23
14.98
0.03
06:48:11 PM
0.00
0.13
4.00
0.10
0.00
95.42
0.34
3.75
0.01
06:48:11 PM
0.01
0.46
3.30
0.11
0.39
0.00
95.69
76.89
0.03
=> Related: : Linux display each multiple SMP CPU
processors utilization individually.
#10: pmap - Process Memory Usage
The command pmap report memory map of a process.
Use this command to find out causes of memory
bottlenecks.
# pmap -d PID
To display process memory information for pid #
47394, enter:
# pmap -d 47394
Sample Outputs:
47394:
Address
Device
/usr/bin/php-cgi
Kbytes Mode
Offset
Mapping
0000000000400000
008:00002 php-cgi
2584 r-x-- 0000000000000000
0000000000886000
008:00002 php-cgi
140 rw--- 0000000000286000
00000000008a9000
000:00000
[ anon ]
52 rw--- 00000000008a9000
0000000000aa8000
008:00002 php-cgi
76 rw--- 00000000002a8000
000000000f678000
1980 rw--- 000000000f678000
000:00000
[ anon ]
000000314a600000
008:00002 ld-2.5.so
112 r-x-- 0000000000000000
000000314a81b000
008:00002 ld-2.5.so
4 r---- 000000000001b000
000000314a81c000
008:00002 ld-2.5.so
4 rw--- 000000000001c000
000000314aa00000
1328 r-x-- 0000000000000000
008:00002 libc-2.5.so
000000314ab4c000
2048 ----- 000000000014c000
008:00002 libc-2.5.so
.....
......
..
00002af8d48fd000
008:00002 xsl.so
4 rw--- 0000000000006000
00002af8d490c000
40 r-x-- 0000000000000000
008:00002 libnss_files-2.5.so
00002af8d4916000
2044 ----- 000000000000a000
008:00002 libnss_files-2.5.so
00002af8d4b15000
4 r---- 0000000000009000
008:00002 libnss_files-2.5.so
00002af8d4b16000
4 rw--- 000000000000a000
008:00002 libnss_files-2.5.so
00002af8d4b17000 768000 rw-s- 0000000000000000
000:00009 zero (deleted)
00007fffc95fe000
84 rw--- 00007ffffffea000
000:00000
[ stack ]
ffffffffff600000
8192 ----- 0000000000000000
000:00000
[ anon ]
mapped: 933712K
shared: 768000K
writeable/private: 4304K
The last line is very important:
mapped: 933712K total amount of memory mapped
to files
writeable/private: 4304K the amount of private
address space
shared: 768000K the amount of address space this
process is sharing with others
=> Related: : Linux find the memory used by a
program / process using pmap command
#11 and #12: netstat and ss - Network
Statistics
The command netstat displays network connections,
routing tables, interface statistics, masquerade
connections, and multicast memberships. ss command
is used to dump socket statistics. It allows showing
information similar to netstat. See the following
resources 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 Network
Statistics
The iptraf command is interactive colorful IP LAN
monitor. It is an ncurses-based IP LAN monitor that
generates various network statistics including TCP
info, 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 read
format:
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
Fig.03 Network traffic statistics by TCP connection
#14: tcpdump - Detailed Network Traffic
Analysis
The tcpdump is simple command that dump traffic on a
network. However, you need good understanding of
TCP/IP protocol to utilize this tool. For.e.g to display
traffic 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, for
example, SYN and FIN packets and ACK-only packets,
enter:
# tcpdump 'tcp port 80 and (((ip[2:2] ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)'
To display all FTP session to 202.54.1.5, enter:
# 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'
Use wireshark to view detailed information 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 for
debugging webserver and other server problems. See
how to use to trace the process and see What it is
doing.
#16: /Proc file system - Various Kernel
Statistics
/proc file system provides detailed information about
various hardware devices and other Linux kernel
information. See Linux kernel /proc documentations for
further details. Common /proc examples:
# cat /proc/cpuinfo
# cat /proc/meminfo
# cat /proc/zoneinfo
# cat /proc/mounts
17#: Nagios - Server And Network
Monitoring
Nagios is a popular open source computer system and
network monitoring application software. You can
easily monitor all your hosts, network equipment and
services. It can send alert when things go wrong and
again when they get better. FAN is "Fully Automated
Nagios". FAN goals are to provide a Nagios installation
including most tools provided by the Nagios
Community. FAN provides a CDRom image in the
standard ISO format, making it easy to easilly install a
Nagios server. Added to this, a wide bunch of tools are
including to the distribution, in order to improve the
user experience around Nagios.
18#: Cacti - Web-based Monitoring Tool
Cacti is a complete network graphing solution
designed to harness the power of RRDTool's data
storage and graphing functionality. Cacti provides a
fast poller, advanced graph templating, multiple data
acquisition methods, and user management features
out of the box. All of this is wrapped in an intuitive,
easy to use interface that makes sense for LAN-sized
installations up to complex networks with hundreds of
devices. It can provide data about network, CPU,
memory, logged in users, Apache, DNS servers and
much more. See how to install and configure Cacti
network graphing tool under CentOS / RHEL.
#19: KDE System Guard - Real-time
Systems Reporting and Graphing
KSysguard is a network enabled task and system
monitor application for KDE desktop. This tool can be
run over ssh session. It provides lots of features such
as a client/server architecture that enables monitoring
of local and remote hosts. The graphical front end uses
so-called sensors to retrieve the information it displays.
A sensor can return simple values or more complex
information like tables. For each type of information,
one or more displays are provided. Displays are
organized in worksheets that can be saved and loaded
independently from each other. So, KSysguard is not
only a simple task manager but also a very powerful
tool to control large server farms.
Fig.05 KDE System Guard {Image credit: Wikipedia}
See the KSysguard handbook for detailed usage.
#20: Gnome System Monitor - Realtime Systems Reporting and Graphing
The System Monitor application enables you to display
basic system information and monitor system
processes, usage of system resources, and file
systems. You can also use System Monitor to modify
the behavior of your system. Although not as powerful
as the KDE System Guard, it provides the basic
information which may be useful for new users:
Displays various basic information about the
computer'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.
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.
ntop web based tool - ntop is the best tool to see
network usage in a way similar to what top
command does for processes i.e. it is network traffic
monitoring 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 X
Window System. It is highly configurable and is able
to monitor many system variables including the
status of the CPU, memory, swap space, disk
storage, temperatures, processes, network
interfaces, 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 traffic
monitor. It keeps a log of hourly, daily and monthly
network traffic for the selected interface(s).
htop - htop is an enhanced version of top, the
interactive process viewer, which can display the list
of processes in a tree form.
mtr - mtr combines the functionality of the traceroute
and ping programs in a single network diagnostic
tool.
Did I miss something? Please add your favorite system
motoring tool in the comments.
How do I Find Out Linux CPU Utilization?
by NI X CRAF T on APRIL 6, 2006 148 COMM ENTS LAST UPDATED DECEM BER 18, 2008
in LI NUX, SYS ADMI N, TI PS
Whenever a Linux system CPU is occupied by a
process, 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
that you can troubleshoot CPU related performance
problems.
Finding CPU utilization is one of the important tasks.
Linux comes with various utilities to report CPU
utilization. With these commands, you will be able to
find out:
* CPU utilization
* Display the utilization of each CPU individually (SMP
cpu)
* Find out your system's average CPU utilization since
the last reboot etc
* Determine which process is eating the CPU(s)
Old good top command to find out Linux
cpu load
The top program provides a dynamic real-time view of
a running system. It can display system summary
information as well as a list of tasks currently being
managed by the Linux kernel.
The top command monitors CPU utilization, process
statistics, and memory utilization. The top section
contains information related to overall system status uptime, load average, process counts, CPU status,
and utilization statistics for both memory and swap
space.
Top command to find out Linux cpu usage
Type the top command:
$ top
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 total
CPU time. In a true SMP environment (multiple
CPUS), top will operate in number of CPUs. Please
note that you need to type q key to exit the top
command display.
The top command produces a frequently-updated list
of processes. By default, the processes are ordered by
percentage of CPU usage, with only the "top" CPU
consumers shown. The top command shows how
much processing power and memory are being used,
as well as other information about the running
processes.
Find Linux CPU utilization using mpstat
and other tools
Please note that you need to install special package
called sysstat to take advantage of following
commands. This package includes system
performance tools for Linux (Red Hat Linux / RHEL
includes these tools by default).
# apt-get install sysstat
Use up2date command if you are using RHEL:
# up2date sysstat
Display the utilization of each CPU
individually using mpstat
If you are using SMP (Multiple CPU) system, use
mpstat command to display the utilization of each CPU
individually. It report processors related statistics. For
example, type command:
# mpstat Output:
Linux 2.6.15.4 (debian)
2006
Thursday 06 April
05:13:05 IST CPU
%user
%nice
%sys %iowait
%irq
%soft %steal
%idle
intr/s
05:13:05 IST
0.07
0.02
all
16.52
0.00
79.42
0.00
2.87
830.06
1.09
The mpstat command display activities for each
available processor, processor 0 being the first one.
Global average activities among all processors are
also reported. The mpstat command can be used both
on SMP and UP machines, but in the latter, only global
average activities will be printed.:
# 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
0.07
0.02
all
16.46
0.00
79.48
0.00
2.88
835.96
1.08
05:14:58 IST
0.07
0.02
0
16.46
0.00
79.48
0.00
2.88
835.96
1.08
05:14:58 IST
0.05
0.03
1
15.77
0.00
81.44
2.70
3.17
822.54
2.01
Another output from my HP Dual Opteron 64 bit
server: # 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.01
0.00
39.19
1063.46
0.36
0.13
07:44:18
0.01
0.01
0
5.87
69.47
24.16
262.11
0.44
0.05
07:44:18
0.00
0.00
1
1.79
48.59
49.02
268.92
0.36
0.23
07:44:18
0.01
0.00
2
2.19
42.63
54.73
260.96
0.28
0.16
07:44:18
0.03
0.00
3
2.17
68.56
28.83
271.47
0.34
0.06
Report CPU utilization using sar command
You can display todays CPU activity, with sar
command:
# sar
Output:
Linux 2.6.9-42.0.3.ELsmp (dellbox.xyz.co.in)
01/13/2007
12:00:02 AM
CPU
%iowait
%idle
%user
%nice
%system
12:10:01 AM
0.04
98.64
all
1.05
0.00
0.28
12:20:01 AM
0.38
98.54
all
0.74
0.00
0.34
12:30:02 AM
0.10
98.53
all
1.09
0.00
0.28
12:40:01 AM
0.03
99.00
all
0.76
0.00
0.21
12:50:01 AM
0.03
98.40
all
1.25
0.00
0.32
01:00:01 AM
0.03
98.92
all
0.80
0.00
0.24
04:40:01 AM
0.06
58.38
all
8.39
0.00
33.17
04:50:01 AM
0.04
53.78
all
8.68
0.00
37.51
05:00:01 AM
0.04
62.39
all
7.10
0.00
30.48
05:10:01 AM
0.03
53.44
all
8.78
0.00
37.74
05:20:02 AM
0.06
56.18
all
8.30
0.00
35.45
Average:
0.09
87.68
all
3.09
0.00
9.14
...
.....
..
Comparison of CPU utilization
The sar command writes to standard output the
contents of selected cumulative activity counters in the
operating system. The accounting system, based on
the values in the count and interval parameters. For
example display comparison of CPU utilization; 2
seconds apart; 5 times, use:
# 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
%iowait
%idle
%user
%nice
%system
05:33:26 AM
0.00
41.50
all
9.50
0.00
49.00
05:33:28 AM
0.00
8.52
all
16.79
0.00
74.69
05:33:30 AM
0.00
2.49
all
17.21
0.00
80.30
05:33:32 AM
0.00
2.25
all
16.75
0.00
81.00
05:33:34 AM
0.00
13.28
all
14.29
0.00
72.43
Average:
0.00
13.61
all
14.91
0.00
71.49
Where,
-u 12 5 : Report CPU utilization. The following
values are displayed:
%user: Percentage of CPU utilization that
occurred while executing at the user level
(application).
%nice: Percentage of CPU utilization that
occurred while executing at the user level with
nice priority.
%system: Percentage of CPU utilization that
occurred while executing at the system level
(kernel).
%iowait: Percentage of time that the CPU or
CPUs were idle during which the system had an
outstanding disk I/O request.
%idle: Percentage of time that the CPU or CPUs
were idle and the system did not have an
outstanding disk I/O request.
To get multiple samples and multiple reports set an
output file for the sar command. Run the sar command
as a background process using.
# sar -o output.file 12 8 >/dev/null 2>&1 &
Better use nohup command so that you can logout and
check 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 displayed
ith the sar command using the -f option.
# sar -f data.file
Task: Find out who is monopolizing or
eating the CPUs
Finally, you need to determine which process is
monopolizing or eating the CPUs. Following command
will displays the top 10 CPU users on the Linux
system.
# ps -eo pcpu,pid,user,args | sort -k 1 -r | head
-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 64bit/Ubuntu 64-bit.vmx -@ ""
0.7 3358 mysql
/usr/libexec/mysqld --defaultsfile=/etc/my.cnf --basedir=/usr -datadir=/var/lib/mysql --user=mysql --pidfile=/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
pcpu (cpu utilization). It is sorted in reverse order to
display top 10 CPU eating process.
iostat command
You can also use iostat command which report Central
Processing Unit (CPU) statistics and input/output
statistics for devices and partitions. It can be use to
find out your system's average CPU utilization since
the last reboot.
# iostat Output:
Linux 2.6.15.4 (debian)
2006
avg-cpu:
%idle
%user
16.36
Device:
Blk_read
hda
16
hdb
875340
%nice %system %iowait
0.00
2.99
1.06
%steal
0.00
79.59
tps
Blk_wrtn
Blk_read/s
Blk_wrtn/s
0.00
0.00
0.00
6.43
85.57
166.74
0.03
0.16
0.00
0.00
0.00
0.00
1705664
hdc
1644
sda
24
Thursday 06 April
You may want to use following command, which gives
you 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 remote
server. For local system with X GUI installed you can
try 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)
In addition, the gnome-system-monitor provides an
overall view of the resource usage on your system,
including memory and CPU allocation.
Printenv | less
Printenv | more
Printenv
Set | more
Set
Env
Env | more