Some Useful Linux Commands
In this article we are going to review some of the useful and frequently used Linux or Unix commands for Linux System Administrators that are used in their daily life. This is not a complete but it’s a compact list of commands to refer when needed. Let us start one by one how we can use those commands.
Uptime
This command tells you how long your system has been running for and system load averages.
# uptime
08:59:01 up 28 min, 1 user, load average: 0.00, 0.01, 0.05
Users
This command will show the names of users currently logged in to current host.
# users
centos root dennis steve
Sudo
This commands allows a permitted user to execute a command as the superuser or another user, as specified in the sudoers file(/etc/sudoers).
# visudo
## Allow root to run any commands anywhere root ALL=(ALL) ALL dennis ALL=(ALL) ALL
Now you are able to use commands with privileges and you have the root rights.
cmp
This command compare two files byte by byte and will display difference.
# cmp file1.txt file2.txt
file1.txt file2.txt differ: byte 1, line 1
lsusb
This command will list the usb devices. If lsusb command is missing then install it using following command.
# yum install usbutils # lsusb
Bus 001 Device 002: ID 0951:16a3 Sandisk
lsmod
This command is a trivial program which nicely formats the contents of the /proc/modules, showing what kernel modules are currently loaded.
# lsmod
Module Size Used by isofs 39844 0 intel_rapl 18773 0 crc32_pclmul 13113 0 ghash_clmulni_intel 13259 0 aesni_intel 69884 0 lrw 13286 1 aesni_intel gf128mul 14951 1 lrw glue_helper 13990 1 aesni_intel ablk_helper 13597 1 aesni_intel cryptd 20359 3 ghash_clmulni_intel,aesni_intel,ablk_helper cirrus 24694 1 syscopyarea 12529 1 cirrus sysfillrect 12701 1 cirrus sysimgblt 12640 1 cirrus ppdev 17671 0 ttm 93441 1 cirrus snd_pcm 105835 0 drm_kms_helper 125008 1 cirrus snd_timer 29639 1 snd_pcm snd 83425 2 snd_timer,snd_pcm soundcore 15047 1 snd pcspkr 12718 0 drm 349210 4 ttm,drm_kms_helper,cirrus i2c_piix4 22106 0 i2c_core 40582 3 drm,i2c_piix4,drm_kms_helper parport_pc 28165 0 parport 42348 2 ppdev,parport_pc nfsd 302418 1 auth_rpcgss 59343 1 nfsd nfs_acl 12837 1 nfsd lockd 93600 1 nfsd grace 13295 2 nfsd,lockd ip_tables 27240 0 xfs 939662 1 libcrc32c 12644 1 xfs ata_generic 12910 0 pata_acpi 13038 0 ata_piix 35038 0 crct10dif_pclmul 14289 0 crct10dif_common 12595 1 crct10dif_pclmul xen_netfront 26720 0 xen_blkfront 26971 2 crc32c_intel 22079 1 libata 218730 3 pata_acpi,ata_generic,ata_piix serio_raw 13462 0 floppy 69417 0 sunrpc 300464 7 nfsd,auth_rpcgss,lockd,nfs_acl
lsblk
This command will lists the information about all available or specified block devices gather information from filesystem. The command prints all block devices (except RAM disks) in a tree-like format by default.
# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT xvda 202:0 0 30G 0 disk └─xvda1 202:1 0 30G 0 part /
Enable an Interface
You can enable system’s interface up by defining the name of the interface with ifconfig command.
Syntax: ifconfig interface-name up
ifconfig eth0 up
Disable an Interface
You can also disable the interface card.
Syntax: ifconfig interface-name up
ifconfig eth0 down
dd
This command will copy a file, converts and formats data according to the operands. In this command its creatig 10 MB file through if= input file and of=output file.
# dd if=/dev/zero of=/root/output.txt bs=1024 count=10240
10240+0 records in 10240+0 records out 10485760 bytes (10 MB) copied, 0.0131311 s, 799 MB/s
bc
This command is basically to calculate two variables in a CLI mode its work just like a calculator.
# bc
bc 1.06.95 Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc. This is free software with ABSOLUTELY NO WARRANTY. For details type `warranty'. 10+12 22 25*35 875 25/5 5
Last reboot
This command will show the last reboot times or system reboots history.
# last reboot
reboot system boot 3.10.0-327.13.1. Mon May 9 08:30 - 09:15 (00:44) reboot system boot 3.10.0-327.10.1. Mon May 9 08:26 - 08:29 (00:03) wtmp begins Mon May 9 08:26:03 2016
Watch
watch runs command repeatedly, displaying its output and errors (the first screenfull). This allows you to watch the program output change over time. By default, the program is run every 2 seconds.
# watch -n 1 'ls -l; echo; du'
Every 1.0s: ls -l; echo; du Mon May 9 09:17:08 2016 total 10244 -rw-r--r--. 1 root root 18 May 9 08:38 logout -rw-r--r--. 1 root root 10485760 May 9 09:11 output.txt 4 ./.ssh 0 ./.pki/nssdb 0 ./.pki 10276 .
Enjoy it!