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 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 don’t 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-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-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 Music Pictures Public Templates Videos

# ls | shuf (shuffle Input)

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 Local Address:Port Peer 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:8000 127.0.0.1:41384

ESTAB 0 0 192.168.1.198:41002 *.*.*.*:http

ESTAB 0 0 127.0.0.1:41384 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 withtty’s.

# last server pts/0 :0 Tue Oct 22 12:03 still logged in server tty8 :0 Tue Oct 22 12:02 still logged in

... (unknown tty8 :0 Tue Oct 22 12:02 - 12:02 (00:00) server pts/0 :0 Tue Oct 22 10:33 - 12:02 (01:29) server tty7 :0 Tue Oct 22 10:05 - 12:02 (01:56)

(unknown tty7 :0 Tue Oct 22 10:04 - 10:05 (00:00) reboot system boot 3.2.0-4-686-pae Tue Oct 22 10:04 - 12:44 (02:39)

wtmp begins Fri Oct 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 don’t 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 init─┬─NetworkManager───{NetworkManager}

├─accounts-daemon───{accounts-daemon}

├─acpi_fakekeyd

├─acpid

├─apache2───10*[apache2]

├─at-spi-bus-laun───2*[{at-spi-bus-laun}]

├─atd

├─avahi-daemon───avahi-daemon ├─bluetoothd

├─colord───{colord}

├─colord-sane───2*[{colord-sane}]

├─console-kit-dae───64*[{console-kit-dae}]

├─cron

├─cupsd

├─2*[dbus-daemon]

├─dbus-launch

├─dconf-service───2*[{dconf-service}]

├─dovecot─┬─anvil

│ ├─config

│ └─log

├─exim4

├─gconfd-2

├─gdm3─┬─gdm-simple-slav─┬─Xorg

│ │ ├─gdm-session-wor─┬─x- session-manag─┬─evolution-a+

│ │ │ │ ├─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-d───9*[{gnome-keyring-d}]

├─gnome-shell-cal───2*[{gnome-shell-cal}]

├─goa-daemon───{goa-daemon}

├─gsd-printer───{gsd-printer}

├─gvfs-afc-volume───{gvfs-afc-volume}

That’s 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. 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 “hi”and 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 Blocks: 64 IO Block: 4096 regular file

Device: 801h/2049d Inode: 5030293 Links: 1 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 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 / type ext3 (rw,errors=remount-ro) tmpfs on /lib/init/rw type tmpfs (rw,nosuid,mode=0755) proc on /proc type proc (rw,noexec,nosuid,nodev) sysfs on /sys type sysfs (rw,noexec,nosuid,nodev) udev on /dev type tmpfs (rw,mode=0755) tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev) devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=620) fusectl on /sys/fs/fuse/connections type fusectl (rw) binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev) nfsd on /proc/fs/nfsd type nfsd (rw)

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 [email protected] -- 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 '[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

François 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)

That’s all for now. Seeing the success of last article of this series and this very article, I’ll be coming with another part of this article containing several other Lesser Known Linuxcommands very soon. Till then Stay Tuned and connected to Tecmint. Don’t 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 avi 36864 Nov 13 2012 101MSDCF

-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:59 Untitled 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 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, don’t 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 avi 220492 Nov 1 13:49 Screenshot-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:29 squeeze.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:56 Untitled 1.odt

-rw-r--r-- 1 avi avi 9405 Nov 12 23:22 Untitled.png

Note: echo “ls -l” : This string echo’s 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 didn’t 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 it’s 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.

That’s 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. Don’t forget to provide us with your value-able comment. I’ll 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:core- 4.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 information in respect of version, id, description,release and codename. 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 libxml- sax-expat-perl libxml-sax-perl libxml-simple-perl libxrandr-dev libxrender-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 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-dvd- 32bit.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 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_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. That’s 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) = -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\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. Let’s 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 don’t 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 today’s 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

