Linux Commands - Complete Guide

Linux Commands

If you are a beginner in Linux you might have started using the command line. Once familiarized it is fairly easy to work from the terminal and that why most Linux sysadmins prefer over the GUI.

This tutorial we did best efforts to add most frequently used and important Linux commands you should know and remember.

System related Linux commands

These commands are used to view and manage Linux system-related information.

1. uname

Uname command is used in Linux to find operating systems information. Uname had many options that can provide kernel name, kernel version, CPU type and hostname.

The following uname command with a option displays all information about the operating system.

$sudo uname -a
Linux linode02 5.1.17-x86_64-linode128 #1 SMP PREEMPT Wed Jul 10 17:11:49 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

2. uptime

Information about how long the Linux system has been running is provided using uptime command. System uptime information is gathered from '/proc/uptime' file. This command will also display the system load average.

From the following command we can understand that the system is up and running for the last 13 mins.

$ uptime
23:41:37 up 13 min,  1 user,  load average: 0.03, 0.07, 0.04

3. hostname

You can display your machine hostname by typing hostname in your terminal. With -i option you can view the ip address of the machine and with -d you can view the domain name.

4. last

Linux's last command is used to see who is the last logged in user into your server. Last command displays a list of all user logged in (and out) from '/var/log/wtmp' since the file was created.

You just need to type 'last' on your terminal. Here’s is an example

$ last
leni pts/0 10.0.76.162 Mon Dec 2 12:32 - 13:25 (00:53)
linoxide tty1 Mon Dec 2 09:31 still logged in
reboot system boot 2.6.32-358.23.2 Mon Dec 2 09:20 - 13:25 (04:05)

5. date

In Linux, date command is used to check the current date and time of the system. This command allows you to set custom formats for dates.

As an example, by using 'date +%D' you can view the date in 'MM/DD/YY' format.

$ date +%D
02/07/20

6. cal

By default, cal command display the calendar of the current month. With -y option you can view the calendar of the whole year.

7. w

By default, w command displays who is currently logged in into your machine and what they are doing.

$ w
 01:36:19 up  2:08,  2 users,  load average: 0.00, 0.00, 0.00
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/0    39.177.9.194     23:29    3.00s  0.02s  0.00s w
linoxide pts/1    59.177.9.193     01:35   11.00s  0.00s  0.00s -bash

8. whoami

Whoami command prints the user name of the currently logged in user. It is similar to id -un command.

9. reboot

To immediately reboot a linux system you can run this command from terminal with root privilege.

10. shutdown

Shutdown command is used to halt or reboot a Linux system. This command has options to schedule shutdown and notify users with custom messages.

By default, the machine will go down in 1 minute and you can cancel the schedule by issuing shutdown -c

$sudo shutdown
Shutdown scheduled for Fri 2020-02-07 02:47:52 UTC, use 'shutdown -c' to cancel.
$

The system can be shut down immediately by providing 'now' option.

$ sudo shutdown -h now

Hardware Related Linux Commands

These commands are used to view and manage hardware-related aspects of the Linux machine.

11. dmesg

Dmesg command prints its data by reading the kernel ring buffer. The data can be information about the processor, hard disk, printer, keyboard, memory and drivers.

$ dmesg

Sample output :

[ 0.000000] Initializing cgroup subsys cpuset
[ 0.000000] Initializing cgroup subsys cpu
[ 0.000000] Linux version 3.8.0-31-generic (buildd@aatxe) (gcc version 4.7.3 (Ubuntu/Linaro 4.7.3-1ubuntu1) ) #46-Ubuntu SMP Tue Sep 10 19:56:49 UTC 2013 (Ubuntu 3.8.0-31.46-generic 3.8.13.8)
[ 0.000000] KERNEL supported cpus:
[ 0.000000] Intel GenuineIntel
[ 0.000000] AMD AuthenticAMD
[ 0.000000] NSC Geode by NSC
[ 0.000000] Cyrix CyrixInstead
[ 0.000000] Centaur CentaurHauls
[ 0.000000] Transmeta GenuineTMx86
[ 0.000000] Transmeta TransmetaCPU
[ 0.000000] UMC UMC UMC UMC

