Linux Commands Cheat Sheet

If you’re new to Linux, don’t worry! There are a few essential commands that can make your journey a lot easier. Commands like ‘ls’ help you see what’s in a directory, ‘cd’ allows you to move into different folders, and ‘pwd’ tells you where you currently are.

To manage files, ‘mkdir’ is used to make new folders, ‘touch’ can create new files, and ‘rm’ helps you delete them. For the system itself, ‘whoami’ tells you your user name, ‘sudo’ lets you perform actions with extra privileges, and ‘reboot’ and ‘poweroff’ are used to restart and shut down the computer. Remember, learning to use the Linux terminal is a bit like learning a new language – it might feel strange at first, but with time and practice, it’ll become second nature.

File System Navigation

CommandDescription
lsList all the files in a directory
ls -lList all files and their details (owner, mtime, size, etc)
ls -aList all the files in a directory (including hidden files)
pwdShow the present working directory
cdChange directory to some other location
fileView the type of any file

View, Create, Edit, and Delete Files and Directories

CommandDescription
mkdirCreate a new directory
touchCreate a new, empty file, or update the modified time of an existing one
cat > fileCreate a new file with the text you type after
cat fileView the contents of a
grepView the contents of a file that match a pattern
nano fileOpen a file (or create new one) in nano text editor
vim fileOpen a file (or create new one) in vim text editor
rm or rmdirRemove a file or empty directory
rm -rRemove a directory that isn’t empty
mvMove or rename a file or directory
cpCopy a file or directory
rsyncSynchronize the changes of one directory to another

Search for Files and Directories

CommandDescription
locateQuickly find a file or directory that has been cached
findSearch for a file or directory based on name and other parameters

Basic Administration Commands

CommandDescription
whoamiSee which user you are currently logged in as
sudoExecute a command with root permissions
sudo apt installInstall a package on Debian based systems
sudo dnf installInstall a package on Red Hat based systems
sudo apt removeRemove a package on Debian based systems
sudo dnf removeRemove a package on Red Hat based systems
rebootReboot the system
poweroffShut down the system

Hard Drive and Storage Commands

CommandDescription
df or df -hSee the current storage usage of mounted partitions
sudo fdisk -lSee information for all attached storage devices
duSee disk usage of a directory’s contents
treeView the directory structure for a path
mount and umountMount and unmount a storage device or ISO file

Compression Commands

CommandDescription
tar cf my_dir.tar my_dirCreate an uncompressed tar archive
tar cfz my_dir.tar my_dirCreate a tar archive with gzip compression
gzip fileCompress a file with gzip compression
tar xf fileExtract the contents of any type of tar archive
gunzip file.gzDecompress a file that has gzip compression

Networking Commands

CommandDescription
ip aShow IP address and other information for all active interfaces
ip rShow IP address of default gateway
cat /etc/resolv.confSee what DNS servers your system is configured to use
pingSend a ping request to a network device
tracerouteTrace the network path taken to a device
sshLogin to a remote device with SSH

File Permissions and Ownership

CommandDescription
chmodChange the file permissions for a file or directory
chownChange the owner of a file or directory
chgrpChange the group of a file or directory

User Management Commands

CommandDescription
useraddLow level utility for adding new user accounts
adduserHigh level utility for adding new user accounts
deluserDelete a user account
usermodModify a user account
groupaddCreate a new group
delgroupDelete a group

System Resource Management Commands

CommandDescription
free -mSee how much memory is in use and free
topSee a list of processes and their resource usage
htopA more human readable and interactive version of top
niceStart a new process with a specified priority
reniceChange the nice value of a currently running process
ps aux or ps -efView all of the currently running processes
kill or killallTerminate a process
kill -9 or killall -9Terminate a process with SIGKILL signal
bgSend a task to the background
fgBring a task to the foreground

Environment Variable Commands

CommandDescription
printenv or printenv variable_nameList all environment variables on a Linux system, or a specific one
whereis and whichFind where a command in PATH is located
export MY_SITE="linuxconfig.org"Set a temporary environment variable
echo $VARIABLEDisplay the value of a variable
unsetRemove a variable

Kernel Information and Module Management

CommandDescription
uname -aOutput detailed information about your kernel version and architecture
lsmodFind what modules are currently loaded
modinfo module_nameGet information about any particular module
modprobe --remove module_nameRemove a module
modprobe module_nameLoad a module into the kernel

Hardware Information Commands

CommandDescription
lspciSee general information about host bridge, VGA, ethernet, USB, SATA controllers, etc.
dmidecodeSee information about BIOS, motherboard, chassis, etc.
cat /proc/cpuinfoRetrieve processor type, socket, speed, configured flags, etc.
x86info or x86info -aSee information about the CPU
cat /proc/meminfoSee detailed information about system RAM
lshwList all hardware components and see their configuration details
lshw -C memory -shortDetect number of RAM slots used, speed, and size
hwinfoList details for all hardware, including device files and configuration
biosdecodeGet some general information about your system’s BIOS
dmidecode -s bios-vendorRetrieve the name of your BIOS vendor
lsusbGet a list of USB devices plugged into your system
ls -la /dev/disk/by-id/usb-*Retrieve a list of USB device files
hdparm -I /dev/sdxGet info on hard drive make, model, serial, firmware, and configuration
hdparm -tT /dev/sdxShow the speed of an installed hard drive (cached and buffered reads)
wodim --devicesLocate CD or DVD device file

Discover more from AddSpice

Subscribe to get the latest posts sent to your email.