This is not a comprehensive list by any means, but this should give you a jumpstart on some of the common Linux commands. Bookmark this article for your future reference.
Command Examples in Linux....
1)Linux Command to Display All Users
If you want to display all the users on your Linux Box, just run this command:
# cat /etc/passwd |grep "/home" |cut -d: -f1
[root@oracle ~]# cat /etc/passwd |grep "/home" |cut -d: -f1
geet
prakash
ajay
jay
sanjeeb
amol
oracle
[root@oracle ~]# /bin/cat /proc/cpuinfo | /bin/egrep 'processor|model name|cachesize|core|sibling|physical'
processor : 0
model name : Intel(R) Core(TM)2 Duo CPU E7500 @ 2.93GHz
physical id : 0
siblings : 2
core id : 0
cpu cores : 2
address sizes : 36 bits physical, 48 bits virtual
processor : 1
model name : Intel(R) Core(TM)2 Duo CPU E7500 @ 2.93GHz
physical id : 0
siblings : 2
core id : 1
cpu cores : 2
address sizes : 36 bits physical, 48 bits virtual
# rpm -ivh httpd-2.2.3-22.0.1.el5.i386.rpm
To upgrade apache using rpm.
# rpm -uvh httpd-2.2.3-22.0.1.el5.i386.rpm
To uninstall/remove apache using rpm.
# rpm -ev httpd
4) date command examples
Set the system date:
# date -s "06/29/2010 23:59:53"
Once you’ve changed the system date, you should syncronize the hardware clock with the
system date as shown below.
# hwclock –systohc
# hwclock --systohc –utc
5) mysql command examples
mysql is probably the most widely used open source database on Linux. Even if you don’t
run a mysql database on your server, you might end-up using the mysql command ( client )
to connect to a mysql database running on the remote server.
To connect to a remote mysql database. This will prompt for a password.
# mysql -u root -p -h 192.168.1.2
To connect to a local mysql database.
# mysql -u root -p
6) mount command examples
To mount a file system, you should first create a directory and mount it as shown below.
# mkdir /u01
# mount /dev/sdb1 /u01
You can also add this to the fstab for automatic mounting. i.e Anytime system is
restarted, the filesystem will be mounted.
/dev/sdb1 /u01 ext2 defaults 0 2
7) kill command examples
Use kill command to terminate a process. First get the process id using ps -ef command,
then use kill -9 to kill the running Linux process as shown below. You can also use
killall, pkill, xkill to terminate a unix process.
# ps -ef | grep vim
prakash 7243 7222 9 22:43 pts/2 00:00:00 vim
# kill -9 7243
8) ps command examples
ps command is used to display information about the processes that are running in the system.
While there are lot of arguments that could be passed to a ps command, following are some
of the common ones.
To view current running processes.
# ps -ef | more
To view current running processes in a tree structure. H option stands for process hierarchy.
# ps -efH | more
9) tar command examples
Create a new tar archive.
# tar cvf archive_name.tar dirname/
Extract from an existing tar archive.
# tar xvf archive_name.tar
View an existing tar archive.
# tar tvf archive_name.tar
10) grep command examples
Search for a given string in a file (case in-sensitive search).
# grep -i "the" demo_file
Print the matched line, along with the 3 lines after it.
# grep -A 3 -i "example" demo_text
Search for a given string in all files recursively
# grep -r "prakash" *
11) find command examples
Find files using file-name ( case in-sensitve find)
# find -iname "MyCProgram.c"
Execute commands on files found by the find command
# find -iname "MyCProgram.c" -exec md5sum {} \;
Find all empty files in home directory
# find ~ -empty
12) lspci
lspci is a utility for displaying information about all PCI buses in the system and all devices connected to them.
Example: 1
[root@oracle ~]# lspci
00:00.0 Host bridge: Intel Corporation 4 Series Chipset DRAM Controller (rev 03)
00:02.0 VGA compatible controller: Intel Corporation 4 Series Chipset Integrated Graphics Controller (rev 03)
00:02.1 Display controller: Intel Corporation 4 Series Chipset Integrated Graphics Controller (rev 03)
00:19.0 Ethernet controller: Intel Corporation 82567V-4 Gigabit Network Connection (rev 02)
00:1a.0 USB controller: Intel Corporation 82801JD/DO (ICH10 Family) USB UHCI Controller #4 (rev 02)
The above command will display the information about system PCI devices
Example: 2
[root@oracle ~]# lspci -t
-[0000:00]-+-00.0
+-02.0
+-02.1
+-19.0
+-1a.0
+-1a.1
+-1a.2
+-1a.7
+-1b.0
+-1c.0-[20]--
+-1d.0
+-1d.1
+-1d.2
+-1d.7
+-1e.0-[10]--
+-1f.0
+-1f.2
\-1f.5
The above commands gives output of all devices,buses, connections in a tree like diagram.
Example:3
[root@oracle ~]# lspci -v
00:00.0 Host bridge: Intel Corporation 4 Series Chipset DRAM Controller (rev 03)
Subsystem: Hewlett-Packard Company Device 1493
Flags: bus master, fast devsel, latency 0
Capabilities: [e0] Vendor Specific Information: Len=0c <?>
Kernel driver in use: agpgart-intel
00:02.0 VGA compatible controller: Intel Corporation 4 Series Chipset Integrated Graphics Controller (rev 03) (prog-if 00 [VGA controller])
Subsystem: Hewlett-Packard Company Device 1493
Flags: bus master, fast devsel, latency 0, IRQ 45
Memory at f0000000 (64-bit, non-prefetchable) [size=4M]
Memory at e0000000 (64-bit, prefetchable) [size=256M]
I/O ports at 1240 [size=8]
Expansion ROM at <unassigned> [disabled]
Capabilities: [90] MSI: Enable+ Count=1/1 Maskable- 64bit-
Capabilities: [d0] Power Management version 2
Kernel driver in use: i915
Kernel modules: i915
00:02.1 Display controller: Intel Corporation 4 Series Chipset Integrated Graphics Controller (rev 03)
Subsystem: Hewlett-Packard Company Device 1493
Flags: bus master, fast devsel, latency 0
Memory at f0400000 (64-bit, non-prefetchable) [disabled] [size=1M]
Capabilities: [d0] Power Management version 2
00:19.0 Ethernet controller: Intel Corporation 82567V-4 Gigabit Network Connection (rev 02)
Subsystem: Hewlett-Packard Company Device 1493
Flags: bus master, fast devsel, latency 0, IRQ 46
Memory at f0500000 (32-bit, non-prefetchable) [size=128K]
Memory at f0524000 (32-bit, non-prefetchable) [size=4K]
I/O ports at 1100 [size=32]
Capabilities: [c8] Power Management version 2
Capabilities: [d0] MSI: Enable+ Count=1/1 Maskable- 64bit+
Capabilities: [e0] PCI Advanced Features
Kernel driver in use: e1000e
Kernel modules: e1000e
00:1a.0 USB controller: Intel Corporation 82801JD/DO (ICH10 Family) USB UHCI Controller #4 (rev 02) (prog-if 00 [UHCI])
Subsystem: Hewlett-Packard Company Device 1493
Flags: bus master, medium devsel, latency 0, IRQ 20
I/O ports at 1120 [size=32]
Capabilities: [50] PCI Advanced Features
Kernel driver in use: uhci_hcd
The above optput shows the details information of all the pci devices, and $lspci –vv gives more detailed verbose information about the pci devices.The proc filesystem (/proc/pci )also have details about pci devices.
13) locate command examples
Using locate command you can quickly search for the location of a specific file
Example 1 locate syslog
Example: slocate syslog | more (Piping structure used to invert the data from locate to the
more command)
[root@oracle ~]# locate syslog | more
/etc/rsyslog.conf
/etc/rsyslog.d
/etc/172.24.3.78/rsyslog
/etc/audisp/plugins.d/syslog.conf
/etc/latrace.d/syslog.conf
/etc/logrotate.d/syslog
/etc/pki/rsyslog
/etc/rc.d/init.d/rsyslog
/etc/rc.d/rc0.d/K88rsyslog
/etc/rc.d/rc1.d/K88rsyslog
/etc/rc.d/rc2.d/S12rsyslog
/etc/rc.d/rc3.d/S12rsyslog
/etc/rc.d/rc4.d/S12rsyslog
/etc/rc.d/rc5.d/S12rsyslog
/etc/rc.d/rc6.d/K88rsyslog
The example 2 below shows all files in the system that contains the word crontab in it
[root@oracle ~]# locate crontab
/etc/anacrontab
/etc/crontab
/usr/bin/crontab
/usr/lib/python2.6/site-packages/sos/plugins/crontab.py
/usr/lib/python2.6/site-packages/sos/plugins/crontab.pyc
/usr/lib/python2.6/site-packages/sos/plugins/crontab.pyo
/usr/share/man/man1/crontab.1.gz
/usr/share/man/man1p/crontab.1p.gz
/usr/share/man/man4/crontabs.4.gz
/usr/share/man/man5/anacrontab.5.gz
/usr/share/man/man5/crontab.5.gz
/usr/share/man/man8/crontab_selinux.8.gz
/usr/share/vim/vim72/syntax/crontab.vim
note: Some keywords returns enormous ammounts of hits. Use MORE to (see example) clear
things up a bit.
14) dmesg
The dmesg command is used to write the kernel messages in Linux and other Unix-like
operating systems to standard output
dmesg examines or controls the kernel ring buffer.
The kernel ring buffer is a data structure that records messages related to the operation
of the kernel. A ring buffer is a special kind of buffer that is always a constant size,
removing the oldest messages when new messages come in.
Syntax # dmesg [options]
Invoking dmesg without any of its options (which are rarely used) causes it to write all
the kernel messages to standard output. This usually produces far too many lines to fit
into the display screen all at once, and thus only the final messages are visible.
However, the output can be redirected to the less command through the use of a pipe
(designated by the vertical bar character), thereby allowing the startup messages to be
viewed one screenful at a time:
# dmesg | less
less allows the output to be moved forward one screenful at a time by pressing the SPACE
bar, backward by pressing the b key and removed by pressing the q key. (The more command
could have been used here instead of the less command; however, less is newer than more
and has additional functions, including the ability to return to previous pages of the
output.)
When a user encounters a problem with the system, it can be convenient to write the output
of dmesg to a file and then send that file by e-mail to a system administrator or other
knowledgeable person for assistance. For example, the output could be redirected to a file
named boot_messages using the output redirection operator (designated by a rightward
facing angle bracket) as follows:
dmesg > boot_messages
Because of the length of the output of dmesg, it can be convenient to pipe its output to
grep, a filter which searches for any lines that contain the string (i.e., sequence of
characters) following it. The -i option can be used to tell grep to ignore the case (i.e.,
lower case or upper case) of the letters in the string. For example, the following command
lists all references to USB (universal serial bus) devices in the kernel messages:
# dmesg | grep -i usb
And the following tells dmesg to show all serial ports (which are represented by the
string tty):
# dmesg | grep -i tty
The dmesg and grep combination can also be used to show how much physical memory (i.e.,
RAM) is available on the system:
# dmesg | grep -i memory
The following command checks to confirm that the HDD(s) is running in DMA (direct memory
access) mode:
# dmesg | grep -i dma
The output of dmesg is maintained in the log file /var/log/dmesg, and it can thus also be
easily viewed by reading that file with a text editor, such as vi or gedit, or with a
command such as cat, e.g.,
# cat /var/log/dmesg | less
15) Less Command
less command allows quickly view file. You can page up and down. Press ‘q‘ to quit from
less window.
# less install.log
Installing setup-2.8.14-10.el6.noarch
warning: setup-2.8.14-10.el6.noarch: Header V3 RSA/SHA256 Signature, key ID c105b9de:
NOKEY
Installing filesystem-2.4.30-2.1.el6.i686
Installing ca-certificates-2010.63-3.el6.noarch
Installing xml-common-0.6.3-32.el6.noarch
Installing tzdata-2010l-1.el6.noarch
Installing iso-codes-3.16-2.el6.noarch====
16) More Command
more command allows quickly view file and shows details in percentage. You can page up and
down. Press ‘q‘ to quit out from more window.
# more install.log
Installing setup-2.8.14-10.el6.noarch
warning: setup-2.8.14-10.el6.noarch: Header V3 RSA/SHA256 Signature, key ID c105b9de:
NOKEY
Installing filesystem-2.4.30-2.1.el6.i686
Installing ca-certificates-2010.63-3.el6.noarch
Installing xml-common-0.6.3-32.el6.noarch
Installing tzdata-2010l-1.el6.noarch
Installing iso-codes-3.16-2.el6.noarch
--More--(10%)
17) Cat Command
cat command used to view multiple file at the same time.
# cat fileA fileB
You combine more and less command with cat command to view file contain if that doesn’t
fit in single screen / page.
# cat install.log | less
# cat install.log | more
18) Top Command
top command displays processor activity of your system and also displays tasks managed by
kernel in real-time. It’ll show processor and memory are being used. Use top command with
‘u‘ option this will display specific User process details as shown below. Press ‘O‘
(uppercase letter) to sort as per desired by you. Press ‘q‘ to quit from top screen.
# top -u prakash
top - 11:13:11 up 3:19, 2 users, load average: 0.00, 0.00, 0.00
Tasks: 116 total, 1 running, 115 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.0%us, 0.3%sy, 0.0%ni, 99.7%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 1030800k total, 736188k used, 294612k free, 51760k buffers
Swap: 2064376k total, 0k used, 2064376k free, 547704k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1989 prakash 20 0 11468 1648 920 S 0.0 0.2 0:00.59 sshd
1990 prakash 20 0 5124 1668 1416 S 0.0 0.2 0:00.44 bash
6278 prakash 20 0 11600 1668 924 S 0.0 0.2 0:01.19 sshd
6285 prakash 20 0 5124 1596 1352 S 0.0 0.2 0:00.11 bash
19) lsof Command
lsof mean List of all open files. Below lsof command list of all opened files by user prakash.
# lsof -u prakash
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
sshd 1421 prakash cwd DIR 253,0 4096 2 /
sshd 1421 prakash txt REG 253,0 531471 291456 /usr/sbin/sshd
sshd 1421 prakash DEL REG 253,0 142140 /lib/libcom_err.so.2.1
sshd 1421 prakash DEL REG 253,0 314216 /lib/ld-2.12.so
sshd 1421 prakash DEL REG 253,0 142143 /usr/lib/libcrypto.so.1.0.0
sshd 1421 prakash DEL REG 253,0 391421 /lib/libnsl-2.12.so
sshd 1421 prakash DEL REG 253,0 415423 /lib/libkrb5support.so.0.1
sshd 1421 prakash DEL REG 253,0 411067 /lib/libplc4.so
20) last command
With last command we can watch user’s activity in the system. This command can execute
normal user also. It will display complete user’s info like terminal, time, date, system
reboot or boot and kernel version. Useful command to troubleshoot.
# last
[root@oracle ~]# last
root pts/0 172.24.0.17 Tue Nov 26 15:46 still logged in
reboot system boot 3.8.2-prakash.el Mon Nov 25 23:45 - 16:44 (16:58)
root pts/0 172.24.0.17 Mon Nov 25 16:24 - down (07:20)
root pts/0 172.24.0.17 Fri Nov 22 21:39 - 22:40 (01:01)
root pts/0 172.24.0.17 Thu Nov 21 16:03 - 21:07 (1+05:04)
root pts/0 172.24.0.17 Tue Nov 19 16:05 - 17:04 (1+00:59)
reboot system boot 3.8.2-prakash.el Tue Nov 19 16:04 - 23:44 (6+07:40)
root pts/0 172.24.0.17 Tue Nov 19 15:19 - down (00:04)
root pts/0 172.24.0.17 Tue Nov 19 15:11 - 15:19 (00:07)
root pts/0 172.24.0.17 Mon Nov 18 23:17 - 10:29 (11:11)
reboot system boot 3.8.2-prakash.el Sat Nov 16 21:22 - 15:24 (2+18:01)
root pts/0 172.24.0.17 Sat Nov 16 21:17 - down (00:03)
You can use last with username to know for specific user’s activity as shown below.
# last oracle
[root@oracle ~]# last oracle
oracle pts/0 172.24.0.17 Sat Nov 16 20:55 - 21:17 (00:21)
oracle pts/0 172.24.0.17 Sat Nov 16 20:47 - down (00:06)
wtmp begins Fri Feb 1 16:50:32 2013
21) Recursively list Sub-Directories
ls -R option will list very long listing directory trees. See an example of output of the
command.
# ls -R
total 1384
-rw-------. 1 root root 33408 Aug 8 17:25 anaconda.log
-rw-------. 1 root root 30508 Aug 8 17:25 anaconda.program.log./httpd:
total 132
-rw-r--r-- 1 root root 0 Aug 19 03:14 access_log
-rw-r--r--. 1 root root 61916 Aug 10 17:55 access_log-20120812./lighttpd:
total 68
-rw-r--r-- 1 lighttpd lighttpd 7858 Aug 21 15:26 access.log
-rw-r--r--. 1 lighttpd lighttpd 37531 Aug 17 18:21 access.log-20120819
./nginx:
total 12
-rw-r--r--. 1 root root 0 Aug 12 03:17 access.log
-rw-r--r--. 1 root root 390 Aug 12 03:17 access.log-20120812.gz
22) Reverse Output Order
With combination of -ltr will shows latest modification file or directory date as last.
# ls -ltr
total 3904
-rwx------. 1 root root 1067 Jan 10 2006 install.sh
-rw-r--r--. 1 root root 83158 Aug 14 2010 iRedMail-0.6.1.tar.bz2
-rw-r--r--. 1 root root 9002 Jul 22 2011 index.html
-rw-r--r--. 1 root root 560123 Oct 16 2012 fuse-2.9.2.tar.gz
-rw-r--r--. 1 root root 14540 Nov 5 2012 epel-release-6-8.noarch.rpm.2
-rw-r--r--. 1 root root 14540 Nov 5 2012 epel-release-6-8.noarch.rpm.1
-rw-r--r--. 1 root root 14540 Nov 5 2012 epel-release-6-8.noarch.rpm
-rw-r--r--. 1 root root 7345 Jan 12 2013 install.log.syslog
-rw-r--r--. 1 root root 25648 Jan 12 2013 install.log
-rw-------. 1 root root 1339 Jan 12 2013 anaconda-ks.cfg
-rw-r--r--. 1 root root 577005 Jan 15 2013 ntfs-3g-1.1120.tgz
-rw-r--r--. 1 root root 0 Feb 8 2013 reboot
-rw-r--r--. 1 root root 0 Feb 8 2013 and
-rw-r--r--. 1 root root 5420 Feb 13 2013 remi-release-6.rpm
-rw-r--r--. 1 root root 38547 Mar 6 2013 boot_messages
-rwxr-xr-x. 1 root root 41847 Apr 4 2013 mysqltuner.pl
-rw-r--r--. 1 root root 41847 Apr 4 2013 mysqltuner.pl.1
drwxr-x---. 3 root root 4096 Apr 9 2013 maldetect-1.4.2
-rw-r--r--. 1 root root 811438 Apr 9 2013 maldetect-current.tar.gz
-rw-r--r--. 1 root root 2128 Apr 9 2013 server-load
# ls -lS
total 176
-rw-r--r--. 1 root root 48867 Jul 31 02:17 install.log
-rw-r--r--. 1 root root 46701 Jul 31 09:58 index.html
-rw-r--r--. 1 root root 21262 Aug 12 12:42 fbcmd_update.php
-rw-r--r--. 1 root root 11439 Jul 31 02:13 install.log.syslog
drwxr-xr-x. 2 root root 4096 Jul 31 02:48 Desktop
drwxr-xr-x. 2 root root 4096 Jul 31 02:48 Documents
drwxr-xr-x. 4 root root 4096 Aug 16 02:55 Downloads
drwxr-xr-x. 2 root root 4096 Jul 31 02:48 Music
drwxr-xr-x. 2 root root 4096 Jul 31 02:48 Pictures
drwxr-xr-x. 2 root root 4096 Jul 31 02:48 Public
drwxr-xr-x. 2 root root 4096 Jul 31 02:48 Templates
drwxr-xr-x. 2 root root 4096 Jul 31 02:48 Videos
-rw-------. 1 root root 1586 Jul 31 02:17 anaconda-ks.cfg
-rw-r--r--. 1 root root 683 Aug 19 09:59 0001.pcap
24) Display Inode number of File or Directory
We can see some number printed before file / directory name. With -i options list file /
directory with inode number.
# ls -i
[root@oracle ~]# ls -i
524297 anaconda-ks.cfg 524312 install.sh
524306 and 524400 iRedMail-0.6.1.tar.bz2
524309 bad-blocks-result 524318 maldetect-1.4.2
524304 boot_messages 524317 maldetect-current.tar.gz
524507 epel-release-6-8.noarch.rpm 524359 mirror
524310 epel-release-6-8.noarch.rpm.2 524313 mysqltuner.pl
524303 fuse-2.9.2.tar.gz 524300 ntfs-3g-1.1120.tgz
1048577 zandu 524369 prakashkernel
524302 index.html 524307 reboot
524358 index.html.1 524311 remi-release-6.rpm
524290 install.log 524360 rpmbuild
524291 install.log.syslog 524315 server-load
# ls -n
-rw-r--r--. 1 0 0 83158 Aug 14 2010 iRedMail-0.6.1.tar.bz2
drwxr-x---. 3 0 0 4096 Apr 9 2013 maldetect-1.4.2
-rw-r--r--. 1 0 0 811438 Apr 9 2013 maldetect-current.tar.gz
-rw-r--r--. 1 0 0 33328 Aug 31 17:50 mirror
-rw-r--r--. 1 0 0 33414 Aug 31 17:52 mirror.1
-rwxr-xr-x. 1 0 0 41847 Apr 4 2013 mysqltuner.pl
-rw-r--r--. 1 0 0 577005 Jan 15 2013 ntfs-3g-1.1120.tgz
drwxr-xr-x. 2 0 0 4096 Sep 4 16:34 prakashkernel
-rw-r--r--. 1 0 0 0 Feb 8 2013 reboot
-rw-r--r--. 1 0 0 5420 Feb 13 2013 remi-release-6.rpm
drwxr-xr-x. 8 0 0 4096 Aug 31 18:09 rpmbuild
-rw-r--r--. 1 0 0 2128 Apr 9 2013 server-load
[root@oracle ~]# whatis rpm
rpm (8) - RPM Package Manager
[root@oracle ~]# whatis ifconfig
ifconfig (8) - configure a network interface
[root@oracle ~]# whatis httpd
httpd (8) - Apache Hypertext Transfer Protocol Server
27) fsck command
Linux fsck utility is used to check and repair Linux filesystems (ext2, ext3, ext4, etc.).
Depending on when was the last time a file system was checked, the system runs the fsck during boot time to check whether the filesystem is in consistent state. System administrator could also run it manually when there is a problem with the filesystems.
Make sure to execute the fsck on an unmounted file systems to avoid any data corruption issues.
This article explains 10 practical examples on how to execute fsck command to troubleshoot and fix any filesystem errors.
Filesystem Check on a Disk Partition
First, view all the available partitions on your system using parted command as shown below
# parted /dev/sda 'print'
Model: ATA Hitachi HDS72102 (scsi)
Disk /dev/sda: 250GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
1 1049kB 211MB 210MB primary ext4 boot
2 211MB 105GB 105GB primary ext4
3 105GB 157GB 52.4GB primary ext4
4 157GB 250GB 92.6GB extended
6 467GB 486GB 18.3GB logical ext2
7 210GB 215GB 5243MB logical linux-swap(v1)
8 215GB 220GB 5243MB logical ext4
9 220GB 226GB 5243MB logical linux-swap(v1)
5 230GB 250GB 20.2GB logical lvm
You can check a specific filesystem (for example: /dev/sda6) as shown below.
# fsck /dev/sda6
fsck from util-linux 2.20.1
e2fsck 1.42 (29-Nov-2011)
/dev/sda6: clean, 95/2240224 files, 3793506/4476416 blocks
OR
# fsck.ext4 /dev/sda5
# cd /sbin
# ls fsck*
# fsck /dev/sda6 -f for forcefully
How to Force fsck on next boot using shutdown command ?
# shutdown -rF now
or
# touch /forcefsck and reboot
28) dmidecode Display Hardware Details In BIOS
Example: 1 Getting HW information about BIOS
[root@pserver ~]# dmidecode -t bios
# dmidecode 2.9
SMBIOS 2.31 present.
Handle 0×0000, DMI type 0, 20 bytes
BIOS Information
Vendor: Phoenix Technologies LTD
Version: 6.00
Release Date: 04/10/2007
Address: 0xE7A00
Runtime Size: 99840 bytes
ROM Size: 64 kB
Characteristics:
ISA is supported
PCI is supported
PC Card (PCMCIA) is supported
PNP is supported
APM is supported
BIOS is upgradeable
BIOS shadowing is allowed
ESCD support is available
USB legacy is supported
Smart battery is supported
BIOS boot specification is supported
[root@pserver ~]#
Similar way you find the hw information like system,baseboard, chassis,processor, memory, cache, connector, slot.
# dmidecode -t system
# dmidecode -t baseboard
# dmidecode -t chassis
# dmidecode -t memory
# dmidecode -t cashe
# dmidecode -t processor
# dmidecode -t connector
# dmidecode -t slot
29) umask establishes the file-creation permissions mask. Usage is umask xyz
30) patch updates source code. Attempts to update a file from a file of change information, or pathces, created by diff
31) lsmod used (by root) to show kernel modules currently loaded
32) lspnp utility to display information about pnp devices. Part of the pcmcia or kernel-pcmcia package, depending on the distribution.
33) awk searches for and process patterns in a file
34) nice & renice [root@prakash ~]# nice --help
With the help of Nice command in Linux you can set process priority. If you give a process a higher priority, then Kernel will allocate more cpu time to that process in Linux you can set process priority. If you give a process a higher priority, then Kernel will allocate more cpu time to that process.Process priority values range from -20 to 19.
A process with the nice value of -20 is considered to be on top of the priority. And a process with nice value of 19 is considered to be low on the priority list.
35) route -n show routing table. The n option returns numerical addresses rather than names.
Did I miss any frequently used Linux commands? Leave a comment and let me know.
Command Examples in Linux....
1)Linux Command to Display All Users
If you want to display all the users on your Linux Box, just run this command:
# cat /etc/passwd |grep "/home" |cut -d: -f1
[root@oracle ~]# cat /etc/passwd |grep "/home" |cut -d: -f1
geet
prakash
ajay
jay
sanjeeb
amol
oracle
2)Linux CPUInfo
# /bin/cat /proc/cpuinfo | /bin/egrep 'processor|model name|cachesize|core|sibling|physical' [root@oracle ~]# /bin/cat /proc/cpuinfo | /bin/egrep 'processor|model name|cachesize|core|sibling|physical'
processor : 0
model name : Intel(R) Core(TM)2 Duo CPU E7500 @ 2.93GHz
physical id : 0
siblings : 2
core id : 0
cpu cores : 2
address sizes : 36 bits physical, 48 bits virtual
processor : 1
model name : Intel(R) Core(TM)2 Duo CPU E7500 @ 2.93GHz
physical id : 0
siblings : 2
core id : 1
cpu cores : 2
address sizes : 36 bits physical, 48 bits virtual
3) rpm command examples
To install apache using rpm.# rpm -ivh httpd-2.2.3-22.0.1.el5.i386.rpm
To upgrade apache using rpm.
# rpm -uvh httpd-2.2.3-22.0.1.el5.i386.rpm
To uninstall/remove apache using rpm.
# rpm -ev httpd
4) date command examples
Set the system date:
# date -s "06/29/2010 23:59:53"
Once you’ve changed the system date, you should syncronize the hardware clock with the
system date as shown below.
# hwclock –systohc
# hwclock --systohc –utc
5) mysql command examples
mysql is probably the most widely used open source database on Linux. Even if you don’t
run a mysql database on your server, you might end-up using the mysql command ( client )
to connect to a mysql database running on the remote server.
To connect to a remote mysql database. This will prompt for a password.
# mysql -u root -p -h 192.168.1.2
To connect to a local mysql database.
# mysql -u root -p
6) mount command examples
To mount a file system, you should first create a directory and mount it as shown below.
# mkdir /u01
# mount /dev/sdb1 /u01
You can also add this to the fstab for automatic mounting. i.e Anytime system is
restarted, the filesystem will be mounted.
/dev/sdb1 /u01 ext2 defaults 0 2
7) kill command examples
Use kill command to terminate a process. First get the process id using ps -ef command,
then use kill -9 to kill the running Linux process as shown below. You can also use
killall, pkill, xkill to terminate a unix process.
# ps -ef | grep vim
prakash 7243 7222 9 22:43 pts/2 00:00:00 vim
# kill -9 7243
8) ps command examples
ps command is used to display information about the processes that are running in the system.
While there are lot of arguments that could be passed to a ps command, following are some
of the common ones.
To view current running processes.
# ps -ef | more
To view current running processes in a tree structure. H option stands for process hierarchy.
# ps -efH | more
9) tar command examples
Create a new tar archive.
# tar cvf archive_name.tar dirname/
Extract from an existing tar archive.
# tar xvf archive_name.tar
View an existing tar archive.
# tar tvf archive_name.tar
10) grep command examples
Search for a given string in a file (case in-sensitive search).
# grep -i "the" demo_file
Print the matched line, along with the 3 lines after it.
# grep -A 3 -i "example" demo_text
Search for a given string in all files recursively
# grep -r "prakash" *
11) find command examples
Find files using file-name ( case in-sensitve find)
# find -iname "MyCProgram.c"
Execute commands on files found by the find command
# find -iname "MyCProgram.c" -exec md5sum {} \;
Find all empty files in home directory
# find ~ -empty
12) lspci
lspci is a utility for displaying information about all PCI buses in the system and all devices connected to them.
Example: 1
[root@oracle ~]# lspci
00:00.0 Host bridge: Intel Corporation 4 Series Chipset DRAM Controller (rev 03)
00:02.0 VGA compatible controller: Intel Corporation 4 Series Chipset Integrated Graphics Controller (rev 03)
00:02.1 Display controller: Intel Corporation 4 Series Chipset Integrated Graphics Controller (rev 03)
00:19.0 Ethernet controller: Intel Corporation 82567V-4 Gigabit Network Connection (rev 02)
00:1a.0 USB controller: Intel Corporation 82801JD/DO (ICH10 Family) USB UHCI Controller #4 (rev 02)
The above command will display the information about system PCI devices
Example: 2
[root@oracle ~]# lspci -t
-[0000:00]-+-00.0
+-02.0
+-02.1
+-19.0
+-1a.0
+-1a.1
+-1a.2
+-1a.7
+-1b.0
+-1c.0-[20]--
+-1d.0
+-1d.1
+-1d.2
+-1d.7
+-1e.0-[10]--
+-1f.0
+-1f.2
\-1f.5
The above commands gives output of all devices,buses, connections in a tree like diagram.
Example:3
[root@oracle ~]# lspci -v
00:00.0 Host bridge: Intel Corporation 4 Series Chipset DRAM Controller (rev 03)
Subsystem: Hewlett-Packard Company Device 1493
Flags: bus master, fast devsel, latency 0
Capabilities: [e0] Vendor Specific Information: Len=0c <?>
Kernel driver in use: agpgart-intel
00:02.0 VGA compatible controller: Intel Corporation 4 Series Chipset Integrated Graphics Controller (rev 03) (prog-if 00 [VGA controller])
Subsystem: Hewlett-Packard Company Device 1493
Flags: bus master, fast devsel, latency 0, IRQ 45
Memory at f0000000 (64-bit, non-prefetchable) [size=4M]
Memory at e0000000 (64-bit, prefetchable) [size=256M]
I/O ports at 1240 [size=8]
Expansion ROM at <unassigned> [disabled]
Capabilities: [90] MSI: Enable+ Count=1/1 Maskable- 64bit-
Capabilities: [d0] Power Management version 2
Kernel driver in use: i915
Kernel modules: i915
00:02.1 Display controller: Intel Corporation 4 Series Chipset Integrated Graphics Controller (rev 03)
Subsystem: Hewlett-Packard Company Device 1493
Flags: bus master, fast devsel, latency 0
Memory at f0400000 (64-bit, non-prefetchable) [disabled] [size=1M]
Capabilities: [d0] Power Management version 2
00:19.0 Ethernet controller: Intel Corporation 82567V-4 Gigabit Network Connection (rev 02)
Subsystem: Hewlett-Packard Company Device 1493
Flags: bus master, fast devsel, latency 0, IRQ 46
Memory at f0500000 (32-bit, non-prefetchable) [size=128K]
Memory at f0524000 (32-bit, non-prefetchable) [size=4K]
I/O ports at 1100 [size=32]
Capabilities: [c8] Power Management version 2
Capabilities: [d0] MSI: Enable+ Count=1/1 Maskable- 64bit+
Capabilities: [e0] PCI Advanced Features
Kernel driver in use: e1000e
Kernel modules: e1000e
00:1a.0 USB controller: Intel Corporation 82801JD/DO (ICH10 Family) USB UHCI Controller #4 (rev 02) (prog-if 00 [UHCI])
Subsystem: Hewlett-Packard Company Device 1493
Flags: bus master, medium devsel, latency 0, IRQ 20
I/O ports at 1120 [size=32]
Capabilities: [50] PCI Advanced Features
Kernel driver in use: uhci_hcd
The above optput shows the details information of all the pci devices, and $lspci –vv gives more detailed verbose information about the pci devices.The proc filesystem (/proc/pci )also have details about pci devices.
13) locate command examples
Using locate command you can quickly search for the location of a specific file
Example 1 locate syslog
Example: slocate syslog | more (Piping structure used to invert the data from locate to the
more command)
[root@oracle ~]# locate syslog | more
/etc/rsyslog.conf
/etc/rsyslog.d
/etc/172.24.3.78/rsyslog
/etc/audisp/plugins.d/syslog.conf
/etc/latrace.d/syslog.conf
/etc/logrotate.d/syslog
/etc/pki/rsyslog
/etc/rc.d/init.d/rsyslog
/etc/rc.d/rc0.d/K88rsyslog
/etc/rc.d/rc1.d/K88rsyslog
/etc/rc.d/rc2.d/S12rsyslog
/etc/rc.d/rc3.d/S12rsyslog
/etc/rc.d/rc4.d/S12rsyslog
/etc/rc.d/rc5.d/S12rsyslog
/etc/rc.d/rc6.d/K88rsyslog
The example 2 below shows all files in the system that contains the word crontab in it
[root@oracle ~]# locate crontab
/etc/anacrontab
/etc/crontab
/usr/bin/crontab
/usr/lib/python2.6/site-packages/sos/plugins/crontab.py
/usr/lib/python2.6/site-packages/sos/plugins/crontab.pyc
/usr/lib/python2.6/site-packages/sos/plugins/crontab.pyo
/usr/share/man/man1/crontab.1.gz
/usr/share/man/man1p/crontab.1p.gz
/usr/share/man/man4/crontabs.4.gz
/usr/share/man/man5/anacrontab.5.gz
/usr/share/man/man5/crontab.5.gz
/usr/share/man/man8/crontab_selinux.8.gz
/usr/share/vim/vim72/syntax/crontab.vim
note: Some keywords returns enormous ammounts of hits. Use MORE to (see example) clear
things up a bit.
14) dmesg
The dmesg command is used to write the kernel messages in Linux and other Unix-like
operating systems to standard output
dmesg examines or controls the kernel ring buffer.
The kernel ring buffer is a data structure that records messages related to the operation
of the kernel. A ring buffer is a special kind of buffer that is always a constant size,
removing the oldest messages when new messages come in.
Syntax # dmesg [options]
Invoking dmesg without any of its options (which are rarely used) causes it to write all
the kernel messages to standard output. This usually produces far too many lines to fit
into the display screen all at once, and thus only the final messages are visible.
However, the output can be redirected to the less command through the use of a pipe
(designated by the vertical bar character), thereby allowing the startup messages to be
viewed one screenful at a time:
# dmesg | less
less allows the output to be moved forward one screenful at a time by pressing the SPACE
bar, backward by pressing the b key and removed by pressing the q key. (The more command
could have been used here instead of the less command; however, less is newer than more
and has additional functions, including the ability to return to previous pages of the
output.)
When a user encounters a problem with the system, it can be convenient to write the output
of dmesg to a file and then send that file by e-mail to a system administrator or other
knowledgeable person for assistance. For example, the output could be redirected to a file
named boot_messages using the output redirection operator (designated by a rightward
facing angle bracket) as follows:
dmesg > boot_messages
Because of the length of the output of dmesg, it can be convenient to pipe its output to
grep, a filter which searches for any lines that contain the string (i.e., sequence of
characters) following it. The -i option can be used to tell grep to ignore the case (i.e.,
lower case or upper case) of the letters in the string. For example, the following command
lists all references to USB (universal serial bus) devices in the kernel messages:
# dmesg | grep -i usb
And the following tells dmesg to show all serial ports (which are represented by the
string tty):
# dmesg | grep -i tty
The dmesg and grep combination can also be used to show how much physical memory (i.e.,
RAM) is available on the system:
# dmesg | grep -i memory
The following command checks to confirm that the HDD(s) is running in DMA (direct memory
access) mode:
# dmesg | grep -i dma
The output of dmesg is maintained in the log file /var/log/dmesg, and it can thus also be
easily viewed by reading that file with a text editor, such as vi or gedit, or with a
command such as cat, e.g.,
# cat /var/log/dmesg | less
15) Less Command
less command allows quickly view file. You can page up and down. Press ‘q‘ to quit from
less window.
# less install.log
Installing setup-2.8.14-10.el6.noarch
warning: setup-2.8.14-10.el6.noarch: Header V3 RSA/SHA256 Signature, key ID c105b9de:
NOKEY
Installing filesystem-2.4.30-2.1.el6.i686
Installing ca-certificates-2010.63-3.el6.noarch
Installing xml-common-0.6.3-32.el6.noarch
Installing tzdata-2010l-1.el6.noarch
Installing iso-codes-3.16-2.el6.noarch====
16) More Command
more command allows quickly view file and shows details in percentage. You can page up and
down. Press ‘q‘ to quit out from more window.
# more install.log
Installing setup-2.8.14-10.el6.noarch
warning: setup-2.8.14-10.el6.noarch: Header V3 RSA/SHA256 Signature, key ID c105b9de:
NOKEY
Installing filesystem-2.4.30-2.1.el6.i686
Installing ca-certificates-2010.63-3.el6.noarch
Installing xml-common-0.6.3-32.el6.noarch
Installing tzdata-2010l-1.el6.noarch
Installing iso-codes-3.16-2.el6.noarch
--More--(10%)
17) Cat Command
cat command used to view multiple file at the same time.
# cat fileA fileB
You combine more and less command with cat command to view file contain if that doesn’t
fit in single screen / page.
# cat install.log | less
# cat install.log | more
18) Top Command
top command displays processor activity of your system and also displays tasks managed by
kernel in real-time. It’ll show processor and memory are being used. Use top command with
‘u‘ option this will display specific User process details as shown below. Press ‘O‘
(uppercase letter) to sort as per desired by you. Press ‘q‘ to quit from top screen.
# top -u prakash
top - 11:13:11 up 3:19, 2 users, load average: 0.00, 0.00, 0.00
Tasks: 116 total, 1 running, 115 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.0%us, 0.3%sy, 0.0%ni, 99.7%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 1030800k total, 736188k used, 294612k free, 51760k buffers
Swap: 2064376k total, 0k used, 2064376k free, 547704k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1989 prakash 20 0 11468 1648 920 S 0.0 0.2 0:00.59 sshd
1990 prakash 20 0 5124 1668 1416 S 0.0 0.2 0:00.44 bash
6278 prakash 20 0 11600 1668 924 S 0.0 0.2 0:01.19 sshd
6285 prakash 20 0 5124 1596 1352 S 0.0 0.2 0:00.11 bash
19) lsof Command
lsof mean List of all open files. Below lsof command list of all opened files by user prakash.
# lsof -u prakash
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
sshd 1421 prakash cwd DIR 253,0 4096 2 /
sshd 1421 prakash txt REG 253,0 531471 291456 /usr/sbin/sshd
sshd 1421 prakash DEL REG 253,0 142140 /lib/libcom_err.so.2.1
sshd 1421 prakash DEL REG 253,0 314216 /lib/ld-2.12.so
sshd 1421 prakash DEL REG 253,0 142143 /usr/lib/libcrypto.so.1.0.0
sshd 1421 prakash DEL REG 253,0 391421 /lib/libnsl-2.12.so
sshd 1421 prakash DEL REG 253,0 415423 /lib/libkrb5support.so.0.1
sshd 1421 prakash DEL REG 253,0 411067 /lib/libplc4.so
20) last command
With last command we can watch user’s activity in the system. This command can execute
normal user also. It will display complete user’s info like terminal, time, date, system
reboot or boot and kernel version. Useful command to troubleshoot.
# last
[root@oracle ~]# last
root pts/0 172.24.0.17 Tue Nov 26 15:46 still logged in
reboot system boot 3.8.2-prakash.el Mon Nov 25 23:45 - 16:44 (16:58)
root pts/0 172.24.0.17 Mon Nov 25 16:24 - down (07:20)
root pts/0 172.24.0.17 Fri Nov 22 21:39 - 22:40 (01:01)
root pts/0 172.24.0.17 Thu Nov 21 16:03 - 21:07 (1+05:04)
root pts/0 172.24.0.17 Tue Nov 19 16:05 - 17:04 (1+00:59)
reboot system boot 3.8.2-prakash.el Tue Nov 19 16:04 - 23:44 (6+07:40)
root pts/0 172.24.0.17 Tue Nov 19 15:19 - down (00:04)
root pts/0 172.24.0.17 Tue Nov 19 15:11 - 15:19 (00:07)
root pts/0 172.24.0.17 Mon Nov 18 23:17 - 10:29 (11:11)
reboot system boot 3.8.2-prakash.el Sat Nov 16 21:22 - 15:24 (2+18:01)
root pts/0 172.24.0.17 Sat Nov 16 21:17 - down (00:03)
You can use last with username to know for specific user’s activity as shown below.
# last oracle
[root@oracle ~]# last oracle
oracle pts/0 172.24.0.17 Sat Nov 16 20:55 - 21:17 (00:21)
oracle pts/0 172.24.0.17 Sat Nov 16 20:47 - down (00:06)
wtmp begins Fri Feb 1 16:50:32 2013
21) Recursively list Sub-Directories
ls -R option will list very long listing directory trees. See an example of output of the
command.
# ls -R
total 1384
-rw-------. 1 root root 33408 Aug 8 17:25 anaconda.log
-rw-------. 1 root root 30508 Aug 8 17:25 anaconda.program.log./httpd:
total 132
-rw-r--r-- 1 root root 0 Aug 19 03:14 access_log
-rw-r--r--. 1 root root 61916 Aug 10 17:55 access_log-20120812./lighttpd:
total 68
-rw-r--r-- 1 lighttpd lighttpd 7858 Aug 21 15:26 access.log
-rw-r--r--. 1 lighttpd lighttpd 37531 Aug 17 18:21 access.log-20120819
./nginx:
total 12
-rw-r--r--. 1 root root 0 Aug 12 03:17 access.log
-rw-r--r--. 1 root root 390 Aug 12 03:17 access.log-20120812.gz
22) Reverse Output Order
With combination of -ltr will shows latest modification file or directory date as last.
# ls -ltr
total 3904
-rwx------. 1 root root 1067 Jan 10 2006 install.sh
-rw-r--r--. 1 root root 83158 Aug 14 2010 iRedMail-0.6.1.tar.bz2
-rw-r--r--. 1 root root 9002 Jul 22 2011 index.html
-rw-r--r--. 1 root root 560123 Oct 16 2012 fuse-2.9.2.tar.gz
-rw-r--r--. 1 root root 14540 Nov 5 2012 epel-release-6-8.noarch.rpm.2
-rw-r--r--. 1 root root 14540 Nov 5 2012 epel-release-6-8.noarch.rpm.1
-rw-r--r--. 1 root root 14540 Nov 5 2012 epel-release-6-8.noarch.rpm
-rw-r--r--. 1 root root 7345 Jan 12 2013 install.log.syslog
-rw-r--r--. 1 root root 25648 Jan 12 2013 install.log
-rw-------. 1 root root 1339 Jan 12 2013 anaconda-ks.cfg
-rw-r--r--. 1 root root 577005 Jan 15 2013 ntfs-3g-1.1120.tgz
-rw-r--r--. 1 root root 0 Feb 8 2013 reboot
-rw-r--r--. 1 root root 0 Feb 8 2013 and
-rw-r--r--. 1 root root 5420 Feb 13 2013 remi-release-6.rpm
-rw-r--r--. 1 root root 38547 Mar 6 2013 boot_messages
-rwxr-xr-x. 1 root root 41847 Apr 4 2013 mysqltuner.pl
-rw-r--r--. 1 root root 41847 Apr 4 2013 mysqltuner.pl.1
drwxr-x---. 3 root root 4096 Apr 9 2013 maldetect-1.4.2
-rw-r--r--. 1 root root 811438 Apr 9 2013 maldetect-current.tar.gz
-rw-r--r--. 1 root root 2128 Apr 9 2013 server-load
23) Sort Files by File Size
With combination of -lS displays file size in order, will display big in size first.# ls -lS
total 176
-rw-r--r--. 1 root root 48867 Jul 31 02:17 install.log
-rw-r--r--. 1 root root 46701 Jul 31 09:58 index.html
-rw-r--r--. 1 root root 21262 Aug 12 12:42 fbcmd_update.php
-rw-r--r--. 1 root root 11439 Jul 31 02:13 install.log.syslog
drwxr-xr-x. 2 root root 4096 Jul 31 02:48 Desktop
drwxr-xr-x. 2 root root 4096 Jul 31 02:48 Documents
drwxr-xr-x. 4 root root 4096 Aug 16 02:55 Downloads
drwxr-xr-x. 2 root root 4096 Jul 31 02:48 Music
drwxr-xr-x. 2 root root 4096 Jul 31 02:48 Pictures
drwxr-xr-x. 2 root root 4096 Jul 31 02:48 Public
drwxr-xr-x. 2 root root 4096 Jul 31 02:48 Templates
drwxr-xr-x. 2 root root 4096 Jul 31 02:48 Videos
-rw-------. 1 root root 1586 Jul 31 02:17 anaconda-ks.cfg
-rw-r--r--. 1 root root 683 Aug 19 09:59 0001.pcap
24) Display Inode number of File or Directory
We can see some number printed before file / directory name. With -i options list file /
directory with inode number.
# ls -i
[root@oracle ~]# ls -i
524297 anaconda-ks.cfg 524312 install.sh
524306 and 524400 iRedMail-0.6.1.tar.bz2
524309 bad-blocks-result 524318 maldetect-1.4.2
524304 boot_messages 524317 maldetect-current.tar.gz
524507 epel-release-6-8.noarch.rpm 524359 mirror
524310 epel-release-6-8.noarch.rpm.2 524313 mysqltuner.pl
524303 fuse-2.9.2.tar.gz 524300 ntfs-3g-1.1120.tgz
1048577 zandu 524369 prakashkernel
524302 index.html 524307 reboot
524358 index.html.1 524311 remi-release-6.rpm
524290 install.log 524360 rpmbuild
524291 install.log.syslog 524315 server-load
25) Display UID(User ID)and GID (Group ID)of Files
To display UID and GID of files and directories. use option -n with ls command.# ls -n
-rw-r--r--. 1 0 0 83158 Aug 14 2010 iRedMail-0.6.1.tar.bz2
drwxr-x---. 3 0 0 4096 Apr 9 2013 maldetect-1.4.2
-rw-r--r--. 1 0 0 811438 Apr 9 2013 maldetect-current.tar.gz
-rw-r--r--. 1 0 0 33328 Aug 31 17:50 mirror
-rw-r--r--. 1 0 0 33414 Aug 31 17:52 mirror.1
-rwxr-xr-x. 1 0 0 41847 Apr 4 2013 mysqltuner.pl
-rw-r--r--. 1 0 0 577005 Jan 15 2013 ntfs-3g-1.1120.tgz
drwxr-xr-x. 2 0 0 4096 Sep 4 16:34 prakashkernel
-rw-r--r--. 1 0 0 0 Feb 8 2013 reboot
-rw-r--r--. 1 0 0 5420 Feb 13 2013 remi-release-6.rpm
drwxr-xr-x. 8 0 0 4096 Aug 31 18:09 rpmbuild
-rw-r--r--. 1 0 0 2128 Apr 9 2013 server-load
26) whatis command examples
Whatis command displays a single line description about a command.[root@oracle ~]# whatis rpm
rpm (8) - RPM Package Manager
[root@oracle ~]# whatis ifconfig
ifconfig (8) - configure a network interface
[root@oracle ~]# whatis httpd
httpd (8) - Apache Hypertext Transfer Protocol Server
27) fsck command
Linux fsck utility is used to check and repair Linux filesystems (ext2, ext3, ext4, etc.).
Depending on when was the last time a file system was checked, the system runs the fsck during boot time to check whether the filesystem is in consistent state. System administrator could also run it manually when there is a problem with the filesystems.
Make sure to execute the fsck on an unmounted file systems to avoid any data corruption issues.
This article explains 10 practical examples on how to execute fsck command to troubleshoot and fix any filesystem errors.
Filesystem Check on a Disk Partition
First, view all the available partitions on your system using parted command as shown below
# parted /dev/sda 'print'
Model: ATA Hitachi HDS72102 (scsi)
Disk /dev/sda: 250GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
1 1049kB 211MB 210MB primary ext4 boot
2 211MB 105GB 105GB primary ext4
3 105GB 157GB 52.4GB primary ext4
4 157GB 250GB 92.6GB extended
6 467GB 486GB 18.3GB logical ext2
7 210GB 215GB 5243MB logical linux-swap(v1)
8 215GB 220GB 5243MB logical ext4
9 220GB 226GB 5243MB logical linux-swap(v1)
5 230GB 250GB 20.2GB logical lvm
You can check a specific filesystem (for example: /dev/sda6) as shown below.
# fsck /dev/sda6
fsck from util-linux 2.20.1
e2fsck 1.42 (29-Nov-2011)
/dev/sda6: clean, 95/2240224 files, 3793506/4476416 blocks
OR
# fsck.ext4 /dev/sda5
# cd /sbin
# ls fsck*
# fsck /dev/sda6 -f for forcefully
How to Force fsck on next boot using shutdown command ?
# shutdown -rF now
or
# touch /forcefsck and reboot
28) dmidecode Display Hardware Details In BIOS
Example: 1 Getting HW information about BIOS
[root@pserver ~]# dmidecode -t bios
# dmidecode 2.9
SMBIOS 2.31 present.
Handle 0×0000, DMI type 0, 20 bytes
BIOS Information
Vendor: Phoenix Technologies LTD
Version: 6.00
Release Date: 04/10/2007
Address: 0xE7A00
Runtime Size: 99840 bytes
ROM Size: 64 kB
Characteristics:
ISA is supported
PCI is supported
PC Card (PCMCIA) is supported
PNP is supported
APM is supported
BIOS is upgradeable
BIOS shadowing is allowed
ESCD support is available
USB legacy is supported
Smart battery is supported
BIOS boot specification is supported
[root@pserver ~]#
Similar way you find the hw information like system,baseboard, chassis,processor, memory, cache, connector, slot.
# dmidecode -t system
# dmidecode -t baseboard
# dmidecode -t chassis
# dmidecode -t memory
# dmidecode -t cashe
# dmidecode -t processor
# dmidecode -t connector
# dmidecode -t slot
29) umask establishes the file-creation permissions mask. Usage is umask xyz
30) patch updates source code. Attempts to update a file from a file of change information, or pathces, created by diff
31) lsmod used (by root) to show kernel modules currently loaded
32) lspnp utility to display information about pnp devices. Part of the pcmcia or kernel-pcmcia package, depending on the distribution.
33) awk searches for and process patterns in a file
34) nice & renice [root@prakash ~]# nice --help
With the help of Nice command in Linux you can set process priority. If you give a process a higher priority, then Kernel will allocate more cpu time to that process in Linux you can set process priority. If you give a process a higher priority, then Kernel will allocate more cpu time to that process.Process priority values range from -20 to 19.
A process with the nice value of -20 is considered to be on top of the priority. And a process with nice value of 19 is considered to be low on the priority list.
35) route -n show routing table. The n option returns numerical addresses rather than names.
Did I miss any frequently used Linux commands? Leave a comment and let me know.