12. lshw

Displays information on the hardware configuration of the system. Lshw command must be run as root or sudo privileged user otherwise it will only report partial information.

13. lsblk

Displays block device-related information of the machine. Lsblk command with -a you can view all block devices.

Output

$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 24.5G 0 disk /
sdb 8:16 0 512M 0 disk [SWAP]

14. free

Free command is used in Linux to check the amount of free RAM memory in the system. The free command also shows swap space, buffer and cache space.

$ free
              total        used        free      shared  buff/cache   available
Mem:        4022216      723872     1359820      157988     1938524     2661636
Swap:        524284      247820      276464

15. lspci

Lspci is a standard Linux utility that shows what your system's hardware has got internally. You can expect your results to have information about PCI buses, AGP and onboard components like USB chipset etc.

16. lsusb

Lsusb command is used to display information about USB buses in the system and the devices connected to them You can find lsusb utility in usbutils package.

17. dmidecode

Dmidecode command reads the system DMI (Desktop Management Interface) table to display hardware and BIOS information of the server. The output of the dmidecode contains several records from the DMI table. This table contains a description of the systems hardware components and also other useful information such as serial number, BIOS revision, etc

You need root or sudo privilege to run this command. The following examples show the bios details.

# dmidecode -t bios
# dmidecode 3.2
Getting SMBIOS data from sysfs.
SMBIOS 2.8 present.

Handle 0x0000, DMI type 0, 24 bytes
BIOS Information
        Vendor: SeaBIOS
        Version: rel-1.12.0-0-ga698c8995f-prebuilt.qemu.org
        Release Date: 04/01/2014
        Address: 0xE8000
        Runtime Size: 96 kB
        ROM Size: 64 kB
        Characteristics:
                BIOS characteristics not supported
                Targeted content distribution is supported
        BIOS Revision: 0.0

18. hdparm

Hdparm is a command used in Linux print hard disk information. It can perform disk speed performance and change DMA settings.

The following command will perform a read speed test on disk sda:

# hdparm -tT /dev/sda

/dev/sda:
 Timing cached reads:   18012 MB in  2.00 seconds = 9023.48 MB/sec
 Timing buffered disk reads: 7146 MB in  3.00 seconds = 2380.77 MB/sec

Statistics Related Linux Commands

These set of commands are used to view various kinds of stats of the Linux system.

19. mpstat

Mpstat command is used to print processor statistics and helps to monitor CPU utilization on your system. It will be more useful if your system has multiple processors.

$ mpstat -P 0
Linux 3.2.0-57-generic (USERNB01) 12/12/2013 _x86_64_ (2 CPU)
03:54:00 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle
03:54:00 PM 0 3.82 0.01 1.16 3.88 0.00 0.06 0.00 0.00 91.06

20. vmstat

Vmstat is a tool that provides reporting virtual memory statistics. It covers the system’s memory, swap and processors utilization in real-time.

By default vmstat print as follows:

$ vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 2  0   8704 531516   7088 161204    0    1   585    11   20   34  0  0 100  0  0

21. iostat

Iostat command is a command used to monitor the system's input/output (I/O) device load by observing the time the devices are active in relation to their average transfer rates.

22. tcpdump

Tcpdump is a network troubleshooting command which is also known as a packet sniffer is used to capture and display packets from a network. To run tcpdump command you require root or user with sudo privileges.

When you use tcpdump without any option, it will analyze the traffic on all the interfaces.

23. lsof

Lsof command stands for 'List Open Files'. It is extremely useful to find out the details about files that have been opened and their respective processes.

In order to see the list of files opened by some particular user, use -u option along with lsof commad.