That’s 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. Don’t 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 don’t 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 [email protected]

Connecting to 27.48.137.6... [email protected]'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 Change remote directory to 'path' lcd path Change local directory to 'path' chgrp grp path Change group of file 'path' to 'grp' chmod mode path Change permissions of file '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 directory listing ln oldpath newpath Symlink remote file lmkdir path Create local directory lpwd Print local working directory ls [path] Display remote directory listing lumask umask Set local umask to 'umask' mkdir path Create remote directory put local-path [remote-path] Upload file pwd Display remote working directory 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' in local shell

! 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 lpwd – print the current directory on your system o 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 NIX CRAFT on JUNE 27, 2009 · 342 COMMENTS· LAST UPDATED JANUARY 1, 2014 in CENTOS, DEBIAN LINUX, FEDORA LINUX

Need 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 Usage Key t Displays summary information off and on. m Displays memory information off and on. Sorts the display by top consumers of various system resources. Useful for A quick identification of performance-hungry tasks on a system. Enters an interactive configuration screen for top. Helpful for setting up top f 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, 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 b swpd free buff cache si so bi bo in cs us sy id wa st

0 0 0 2540988 522188 5130400 0 0 2 32 4 2 4 1 96 0 0

1 0 0 2540988 522188 5130400 0 0 0 720 1199 665 1 0 99 0 0

0 0 0 2540956 522188 5130400 0 0 0 0 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 0 536 1189 932 1 0 98 0 0

0 0 0 2538444 522188 5130588 0 0 0 0 1187 1417 4 1 96 0 0

0 0 0 2490060 522188 5130640 0 0 0 18 1253 1123 5 1 94 0 0

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, 2 users, load average: 0.36, 0.26, 0.24

USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT root pts/0 10.1.3.145 14:55 5.00s 0.04s 0.02s vim /etc/resolv.conf root pts/1 10.1.3.145 17:43 0.00s 0.03s 0.00s w

#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, 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 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: total used free shared buffers cached Mem: 12302896 9739664 2563232 0 523124 5154740

-/+ buffers/cache: 4061800 8241096

Swap: 1052248 0 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: %user %nice %system %iowait %steal %idle

3.50 0.09 0.51 0.03 0.00 95.86

Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn sda 22.04 31.88 512.03 16193351 260102868 sda1 0.00 0.00 0.00 2166 180 sda2 22.04 31.87 512.03 16189010 260102688 sda3 0.00 0.00 0.00 1615 0

=> 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 %nice %system %iowait %steal %idle 06:45:16 PM all 2.00 0.00 0.22 0.00 0.00 97.78

06:45:20 PM all 2.07 0.00 0.38 0.03 0.00 97.52

06:45:24 PM all 0.94 0.00 0.28 0.00 0.00 98.78

06:45:28 PM all 1.56 0.00 0.22 0.00 0.00 98.22

06:45:32 PM all 3.53 0.00 0.25 0.03 0.00 96.19

Average: all 2.02 0.00 0.27 0.01 0.00 97.70

=> 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.03 0.01 0.17 0.00 95.86 1218.04

06:48:11 PM 0 3.44 0.08 0.31 0.02 0.00 0.12 0.00 96.04 1000.31

06:48:11 PM 1 3.10 0.08 0.32 0.09 0.02 0.11 0.00 96.28 34.93

06:48:11 PM 2 4.16 0.11 0.36 0.02 0.00 0.11 0.00 95.25 0.00

06:48:11 PM 3 3.77 0.11 0.38 0.03 0.01 0.24 0.00 95.46 44.80

06:48:11 PM 4 2.96 0.07 0.29 0.04 0.02 0.10 0.00 96.52 25.91

06:48:11 PM 5 3.26 0.08 0.28 0.03 0.01 0.10 0.00 96.23 14.98

06:48:11 PM 6 4.00 0.10 0.34 0.01 0.00 0.13 0.00 95.42 3.75

