#Introduction
In this tutorial, The ultimate Linux commands cheat sheet. On Linux operating system and other UNIX-like operating systems.
System Information
Linux Commands for System Information. You want to query information about your system.
Commands | Description | For example |
whoami | Output the current user using the Linux system | [vagrant@localhost ~]$ whoami vagrant |
w | who or which systems are online especially | [vagrant@localhost ~]$ w 20:29:06 up 3 min, 1 user, load average: 0.00, 0.00, 0.00 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT vagrant pts/0 10.0.2.2 20:27 2.00s 0.01s 0.00s w |
cal | Outputs the present month’s calendar. | [vagrant@localhost ~]$ cal September 2021 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
date | Displaying the current date and time. | [vagrant@localhost ~]$ date Tue Sep 21 20:30:00 +07 2021 |
last reboot | A useful command of how many times your system restarted. | [vagrant@localhost ~]$ last reboot reboot system boot 3.10.0-1127.el7. Tue Sep 21 20:25 – 20:30 (00:04) reboot system boot 3.10.0-1127.el7. Tue Sep 21 14:42 – 17:26 (02:44) reboot system boot 3.10.0-1127.el7. Sat Sep 18 20:56 – 22:00 (01:03) reboot system boot 3.10.0-1127.el7. Sat Sep 18 14:37 – 22:00 (07:22) wtmp begins Sat Sep 18 14:37:54 2021 |
hostname -I | Outputs the assigned IP address your system is currently | [vagrant@localhost ~]$ hostname -I 10.0.2.15 192.168.3.4 172.17.0.1 |
hostname | Outputs your system’s hostname | [vagrant@localhost ~]$ hostname localhost.localdomain |
uptime | Outputs how long your Linux system has been active | [vagrant@localhost ~]$ uptime 20:31:27 up 5 min, 1 user, load average: 0.00, 0.00, 0.00 |
lsb_release -a | You can obtain information specific to your Linux distribution. This command displays its Distributor ID, Description, Release, and Codename. | vagrant@vagrant:~$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 21.04 Release: 21.04 Codename: hirsute |
uname -r | Outputs the kernel release information | [vagrant@localhost ~]$ uname -r 3.10.0-1127.el7.x86_64 |
uname -a | Displays basic system information like machine name, etc. | [vagrant@localhost ~]$ uname -a Linux localhost.localdomain 3.10.0-1127.el7.x86_64 #1 SMP Tue Mar 31 23:36:51 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux |
File Permissions
Linux Commands for File Permissions. File permissions in Linux relate to Read (r), Write (w), and Execute (x) privileges.
Commands | Description | For example |
ls -l | Outputs the file type and the file permissions | [root@localhost vagrant]# ls -l total 0 -rw-rw-r–. 1 vagrant vagrant 0 Sep 21 20:34 devopsroles.com drwxr-xr-x. 2 vagrant vagrant 6 Sep 13 20:12 share |
chown user:group file_name | Change The user and group privileges | [root@localhost vagrant]# chown huupv:root devopsroles.com [root@localhost vagrant]# ls -l devopsroles.com -rw-rw-r–. 1 huupv root 0 Sep 21 20:34 devopsroles.com |
chmod 777 file_name | Everyone access the file | [root@localhost vagrant]# chmod 777 devopsroles.com [root@localhost vagrant]# ls -l devopsroles.com -rwxrwxrwx. 1 huupv root 0 Sep 21 20:34 devopsroles.com |
chmod 755 file_name | The owner of the file: Read, Write, Execute other users and Group will only have read and executed permissions. | [root@localhost vagrant]# chmod 755 devopsroles.com [root@localhost vagrant]# ls -l devopsroles.com -rwxr-xr-x. 1 huupv root 0 Sep 21 20:34 devopsroles.com |
chmod 766 file_name | The owner of the file: Read, Write, Execute other users and Group will only have Read and Write permissions. | [root@localhost vagrant]# chmod 766 devopsroles.com [root@localhost vagrant]# ls -l devopsroles.com -rwxrw-rw-. 1 huupv root 0 Sep 21 20:34 devopsroles.com |
touch -a -t | Useful in creating or modifying a file timestamp. -a = accessed -m = modified -t = timestamp – use [[CC]YY]MMDDhhmm[.ss] time format | [root@localhost vagrant]# touch -a -t 201902090123.30 devopsroles.com [root@localhost vagrant]# stat devopsroles.com File: ‘devopsroles.com’ Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: 801h/2049d Inode: 5323348 Links: 1 Access: (0766/-rwxrw-rw-) Uid: ( 1001/ huupv) Gid: ( 0/ root) Context: unconfined_u:object_r:user_home_t:s0 Access: 2019-02-09 01:23:30.000000000 +0700 Modify: 2021-09-21 20:34:35.629225064 +0700 Change: 2021-09-21 20:43:41.338885218 +0700 Birth: – |
chgrp group_name filename | Useful in changing the group permission of a file. | [root@localhost vagrant]# ls -l devopsroles.com -rwxr-xr-x. 1 huupv root 0 Sep 21 20:34 devopsroles.com [root@localhost vagrant]# chgrp vagrant devopsroles.com [root@localhost vagrant]# ls -l devopsroles.com -rwxr-xr-x. 1 huupv vagrant 0 Sep 21 20:34 devopsroles.com |
chmod -c -R | Assign a file the read, write, and execute permissions. | [root@localhost vagrant]# ls -l devopsroles.com -rwxr-xr-x. 1 huupv vagrant 0 Sep 21 20:34 devopsroles.com [root@localhost vagrant]# chmod -c -R 777 devopsroles.com mode of ‘devopsroles.com’ changed from 0755 (rwxr-xr-x) to 0777 (rwxrwxrwx) [root@localhost vagrant]# ls -l devopsroles.com -rwxrwxrwx. 1 huupv vagrant 0 Sep 21 20:34 devopsroles.com |
Hardware Information
Commands | Description | For example |
cat /proc/cpuinfo | Outputs CPU information of your machine. | [vagrant@localhost ~]$ cat /proc/cpuinfo processor : 0 vendor_id : GenuineIntel cpu family : 6 model : 167 model name : 11th Gen Intel(R) Core(TM) i7-11700 @ 2.50GHz stepping : 1 cpu MHz : 2496.004 cache size : 16384 KB …… |
cat /proc/meminfo | Outputs Memory information | [vagrant@localhost ~]$ cat /proc/meminfo MemTotal: 498684 kB MemFree: 131816 kB MemAvailable: 343212 kB Buffers: 2068 kB Cached: 207228 kB SwapCached: 0 kB Active: 107336 kB ….. |
free -h | Outputs both free and used machine memory info. | [vagrant@localhost ~]$ free -h total used free shared buff/cache available Mem: 486M 134M 128M 4.5M 223M 334M Swap: 2.0G 0B 2.0G |
lshw | Outputs the system’s hardware configuration information. | [vagrant@localhost ~]$ sudo lshw -short H/W path Device Class Description system VirtualBox /0 bus VirtualBox /0/0 memory 128KiB BIOS /0/1 memory 512MiB System memory /0/2 processor 11th Gen Intel(R) Core(TM) i7-11700 @ 2.50GHz /0/100 bridge 440FX – 82441FX PMC [Natoma] /0/100/1 bridge 82371SB PIIX3 ISA [Natoma/Triton II] /0/100/1.1 scsi0 storage 82371AB/EB/MB PIIX4 IDE /0/100/1.1/0.0.0 /dev/sda disk 42GB VBOX HARDDISK /0/100/1.1/0.0.0/1 volume 39GiB Linux filesystem partition /0/100/2 display VirtualBox Graphics Adapter /0/100/3 eth0 network 82540EM Gigabit Ethernet Controller /0/100/4 generic VirtualBox Guest Service /0/100/5 multimedia 82801AA AC’97 Audio Controller /0/100/7 bridge 82371AB/EB/MB PIIX4 ACPI /0/100/8 eth1 network 82540EM Gigabit Ethernet Controller /0/3 input PnP device PNP0303 /0/4 input PnP device PNP0f03 /1 docker0 network Ethernet interface |
lsblk | Outputs the system’s block devices information. | [vagrant@localhost ~]$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 40G 0 disk └─sda1 8:1 0 40G 0 part / |
lspci -tv | Outputs the system’s PCI devices. | [vagrant@localhost ~]$ lspci -tv -[0000:00]-+-00.0 Intel Corporation 440FX – 82441FX PMC [Natoma] +-01.0 Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II] +-01.1 Intel Corporation 82371AB/EB/MB PIIX4 IDE +-02.0 InnoTek Systemberatung GmbH VirtualBox Graphics Adapter +-03.0 Intel Corporation 82540EM Gigabit Ethernet Controller +-04.0 InnoTek Systemberatung GmbH VirtualBox Guest Service +-05.0 Intel Corporation 82801AA AC’97 Audio Controller +-07.0 Intel Corporation 82371AB/EB/MB PIIX4 ACPI -08.0 Intel Corporation 82540EM Gigabit Ethernet Controller |
lsusb -tv | Outputs the system’s USB devices. | |
dmidecode | Outputs the system’s hardware information on DMI/SMBIOS related to the BIOS. | [vagrant@localhost ~]$ sudo dmidecode dmidecode 3.2 Getting SMBIOS data from sysfs. SMBIOS 2.5 present. 10 structures occupying 450 bytes. Table at 0x000E1000. Handle 0x0000, DMI type 0, 20 bytes BIOS Information Vendor: innotek GmbH Version: VirtualBox Release Date: 12/01/2006 Address: 0xE0000 ….. |
dmesg | Outputs the kernel ring buffer messages. | [vagrant@localhost ~]$ dmesg [ 0.000000] Initializing cgroup subsys cpuset [ 0.000000] Initializing cgroup subsys cpu [ 0.000000] Initializing cgroup subsys cpuacct [ 0.000000] Linux version 3.10.0-1127.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) ) #1 SMP Tue Mar 31 23:36:51 UTC 2020 [ 0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-3.10.0-1127.el7.x86_64 root=UUID=1c419d6c-5064-4a2b-953c-05b2c67edb15 ro no_timer_check console=tty0 console=ttyS0,115200n8 net.ifnames=0 biosdevname=0 elevator=noop crashkernel=auto LANG=en_US.UTF-8 [ 0.000000] e820: BIOS-provided physical RAM map: [ 0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable [ 0.000000] BIOS-e820: [mem 0x000000000009fc00-0x000000000009ffff] reserved …. |
lscpu | Outputs information about the CPU and processing units. | [vagrant@localhost ~]$ lscpu Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 1 On-line CPU(s) list: 0 Thread(s) per core: 1 Core(s) per socket: 1 Socket(s): 1 NUMA node(s): 1 Vendor ID: GenuineIntel CPU family: 6 ….. |
lsscsi | Lists out the SCSI/SATA devices like hard drives and optical drives. | [vagrant@localhost ~]$ lsscsi [0:0:0:0] disk ATA VBOX HARDDISK 1.0 /dev/sda |
Networking
Commands | Description | For example |
ping hostname_or_IP | Useful in analyzing the responsiveness of a hostname connected to a network. | [vagrant@localhost ~]$ ping 192.168.3.4 PING 192.168.3.4 (192.168.3.4) 56(84) bytes of data. 64 bytes from 192.168.3.4: icmp_seq=1 ttl=64 time=0.017 ms 64 bytes from 192.168.3.4: icmp_seq=2 ttl=64 time=0.021 ms 64 bytes from 192.168.3.4: icmp_seq=3 ttl=64 time=0.021 ms |
tcpdump | Used to dump network traffic. | [vagrant@localhost ~]$ sudo tcpdump -i eth0 |
netstat -r -v | Prints network routing, information, and connections. | [vagrant@localhost ~]$ netstat -r -v Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface default gateway 0.0.0.0 UG 0 0 0 eth0 10.0.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0 192.168.3.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1 |
ip addr show | Outputs network interfaces and their related IP addresses. | |
ifconfig | Outputs configured network interfaces’ IP addresses. | |
whois domain_name | Reveals more information regarding an active domain name on the internet. | [vagrant@localhost ~]$ whois devopsroles.com Domain Name: DEVOPSROLES.COM Registry Domain ID: 2245154670_DOMAIN_COM-VRSN …… |
dig domain_name | Reveals DNS information and configuration regarding an active domain name. | |
dig -x host | It is applicable when dealing with DNS and will reverse lookup an active domain. | [vagrant@localhost ~]$ dig -x huuphan.com ; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.7 <<>> -x huuphan.com ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 43438 ;; flags: qr rd ra ad; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 512 ;; QUESTION SECTION: ;com.huuphan.in-addr.arpa. IN PTR ;; AUTHORITY SECTION: in-addr.arpa. 3486 IN SOA b.in-addr-servers.arpa. nstld.iana.org. 2021090215 1800 900 604800 3600 ;; Query time: 34 msec ;; SERVER: 10.0.2.3#53(10.0.2.3) ;; WHEN: Wed Sep 22 20:23:37 +07 2021 ;; MSG SIZE rcvd: 121 |
dig -x IP_address | It will reverse lookup an active IP address. | [vagrant@localhost ~]$ dig -x 172.67.137.70 ; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.7 <<>> -x 172.67.137.70 ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 52165 ;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 512 ;; QUESTION SECTION: ;70.137.67.172.in-addr.arpa. IN PTR ;; AUTHORITY SECTION: 67.172.in-addr.arpa. 1800 IN SOA cruz.ns.cloudflare.com. dns.cloudflare.com. 2034580120 10000 2400 604800 3600 ;; Query time: 41 msec ;; SERVER: 10.0.2.3#53(10.0.2.3) ;; WHEN: Wed Sep 22 20:24:27 +07 2021 ;; MSG SIZE rcvd: 117 |
host domain_name | It will lookup the IP address of an active domain | [vagrant@localhost ~]$ host huuphan.com huuphan.com has address 104.21.73.16 huuphan.com has address 172.67.137.70 huuphan.com has IPv6 address 2606:4700:3032::6815:4910 huuphan.com has IPv6 address 2606:4700:3031::ac43:8946 huuphan.com mail is handled by 10 aspmx2.googlemail.com. huuphan.com mail is handled by 1 aspmx.l.google.com. huuphan.com mail is handled by 5 alt1.aspmx.l.google.com. huuphan.com mail is handled by 10 aspmx3.googlemail.com. huuphan.com mail is handled by 5 alt2.aspmx.l.google.com. |
wget file_name | Useful in downloading a file from a specified domain name | wget https://www.huuphan.com/filename.zip |
ifconfig -a | Outputs all the network interface details | |
ifconfig eth0 | Outputs eth0 configuration and address details. | |
ethtool eth0 | Used to manage hardware and network drivers query and control settings | [vagrant@localhost ~]$ ethtool eth0 Settings for eth0: Supported ports: [ TP ] Supported link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Full Supported pause frame use: No Supports auto-negotiation: Yes Supported FEC modes: Not reported Advertised link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Full Advertised pause frame use: No Advertised auto-negotiation: Yes Advertised FEC modes: Not reported Speed: 1000Mb/s Duplex: Full Port: Twisted Pair PHYAD: 0 Transceiver: internal Auto-negotiation: on MDI-X: off (auto) Cannot get wake-on-lan settings: Operation not permitted Current message level: 0x00000007 (7) drv probe link Link detected: yes |
Archives and File Compression
Commands | Description | For example |
tar cvf compressed_file_name.tar file_name # creating tar xvf compressed_file_name.tar file_name # extracting | creating or extracting files with .tar | [vagrant@localhost ~]$ tar cvf share.tar share share/ [vagrant@localhost ~]$ tar xvf share.tar share/ |
tar czf compressed_file_name.tar.gz | compresses a tar file into a gzip archive. | |
tar cjf archive.tar.bz2 folder | compresses a tar file inside a bz2 archive. | [vagrant@localhost ~]$ tar cjf archive.tar.bz2 share [vagrant@localhost ~]$ ll total 20 -rw-rw-r–. 1 vagrant vagrant 150 Sep 23 07:51 archive.tar.bz2 |
tar xjf archive.tar.bz2 | extracts a tar file compressed inside a bz2 archive. | |
gzip, gunzip, zcat file_name | creating, extracting. or viewing files with .gz extension | |
uuencode, uudecode | creating or extracting files with .Z extension. | |
zip, unzip -v | creating or extracting files with .Zip extension. | [vagrant@localhost ~]$ zip -r share.zip share adding: share/ (stored 0%) adding: share/abc.txt (stored 0%) [vagrant@localhost ~]$ ls -l share.zip -rw-rw-r–. 1 vagrant vagrant 316 Sep 23 07:56 share.zip [vagrant@localhost ~]$ unzip -v share.zip Archive: share.zip Length Method Size Cmpr Date Time CRC-32 Name ——– —— ——- —- ———- —– ——– —- 0 Stored 0 0% 09-23-2021 07:50 00000000 share/ 0 Stored 0 0% 09-23-2021 07:50 00000000 share/abc.txt ——– ——- — ——- 0 0 0% 2 files |
bzip2, bunzip2 | creating or extracting files with .bz2 extension. | |
rar | creating or extracting files with .rar extension. |
Installing Packages
Commands | Description | For example |
yum search keyword | Search a package installation based on specific keywords. | [vagrant@localhost ~]$ yum search nginx Loaded plugins: fastestmirror Determining fastest mirrors base: mirror.vietnix.vn epel: mirror.xeonbd.com extras: mirror.vietnix.vn updates: mirror.vietnix.vn =============== N/S matched: nginx ========== collectd-nginx.x86_64 : Nginx plugin for collectd munin-nginx.noarch : NGINX support for Munin resource monitoring nginx-all-modules.noarch : A meta package that installs all available Nginx modules nginx-filesystem.noarch : The basic directory layout for the Nginx serve …… |
yum install package.rpm | The use of a YUM package manager to install and configure a package. | |
yum info package | To find more information about a package before optionally proceeding with its installation. | [vagrant@localhost ~]$ yum info nginx Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile base: mirror.vietnix.vn epel: mirror.xeonbd.com extras: mirror.vietnix.vn updates: mirror.vietnix.vn Available Packages Name : nginx Arch : x86_64 Epoch : 1 Version : 1.20.1 Release : 2.el7 Size : 586 k Repo : epel/x86_64 Summary : A high performance web server and reverse proxy server URL : https://nginx.org License : BSD Description : Nginx is a web server and a reverse proxy server for HTTP, SMTP, POP3 and : IMAP protocols, with a strong focus on high concurrency, performance and low : memory usage. |
rpm -i package.rpm | To install a downloaded RPM package. | |
yum remove package | To uninstall or remove a Yum package from your system. | |
tar zxvf sourcecode.tar.gz cd sourcecode ./configure make make install | Command sequence to install a package software that comes as a source code. | |
dnf install package.rpm | Using the DNF package manager to install package software. | |
apt install package | Using the APT package manager to install package software. | |
rpm -e package.rpm | Using the RPM package manager to remove or uninstall an rpm package |
Search Commands
Commands | Description | For example |
grep pattern file | To search the contents of a file with a pattern | [vagrant@localhost ~]$ grep devopsroles devopsroles.com welocome devopsroles.com |
grep -r pattern directory_name | Recursively or repeatedly searches within a specified directory for a defined pattern match. | |
find /path/to/folder -name match-a | search based on a character match. In this case [ match-a ] | [vagrant@localhost ~]$ find /home/vagrant -name devopsroles.com /home/vagrant/devopsroles.com |
find /path/to/folder -name ‘prefix*’ | Traces a specified system path for files with a matching prefix. | [vagrant@localhost ~]$ find /home/vagrant -name ‘devops*’ /home/vagrant/devopsroles.com |
SSH Logins
Commands | Description | For example |
ssh user_name@hostname | Connects you to a remote machine or server | |
ssh host | Connects you to a specified host through the default port 22. | |
ssh -p port user_name@hostname | Connects you to a remote machine or server through a specified port. | |
telnet hostname | Uses telnet’s default port 23 to connect you to a target hostname, remote machine, or server. |
File Transfers and Management
Commands | Description | For example |
rm -r -f | To remove or delete active files and directories | |
du -s | Give important information regarding the disk usage (storage space) on your Linux system. | [vagrant@localhost ~]$ du -s /home/vagrant 60 /home/vagrant |
file -b -i | Helps identify the type of file on your system. | [vagrant@localhost ~]$ file -b -i .env text/plain; charset=us-ascii |
mv -f -i | Used for moving directories or files to a different system path or location. | |
grep, egrep, fgrep -i -v | Useful in printing lines with a matching pattern. | |
scp file.txt server:/tmp | To copy files to a remote server. | |
scp server:/home/vagrant/*.txt /tmp | to copy files from a remote server to a directory on a local machine. | |
scp -r server:/home/vagrant /tmp | recursively copy all the files and directories on a remote server’s directory to a target machine directory. | |
rsync -a /var/www /backups/ | Synchronizes the content of two directories (/var/www and /backups) on the same machine. | |
rsync -avz /home/vagrant server:/backups/ | synchronizes the content of a folder on a local machine with the content of a folder on a remote server. |
File and Directory Commands
Commands | Description |
ls | list the files and directories under and directory path. |
pwd | print working directory |
mkdir dir_name | create a directory with the specified name. |
rm filename | delete a file with the specified name. |
rm -rf directory_name | recursively and forcefully delete a directory with the specified name. |
cp filename1 filename2 | copy filename1 to filename2 |
cp -r directory1 directory2 | recursively copy the content of directory1 to directory2 |
mv filename1 filename2 | rename filename1 to filename2 |
ln -s /path/to/file_name link_name | To create a symbolic link (link_name) to a specified file name (file_name). |
touch filename | to create a new file |
more filename | open and display the contents of a specified file. |
cat filename | open and display the contents of a specified file. |
cat filename1 >> filename2 | appends or adds the content of filename1 at the bottom of filename2. |
head filename | Outputs the first ten lines of a specified file name. |
tail filename | Outputs the last ten lines of a specified file name. |
gpg -c filename | to encrypt a specified file. |
gpg filename.gpg | to decrypt a specified file with a .gpg extension. |
wc filename | Outputs the number of bytes, lines, and words of a specified file name. |
cd | Takes you to the Home directory |
cd /target/directory | To change directories to a specific directory name. |
Disk Utilities and Usage
Commands | Description | For example |
df -h | Display the amount of free space in the file system | [vagrant@localhost ~]$ df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 237M 0 237M 0% /dev tmpfs 244M 0 244M 0% /dev/shm tmpfs 244M 4.5M 240M 2% /run tmpfs 244M 0 244M 0% /sys/fs/cgroup /dev/sda1 40G 4.2G 36G 11% / tmpfs 49M 0 49M 0% /run/user/1000 |
df -i | Works with mounted systems to reveal their free inodes. | [vagrant@localhost ~]$ df -i Filesystem Inodes IUsed IFree IUse% Mounted on devtmpfs 60456 306 60150 1% /dev tmpfs 62335 1 62334 1% /dev/shm tmpfs 62335 395 61940 1% /run tmpfs 62335 16 62319 1% /sys/fs/cgroup /dev/sda1 20971008 48415 20922593 1% / tmpfs 62335 1 62334 1% /run/user/1000 |
fdisk -l | print partition tables of all devices | [vagrant@localhost ~]$ sudo fdisk -l Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x0009ef1a Device Boot Start End Blocks Id System /dev/sda1 * 2048 83886079 41942016 83 Linux |
du -ah | Outputs files and directories disk usage. | [vagrant@localhost ~]$ du -ah 4.0K ./.bash_logout 4.0K ./.bash_profile 4.0K ./.bashrc 4.0K ./.ssh/authorized_keys 4.0K ./.ssh/known_hosts 8.0K ./.ssh 0 ./share 4.0K ./.env 8.0K ./.bash_history 4.0K ./devopsroles.com 4.0K ./myscript_onLocal.sh 12K ./share.tar 4.0K ./archive.tar.bz2 4.0K ./share.zip 4.0K ./linuxopratingsystem.net 4.0K ./.viminfo 68K . |
findmnt | Outputs the target mount point associated with all your file systems. | |
mount device_path mount_point | to mount a device. | |
mkfs -t -V | to create a new file system. | |
resize2fs | updating a file system, especially after lvextend* | |
fsck -A -N | to check and repair a file system. | |
pvcreate | creating a physical volume. | |
mount -a -t | mounting a file system. | |
lvcreate | creating a logical volume. | |
unmount -f -v | unmounting a mounted file system. |
Environment Variables
Commands | Description | For example |
env | Display all exported environment or run a program in a modified environment | vagrant@devopsroles:~$ env SHELL=/bin/bash PWD=/home/vagrant LOGNAME=vagrant XDG_SESSION_TYPE=tty MOTD_SHOWN=pam HOME=/home/vagrant LANG=en_US.UTF-8 ….. |
variable_name=variable_value | to assign a variable name with a variable value. | vagrant@devopsroles:~$ site=devopsroles.com vagrant@devopsroles:~$ echo $site devopsroles.com |
echo $Variable_name | Outputs the value of a defined variable on the terminal. | vagrant@devopsroles:~$ echo $site devopsroles.com |
export Variable = value | To assign an environment variable a new value. | vagrant@devopsroles:~$ export site=devopsroles.com vagrant@devopsroles:~$ env | grep site site=devopsroles.com |
unset | To remove a variable. | vagrant@devopsroles:~$ unset site vagrant@devopsroles:~$ echo $site |
System Processes Management
Commands | Description | For example |
top | Outputs all active processes details. | |
bg | running process to execute in the background. | |
fg | Sends a stopped or halted process to keep executing on the foreground. | |
ps -ef | Outputs all active or executing processes on the Linux system. | |
ps PID | Outputs a running processes’ status in reference to its process ID. | |
pidof | find the process ID of the running program | |
kill PID | Kills a running process | |
nice | lets you run a command at a priority lower than the command’s normal priority | |
renice | alters the nice value of one or more running processes | |
sensors | Outputs the Linux system’s CPU temperature. | |
ps aux | To monitor processes running on your Linux system | |
dmesg -k | Helps in troubleshooting the health status of your Linux system. | |
program & | Executes a program in the system background. | |
fg n | Moves a running job n to the system’s foreground. |
File Editors
Commands | Description |
vi | the editor is a full-screen editor and has two modes of operation |
nano | the GNU nano editor. |
view | an editor in view or read-only mode. |
emacs | emacs is a screen editor |
sed | launches stream editor |
File Utilities
Commands | Description |
cut | removes or deletes a file’s section. |
diff | Command to compare files line by line. |
head | prints the first lines (10 lines by default) of one or more files or piped data to standard output. |
join | merges the lines of two sorted text files based on the presence of a common field. |
more, less | to view the contents of a file, a single file page view at a time. |
sort | to sort a file, arranging the records in a particular order. |
split | used to split large files into smaller files. |
tr | translating or deleting characters. |
uniq | reports or filters out the repeated lines in a file. |
comm | compare two sorted files line by line and write to standard output |
Performance Monitoring and Statistics
Commands | Description |
tcpdump -i eth1 ‘port 80’ | monitoring traffic through port 80 |
tcpdump -i eth1 | An interface eth1-related command for outputting captured packets. |
watch df -h | A command to output periodic system updates. |
lsof -u user | Outputs a list of all the files opened by a system user. |
iostat 1 | used to get reports and statistics. |
vmstat 1 | Outputs statistical data related to the system’s virtual memory. |
mpstat 1 | Outputs processor-related statistics. |
Conclusion
Linux commands cheat sheet above. I hope will this your helpful. Thank you for reading the DevopsRoles page!