$ lsof -u linoxide
COMMAND  PID     USER   FD   TYPE             DEVICE SIZE/OFF   NODE NAME
bash    6371 linoxide  cwd    DIR                8,0     4096 128025 /home/linoxide
bash    6371 linoxide  rtd    DIR                8,0     4096      2 /
bash    6371 linoxide  txt    REG                8,0  1219272   6329 /usr/bin/bash
bash    6371 linoxide  mem    REG                8,0  2586242   5503 /usr/lib/locale/en_US.utf8/LC_COLLATE
bash    6371 linoxide  mem    REG                8,0  8406312  34008 /var/lib/sss/mc/passwd
bash    6371 linoxide  mem    REG                8,0    42104  19992 /usr/lib64/libnss_sss.so.2
bash    6371 linoxide  mem    REG                8,0  3201344   5604 /usr/lib64/libc-2.28.so
bash    6371 linoxide  mem    REG                8,0    28784   5606 /usr/lib64/libdl-2.28.so
bash    6371 linoxide  mem    REG                8,0   208616   5252 /usr/lib64/libtinfo.so.6.1

24. watch

Linux watch command can be used to repeat a command at regular intervals.

User Related Linux Commands

These commands are used to manage Linux users.

25. id

ID command is used in Linux to print real and effective User ID (UID) and Group ID (GID). An UID is a single identity for a user. While Group ID (GID) can consist of more than one UID.

26. last

Linux last command is used to check previously logged in user into your server.

27. who

Who command is a tool print information about users who are currently logged in. who command only see a real user who logged in. It won’t see a user that doing su command (switch user).

28. groupadd

Groupadd command is used to create a group in Linux.

The following command will add a group 'developers' to the system.

# groupadd developers

29. useradd

In Linux and Unix-like operating systems, the most common command to create users is 'useradd' or 'adduser'.

Let's check how to create a new user 'bill' and set a password. The command adds an entry to the /etc/passwd, /etc/shadow, /etc/group and /etc/gshadow files.

# useradd bill
# passwd bill

30. userdel

Userdel is a low-level utility for removing users. Userdel command will look for the system account files such as '/etc/password' and '/etc/group' and then it will delete all entries related to the user name from there.

31. usermod

Linux usermod command is used to modify or change an existing user’s attributes. User's attributes are home directory, shell, password expiration date, groups, UID etc.

32. passwd

Passwd is the command used in Linux (Redhat, Centos, Ubuntu, Debian, Fedora) and UNIX-like operating systems to change passwords.

File Related Linux Commands

These commands are used to handle files and directories.

33. ls

A very simple yet powerful command used for listing files and directories. By default, ls command will list the content of the current directory.

34. pwd

Linux pwd is a command to print the name of the current working directory. When we are 'lost' into a deep directory, we can always reveal where we are.

Check the example below:

[linoxide@li53-41 fsfreeze-hook.d]$ pwd
/usr/share/qemu-kvm/qemu-ga/fsfreeze-hook.d

35. mkdir

On Linux, we can use mkdir command to create a directory.

By default, running mkdir without any option, it will create a directory under the current directory.

$ mkdir account
$ ls -l
total 4
drwxrwxr-x. 2 linoxide linoxide 4096 Feb  8 08:04 account
$

36. cat

We use cat command mainly to view contents, concatenate and redirect the output of files. The easiest way to use cat is just type ‘cat file_name’.

The following examples of cat command will display Linux distribution name and which version is currently installed on the hardware.

$sudo cat /etc/redhat-release
CentOS Linux release 8.0.1905 (Core)

37. rm

When a file no longer needed, we may delete it to save storage space. On the Linux system, we can use rm command to do it.

38. cp

Cp command is used in Linux to create copy of files and directories.

The following command will copy the file 'myfile.txt' from current directory to '/home/linoxide/office'.

$ cp myfile.txt /home/linoxide/office

39. mv

When you want to move files from one place to another and you don’t want to duplicate it, we use mv command.

40.cd

Cd command is used to change the current working directory of a user in Linux and other Unix-like operating systems.

41. ln

Symbolic link or soft link is a special type of file that contains a reference, which points to another file or directory. ln command is used to create symbolic links.

Ln command uses the following syntax:

ln -s [target directory or file] [symlink shortcut]

42. touch

Touch command is used in Linux to change for file access and modification time. We may use touch command in Linux to create an empty file.

43. more

More command is a command for displaying a long text file per page at a time.

44. head

The head command is used to print the first few lines of a text file. By default, the head command prints the first 10 lines of each file to standard output, which is the display screen.

45. tail