06:48:11 PM 7 3.30 0.11 0.39 0.03 0.01 0.46 0.00 95.69 76.89

=> 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: /usr/bin/php-cgi

Address Kbytes Mode Offset Device Mapping

0000000000400000 2584 r-x-- 0000000000000000 008:00002 php-cgi

0000000000886000 140 rw--- 0000000000286000 008:00002 php-cgi

00000000008a9000 52 rw--- 00000000008a9000 000:00000 [ anon ]

0000000000aa8000 76 rw--- 00000000002a8000 008:00002 php-cgi

000000000f678000 1980 rw--- 000000000f678000 000:00000 [ anon ]

000000314a600000 112 r-x-- 0000000000000000 008:00002 ld-2.5.so

000000314a81b000 4 r---- 000000000001b000 008:00002 ld-2.5.so

000000314a81c000 4 rw--- 000000000001c000 008:00002 ld-2.5.so 000000314aa00000 1328 r-x-- 0000000000000000 008:00002 libc-2.5.so

000000314ab4c000 2048 ----- 000000000014c000 008:00002 libc-2.5.so

.....

......

..

00002af8d48fd000 4 rw--- 0000000000006000 008:00002 xsl.so

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 writeable/private: 4304K shared: 768000K

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 - Real- time 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 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 NIX CRAFT on APRIL 6, 2006 · 148 COMMENTS· LAST UPDATED DECEMBER 18, 2008 in LINUX, SYS ADMIN, TIPS

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 task’s 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) Thursday 06 April 2006

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.09 0.07 0.02 0.00 79.42 830.06

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 all 16.46 0.00 2.88 1.08 0.07 0.02 0.00 79.48 835.96

05:14:58 IST 0 16.46 0.00 2.88 1.08 0.07 0.02 0.00 79.48 835.96

05:14:58 IST 1 15.77 2.70 3.17 2.01 0.05 0.03 0.00 81.44 822.54

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.36 0.13 0.01 0.00 39.19 1063.46

07:44:18 0 5.87 69.47 0.44 0.05 0.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 07:44:18 2 2.19 42.63 0.28 0.16 0.01 0.00 54.73 260.96

07:44:18 3 2.17 68.56 0.34 0.06 0.03 0.00 28.83 271.47

Report CPU utilization using sar command You can display today’s 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 %user %nice %system %iowait %idle

12:10:01 AM all 1.05 0.00 0.28 0.04 98.64

12:20:01 AM all 0.74 0.00 0.34 0.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.21 0.03 99.00

12:50:01 AM all 1.25 0.00 0.32 0.03 98.40 01:00:01 AM all 0.80 0.00 0.24 0.03 98.92

...

.....

..

04:40:01 AM all 8.39 0.00 33.17 0.06 58.38

04:50:01 AM all 8.68 0.00 37.51 0.04 53.78

05:00:01 AM all 7.10 0.00 30.48 0.04 62.39

05:10:01 AM all 8.78 0.00 37.74 0.03 53.44

05:20:02 AM all 8.30 0.00 35.45 0.06 56.18

Average: all 3.09 0.00 9.14 0.09 87.68

Comparison of CPU utilization The sar command writes to standard output the contents of selected cumulative activity counters in the . 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 %user %nice %system %iowait %idle

05:33:26 AM all 9.50 0.00 49.00 0.00 41.50

05:33:28 AM all 16.79 0.00 74.69 0.00 8.52

05:33:30 AM all 17.21 0.00 80.30 0.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.43 0.00 13.28

Average: all 14.91 0.00 71.49 0.00 13.61

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 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 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) Thursday 06 April 2006 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/s Blk_read Blk_wrtn hda 0.00 0.00 0.00 16 0 hdb 6.43 85.57 166.74 875340 1705664 hdc 0.03 0.16 0.00 1644 0 sda 0.00 0.00 0.00 24 0 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