Welcome to our comprehensive guide on various Linux commands.

Whether you’re a beginner dipping your toes into the world of Linux or an experienced user aiming to broaden your knowledge, this guide aims to be an invaluable resource.

Linux, renowned for its robustness and flexibility, powers millions of servers worldwide, and having a solid understanding of its command-line interface is crucial for effective system administration.

This guide is designed to walk you through a wide array of Linux commands, from basic file navigation commands to more advanced commands for system management. We’ll provide explanations and practical examples to help you understand the purpose and functionality of each command.

By the end of this guide, you should be more comfortable with the Linux command-line environment and have a stronger foundation to perform tasks efficiently and effectively.

Basic Linux Commands

Basic Linux commands form the foundation for interacting with a Linux system. They enable users to navigate through the file system, manage files and directories, control processes, and perform various system-related tasks. Commands like ls, cd, mkdir, ps, and chmod are fundamental for day-to-day operations on a Linux environment.

lsLists all files and directories in the current directory
cdChanges the current working directory
pwdPrints the path of the current working directory
catConcatenates and displays the content of files
touchCreates a new empty file
rmRemoves files or directories
cpCopies files or directories
mvMoves or renames files or directories
mkdirCreates a new directory
rmdirRemoves an empty directory
manDisplays the manual page of a command
sudoExecutes a command with superuser (root) privileges
exitCloses the terminal or ends a terminal session
hostnamectlShows or sets system hostname settings
dateDisplays or sets the system date and time
hostnameShows or sets the system’s host name
ifconfigDisplays or configures network interface parameters
wDisplays who is logged on and what they are doing
free -mShows the amount of free and used memory in the system
topDisplays dynamic real-time view of the running tasks in the system
ls -alLists all files (including hidden) in a directory in long format
cd ..Changes the working directory to the parent directory
cat filenameDisplays the content of ‘filename’
cat file1 file2 > file3Concatenates ‘file1’ and ‘file2’ and redirects the output to ‘file3’
tail filenameDisplays the last part of a file ‘filename’
head filenameDisplays the beginning of a file ‘filename’
mv oldfile newfileRenames ‘oldfile’ to ‘newfile’
rm filenameDeletes ‘filename’
mkdir dirnameCreates a directory named ‘dirname’
rm -rf dirnameDeletes a directory named ‘dirname’ and its contents
historyDisplays the command history
shutdown -h nowShuts down the system immediately
rebootReboots the system

Networking Commands

Networking commands in Linux are used for diagnosing, monitoring, and configuring network interfaces and connections. They help users to check the network status, troubleshoot connectivity issues, monitor network traffic, configure network interfaces, and interact with remote servers. Commands like ping, netstat, ifconfig, and ssh are common tools for managing network interactions in a Linux environment.

ifconfigDisplays or configures network interface parameters
ipA versatile tool that can display or manipulate all IP or network devices
netstatDisplays various network-related information such as network connections, routing tables, and interface statistics
ssAnother utility to investigate sockets, similar to netstat
pingSends an ICMP echo request to establish a connection to server addresses
traceroutePrints the route that a packet takes to reach the host
routeDisplays or alters the IP routing table
nslookupQueries internet domain name servers
digA flexible tool for interrogating DNS name servers
hostPerforms DNS lookups
arpDisplays and modifies the IP-to-Physical address translation tables used by Address Resolution Protocol (ARP)
iwconfigConfigures wireless network interfaces
curlA tool to transfer data from or to a server
wgetDownloads files from the web
telnetA user interface to the TELNET protocol
sshSecure Shell is a protocol to securely get access to a remote computer
ip addr showDisplays IP addresses and all the network interfaces
ip addr add dev eth1Adds an IP address to network interface ‘eth1’
netstat -pnltuDisplays listening server sockets along with their PID
whois domainnameLooks up WHOIS information for a domain name
dig domainnameQueries DNS servers for information about ‘domainname’
host domainnamePerforms a DNS lookup for ‘domainname’
dig -x IP-AddressPerforms a reverse DNS lookup on ‘IP-Address’
dig -x domainamePerforms a reverse DNS lookup on ‘domainame’
ping host-ipSends ICMP echo request to ‘host-ip’ to check network connectivity

File Permission Commands

File Permission commands in Linux are used to control who can read, write, and execute files and directories. They are essential for maintaining system security, ensuring only authorized users have access to certain files. Commands like chmod and chown allow users to modify the permissions and ownership of files and directories.

ls -l filenameDisplays detailed information about ‘filename’, including file permissions
chmod 777 filenameChanges the permissions of ‘filename’ to be fully open (read, write, and execute permissions for everyone)
chmod -R 777 dirnameChanges the permissions of ‘dirname’ and all its contents to be fully open (read, write, and execute permissions for everyone)
chmod 766 filenameChanges the permissions of ‘filename’ to allow the owner to read, write, and execute, while everyone else can only read and write
chmod -x filenameRemoves the execute permission from ‘filename’ for all users
chown username filenameChanges the ownership of ‘filename’ to ‘username’
chown user:group filenameChanges the ownership of ‘filename’ to ‘user’ and the group ownership to ‘group’
chown -R user:group dirnameRecursively changes the ownership of ‘dirname’ and all its contents to ‘user’ and the group ownership to ‘group’

User and Group Management Commands

User and Group Management commands in Linux are utilized for the creation, deletion, and modification of user accounts and groups. They enable system administrators to manage access rights, assign users to specific groups, change user passwords, and adjust other user and group settings. This set of commands is crucial for maintaining system security and managing access to resources.