As you may know, cat command is used in displaying the entire content of a file via standard input. But in some cases, we have to print part of the file. By default, the tail command displays the last ten lines.

46. gpg

GPG is a tool used in linux for secure communication. It uses a combination of two keys (symmetric-key and public-key cryptography) for encrypting files.

47. cksum

Cksum command is used in Linux print CRC checksum and the number of bytes that are there in that file.

48. diff

Diff command is used to compare two files line by line from the terminal.

49. sort 

Sort command is used in Linux to sort the contents of a text file line by line.

50. uniq

Uniq is a command line tool used to report and filter duplicate lines from a file.

51. wc

Linux wc command counts the number of bytes, characters, words, and lines in a file or in standard input.

52. dir

Dir command is used to lists the content of a directory.

53. tee

Linux tee command is used for chaining and redirection of tasks, you can redirect the output and/or errors to a file and it will not be shown on the terminal.

54. tr

The tr (translate) command is used in Linux mainly for translating and deleting characters. It can be used to convert uppercase to lowercase, squeeze repeating characters and deleting characters.

Process Related Linux Commands

These commands are used to handle Linux processes

55. ps

Linux ps command is a built-in tool to capture current processes on the system. It will capture the system condition at a single time.

56. pmap

The Linux pmap command displays the memory usage map of a process or multiple processes. Pmap reports information about the address space or memory usage map of a process.

57. top

The top command in Linux displays the running processes on the system. It is used extensively for monitoring the load on a server.

58. kill

The kill command is used on Linux and other Unix-like operating systems to terminate processes without having to log out or reboot the computer.

59. killall

The killall command can be used to send a signal to a particular process by using its name. It means if you have five versions of the same program running, the killall command will kill all five.

60. pkill

Similar to killall command, pkill send signal to terminate a process with its name. From Centos 7, it encourages to use pkill.

61. fg and bg

We can run the jobs in background without any intervention from user. The processes that have been stopped by some interrupt signal can be continued in background with bg command. The fg command is like bg command except that instead of sending a command in the background, it runs them in foreground and occupies the current terminal and waits for process to exit.

File Permission Related Linux Commands

These commands are used to change permissions of the files

62. chmod

The file permissions are applied on three levels: the owner, group members and others. The chmod command is used to change these permissions.

For following example, 755 will set read+write+execute permission to the user, set read+execute permission to the group and set read+execute permission to others for the file 'asciiquarium.tar.gz'.

# chmod 755 asciiquarium.tar.gz

63. chown

The chown command in Linux is used to change the ownership and group ownership of files and directories.

In the following examples the owership of the file '/corpora/stopwords/danish.txt' is change from 'root:root' to 'raghu:altair'.

# ls -l /corpora/stopwords/danish.txt
-rw-r--r-- 1 root root 424 Dec 10 2012 /corpora/stopwords/danish.txt

# chown raghu:altair /corpora/stopwords/danish.txt

# ls -l corpora/stopwords/danish
-rw-r--r-- 1 raghu altair 424 Dec 10 2012 /corpora/stopwords/danish.txt

64. chgrp

Chgrp command is used to changes the group ownership of a file unlike chown command that allows you to change the user and group ownership.

Network Related Linux Commands

These commands are used to view and edit network configurations related aspects of the system

65. ifconfig

The ifconfig command is used to display and set ip address to network interfaces in Linux. Now ifconfig is deprecated in favor of iproute2 (the ip command).

66. ip

The linux ip command is similar to ifconfig, but more powerful and is intended to be a replacement for it. With ip you have the advantage of performing several network administration tasks with only one command.

67. ethtool

The ethtool command is used to display/change Ethernet adapter settings. You can change network card speed, auto-negotiation, wake on LAN setting, duplex mode using this tool in Linux.

68. mii-tool

Both mii-tool and ethernet tool allows Linux system administrators to modify or change or check the network interface card.

69. ping and ping6

Ping and ping 6 commands are used to sends echo requests to the host to test ipv4 and ipv6 connection.

70. whois

In Linux whois command is used to gets information for a domain such as owner of the domain, the owner's contact information, and nameservers.

71. dig

Dig performs DNS lookups and displays the answers that are returned from the name server(s) that were queried.

72. host

