Linux Some Commands
Linux Some 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)
..
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
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.
# 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
Music
Pictures
Music
Documents
Templates
Pictures
Public
Desktop
Downloads
Videos
#
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)
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.
# 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
|
|-- 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.
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.
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)
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.
Sample Outpit
Tecmint [dot] com is the world's best website for
qualitative Linux article
The above command shows the list of all the mounted filesystem in a nice formatting with
specification.
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
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
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.
20. file
No! the above command is not a typo. file is a command which gives you information
about the type of file.
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.
avi@localhost:~/Desktop$ lls -l
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
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.
OR
Sample Output
-rw-r--r-- 1 avi
Screenshot-1.png
avi
220492 Nov
avi
1 13:49
..
..
-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
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.
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.
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
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
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.
...
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
avi@localhost:~/Desktop$ factor 22
22: 2 11
avi@localhost:~/Desktop$ factor 21
21: 3 7
avi@localhost:~/Desktop$ factor 11
11: 11
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.
Sample Output
1. Linux is built with certain powerful tools, which
are unavailable in windows.
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.
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:
Release:
6.3
Codename:
Final
Note:
Option
-a,
shows
all
the
available
of version, id, description,release and codename.
information
in
respect
$ nc -zv localhost 80
$ 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."
./.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.
./.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
./.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.
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
$ ps -LF -u avi
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.
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:
Sample Output
execve("/bin/pwd", ["pwd"], [/* 29 vars */]) = 0
brk(0)
= 0x728000
= -1 ENOENT
open("/etc/ld.so.cache", O_RDONLY)
= 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
= 0
32
Download Linux Command Line Cheat Sheet
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.
Sample Output
_ ___
____
___
Fri Nov 29 10:29:34 GMT
_____ _
/ |/ _ \ _|___ \ / _ \ _|___ /| || |
| | | | (_) __) | (_) (_) |_ \| || |_
| | |_| |_ / __/ \__, |_ ___) |__
|_|\___/(_)_____|
/_/(_)____/
_|
|_|
dstat command
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)
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.
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.
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'
lcd path
to 'path'
Change permissions of
help
Download file
ln oldpath newpath
lmkdir path
lpwd
directory
ls [path]
directory listing
Display remote
lumask umask
'umask'
mkdir path
Upload file
pwd
directory
exit
Quit sftp
quit
Quit sftp
rmdir path
rm path
version
!command
local shell
Execute 'command' in
sftp> lpwd
Local working directory: /
sftp> pwd
Remote working directory: /tecmint/
o
o
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.
6. Download Files
Getting single or multiple files in local system.
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.
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.
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.
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
# 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 0
0 2540956 522188 5130400
0 1151 1569 4 1 95 0 0
0 0
6 1117
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 0
536 1189
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
Output:
18:02:41 up 41 days, 23:42,
0.00, 0.00, 0.00
1 user,
load average:
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 -ejH
# ps axjf
# pstree
OR
# pgrep lighttpd
OR
# pgrep -u vivek php-cgi
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?
Sample Outputs:
Linux 2.6.18-128.1.14.el5 (www03.nixcraft.in)
06/26/2009
avg-cpu:
%idle
%user
3.50
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
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
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
# pmap -d PID
Sample Outputs:
47394:
Address
Device
/usr/bin/php-cgi
Kbytes Mode
Offset
Mapping
0000000000400000
008:00002 php-cgi
0000000000886000
008:00002 php-cgi
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
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
Output:
Thursday 06 April
all
16.52
0.00
79.42
0.00
2.87
830.06
1.09
# 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
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
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
...
.....
..
# sar -u 2 5
%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,
-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]
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
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
Printenv | less
Printenv | more
Printenv
Set | more
Set
Env
Env | more