useradd usernameAdds a new user ‘username’ to the system
userdel usernameDeletes the user ‘username’ from the system
usermod options usernameModifies the settings of user ‘username’
passwd usernameChanges the password of user ‘username’
groupadd groupnameAdds a new group ‘groupname’ to the system
groupdel groupnameDeletes the group ‘groupname’ from the system
groupmod options groupnameModifies the settings of group ‘groupname’
usermod -aG groupname usernameAdds user ‘username’ to group ‘groupname’
id usernamePrints real and effective user and group IDs for ‘username’
su - usernameSwitches the current user to ‘username’
whoamiPrints the current user name
chown username filenameChanges the owner of the file to ‘username’
chgrp groupname filenameChanges the group of the file to ‘groupname’

Process Management Commands

Process management commands in Linux are used to control and interact with processes (running instances of programs). They allow users to view, start, stop, and manage processes, as well as adjust their priority and monitor their status. These commands provide essential control over system resources and running applications.

psReports a snapshot of the current processes
topDisplays dynamic real-time view of running tasks
htopInteractive process viewer (more user-friendly than top)
pgrep patternLooks through the currently running processes and lists the process IDs which match the selection criteria
pkill patternSends a signal to the processes identified by the ‘pattern’
kill PIDSends a signal to the process with the specified Process ID (PID)
killall process-nameKills all processes with the name ‘process-name’
bgPlaces a job in the background
fgBrings a job to the foreground
jobsLists the jobs currently running in the background
niceModifies the priority of a process
reniceChanges the priority of a running process
uptimeShows how long the system has been running

Disk Management Commands

Disk management commands in Linux are utilities used to manage storage devices, file systems, and data on a Linux system. They help users to view disk usage, manage files and directories, format and partition disks, and mount or unmount disk volumes. These commands are critical for managing storage effectively and efficiently on a Linux system.

dfReports the amount of disk space used and available on file systems
duEstimates file and directory space usage
fdiskManipulates disk partition table
partedA partition manipulation program
mkfsBuilds a Linux file system, usually on a unmounted partition
mountMounts a file system
umountUnmounts a file system
fsckChecks the integrity of a file system and fixes errors if necessary
lsblkLists block devices
blkidLocates/print block device attributes
ddConverts and copies a file, can also be used to create disk images
fileDetermines the file type
findmntFinds a file system
lsofLists open files, and can also list files opened by a specific process
fdisk /dev/sdaStarts fdisk for device /dev/sda
mkfs.ext4 /dev/sda1Makes an ext4 file system on /dev/sda1
fsck.ext4 /dev/sda1Checks an ext4 file system on /dev/sda1
mount /dev/sda1 /mntMounts /dev/sda1 to the /mnt directory
df -hDisplays disk usage in human-readable format
df -iDisplays the inode usage of the file system
du -hsDisplays a summary of the total disk usage in human-readable format
lsusb -tvDisplays USB devices as a tree
hdparm -tT /dev/sdaPerforms a read speed test on /dev/sda
badblocks -s /dev/sdaChecks for bad blocks on /dev/sda

Package Management Command

Package management commands in Linux are used to automate the process of installing, upgrading, configuring, and removing software packages in a consistent manner. They handle software dependencies and ensure that all packages are kept up-to-date and function correctly. The specific package management system and the corresponding commands vary between different Linux distributions.

Below are all of the commands to install, remove and manage packages in Linux.

apt-get updateUpdates the list of available packages and their versions, but it does not install or upgrade any packages
apt-get upgradeInstalls the newest versions of all packages currently installed on the system
apt-get install packageNameInstalls a package
apt-get remove packageNameRemoves a package
apt-get autoremoveRemoves packages that were automatically installed to satisfy dependencies for some package and that are no more needed
apt-get -y upgradeUpgrades the system by removing/installing/upgrading packages
dpkg -i packageName.debInstalls a DEB package
dpkg -r packageNameRemoves a DEB package
dpkg -l | grep -i installedLists all installed DEB packages
yum updateUpdates all system packages
yum install packageNameInstalls a package
yum remove packageNameRemoves a package
yum listLists all packages in all repositories
rpm -i packageName.rpmInstalls an RPM package
rpm -e packageNameRemoves an RPM package

Compress and Uncompress Commands

In Linux, compress and uncompress commands are used to reduce the size of files or directories (compression) and restore them to their original size (uncompression or extraction). They are essential for data storage, file transfer, and for saving bandwidth on the internet. Tools like ‘tar’, ‘gzip’, ‘zip’, and ‘unzip’ are widely used for these tasks.

tar cf file.tar filesCreates a tarball
tar xf file.tarExtracts from a tarball
tar czf file.tar.gz filesCreates a tarball with gzip compression
tar xzf file.tar.gzExtracts from a gzip compressed tarball
tar cjf file.tar.bz2 filesCreates a tarball with bzip2 compression
tar xjf file.tar.bz2Extracts from a bzip2 compressed tarball
tar -cvf filename.tar filenameCreates a tarball with verbose output
tar -xvf filename.tarExtracts from a tarball with verbose output
tar -tvf filename.tarLists the contents of a tarball
tar -xvf filename.tar file1.txtExtracts a specific file from a tarball
tar -rvf filename.tar file2.txtAppends a file to a tarball
gzip fileCompresses a file with gzip, resulting in file.gz
gunzip file.gzDecompresses a gzip file
zip file.zip filesCreates a zip archive
unzip file.zipExtracts files from a zip archive
zip filename.zip file1.txt file2.txt file3.txtAdds multiple files to a zip archive
zip -u filename.zip file4.txtAdds or updates a file in a zip archive
zip -d filename.zip file4.txtDeletes a file from a zip archive
unzip -l filename.zipLists the contents of a zip archive
unzip filename.zip -d /dirnameExtracts files from a zip archive to a specific directory

More Cheat Sheets on Practically Networked

BASH Cheat Sheet