Host command is a simple utility for performing DNS lookups in Linux. With this command, we can translate names into IP Addresses and vice versa.

73. wget

Wget is the command line, noninteractive, free utility in Unix like Operating systems not excluding Microsoft Windows, for downloading files from the internet.

74. netstat

Netstat is a command-line tool that is used to view and monitor network statistics and configurations of a system. This tool is available on both Unix, Linux and Windows NT-based operating systems

75. nslookup

Nslookup is a network administration tool for querying the Domain Name System to obtain domain name or IP address from DNS record.

Compression/Archive Related Commands

These commands are used to compress and decompress files.

76. tar

Tar is a command line tool used to create and manipulate archive files in Linux and Unix systems. Tar command creates .tar archive file and then compress using gzip or bzip2.

77. gzip

Gzip command compresses files into a single file and suffix '.gz'.

Package Installation Related Commands

These commands are used to manage Linux packages.

78. rpm

RPM (Redhat Package Manager) is a command line package management utility used for installing, uninstalling, updating, querying and verifying software packages.

79. make

Make command is used to build executable programs and libraries from source code.

80. yum

Yum (Yellowdog Updater Modified) is a utility provided in RHEL based systems to install, remove and search packages. Yum installs the package dependencies automatically, for example, yum install httpd will install 'apache' server and it's required dependencies automatically.

81. Apt

Apt is a command line tool for installing, updating, removing deb packages on Ubuntu, Debian, and related Linux distributions.

Search Related Linux Commands

These commands are used to search for files and patterns

82. grep

The grep command allows searching for a text or string in a file or from output console of a command, for a term or pattern matching regular expressions.

83. locate

The locate is a command line utility for searching files and directories in the entire filesystem.

84. find

The Linux find command is a very powerful command which is basically used for searching files under a directory structure using certain criteria.

85. ssh

SSH is used for logging into a remote machine and for executing commands on a remote machine. Whenever data is sent by a computer to the network, ssh will automatically encrypt.

86. telnet

Telnet is a command-line tool used to connect remote host manly to test application ports connectivity.

File Transfer Related Linux Commands

These commands are used to copy files from one system to another system
87. scp

SCP is a secure copy program to transfer files or directories between Linux hosts on the network. SCP uses ssh protocol to transfer the data.

Here, a local file 'examples.txt' is copied to a remote host.

$ scp examples.txt user@192.168.1.10:/home/user/account

88. rsync

Rsync synchronizes files and directories between local machines to the remote machine. It can recursively copy files and directory, copy symlinks, preserve (permissions, group, modification time and ownership) file identity.

Disk Use Related Linux Commands

These commands are used to view disk statistics.

89. df

The df command displays the disk space usage for the Linux filesystems. It displays the amount of total and free disk space available on the mounted file systems.

90. fdisk

Fdisk command is used in Linux to view the existing partitions, create a new partition, delete or change existing partitions.

91. du

The du (disk usage) is the command used in Linux to check the directory size including its other contents as well as the size of individual files.

92. findmnt

The command findmnt is used to list mounted filesystems in Linux. This command will look for a particular filesystem in /etc/fstab, /etc/mtab or /proc/self/mountinfo.

93. mount

Mount is a command used in Linux to attached filesystems and drives and umount command is used to detach (unmount) any attached file systems or devices.

Conclusion

In this tutorial, we learned an overview of all most all Linux commands.  For a final word, you can always rely on Linux man pages for more information. I hope this tutorial was helpful and please provide your suggestions in the below comment section.

Nishali Wijesinghe 2:54 am

Comments

Your email address will not be published. Required fields are marked *

All comments are subject to moderation.

7 Comments

  1. Symbolic Links:-
    In this list of 106 which is correct ?
    48. ln -s /path/to/file-name link-name : Creates a symbolic link to file-name
    or
    57. ln -s link file : Create a soft link named link to the file
    Slightly baffled,
    Jeremy

    1. Hi Arup,

      It's a very fair question. In the mentioned article we focus on a Linux command cheat sheet for download or print out.

  2. can u please share detail linux documentation with us so that we can learn linux in detail with all server configuration like http server,apache,ftp...etc