Linux Cheat Sheet - (A quick reference for common tasks)

 




Linux, along with its various distributions like Ubuntu, CentOS, and Debian, is the backbone of countless servers, cloud environments, and development workstations around the world. Whether you're an experienced Qa/Automation Engineer/developer, or just getting started with Linux, knowing or even having a cheat sheet of the most common commands can save you time and frustration.

In this cheat sheet, I’ve compiled the most essential Linux commands that will help you navigate, manage files, control processes, and troubleshoot network issues efficiently. These commands are fundamental whether you're working with a server environment or a desktop interface. Whether you're new to Linux or need a refresher, this guide will serve as a handy reference for day-to-day tasks.


File System Navigation

  • ls – List directory contents

ls          # Basic listing  

ls -l       # Long format with details  

ls -a       # Show hidden files  

ls -h       # Human-readable file sizes  

  • cd – Change directory

cd /path/to/dir   # Navigate to a specific directory  

cd ..             # Move up one directory  

cd ~              # Go to the home directory  

  • pwd – Print working directory

pwd    # Show the current directory path  

  • stat – Display detailed file information

stat filename    # Includes creation/modification times  


2. File and Directory Management

  • mkdir – Create directories

mkdir dir           # Create a new directory  

mkdir -p dir1/dir2  # Create nested directories  

  • touch – Create empty files

touch file.txt    # Create an empty file  

  • rm – Remove files and directories

rm file.txt       # Remove a file  

rm -r dir         # Remove directory and its contents  

rm -f file.txt    # Force remove  

rm -f file.txt    # Force remove directory and its contents 

  • cp – Copy files and directories

cp file.txt /path    # Copy file  

cp -r dir /path      # Copy directory  

  • mv – Move or rename files

mv file.txt /path         # Move file  

mv oldname newname        # Rename a file or directory  


3. Viewing and Editing Files

  • cat – View file contents

cat file.txt      # Show full file content  

  • less – View file contents one page at a time

less file.txt     # Scroll through file  

  • head / tail – View the beginning or end of a file

head file.txt     # View the first 10 lines  

tail file.txt     # View the last 10 lines  

  • nano / vim – Edit files in the terminal

nano file.txt     # Open file in Nano text editor  

vim file.txt      # Open file in Vim text editor  


4. User Management

  • whoami – Display the current user

whoami  

  • sudo – Execute a command as a superuser

sudo <command >

sudo su        #run as sudo user


5. Permissions

  • chmod – Change file or directory permissions

chmod 755 file.txt       # Set read, write, and execute permissions for the owner; read and execute for others  

  • chown – Change file owner

sudo chown user:group file.txt   # Change owner to 'user' and group to 'group'  


6. Networking

  • ping – Check network connection

ping google.com  

  • ifconfig / ip – View or configure network interfaces

ifconfig  

ip addr show  

  • telnet – Test network connectivity

telnet hostname port  


7. Process Management

  • ps – View running processes

ps aux  

  • top / htop – Real-time process viewer

top  

htop  

  • kill – Terminate processes

kill -9 PID  


8. Disk Usage and Space

  • df – Disk space usage

df -h    # Human-readable disk space usage  

  • du – Directory space usage

du -sh /path/to/dir    # Check size of directory  


9. Package Management

Debian/Ubuntu

  • apt – Manage packages

sudo apt update                # Update package list  

sudo apt install package-name  # Install a package  

sudo apt remove package-name   # Remove a package  

RedHat/CentOS

  • yum – Manage packages

sudo yum install package-name  # Install a package  

sudo yum remove package-name   # Remove a package  


10. Searching

  • grep – Search text in files

grep "search-term" file.txt  

  • find – Locate files and directories

find /path/to/search -name "filename"  


11. System Monitoring

  • uptime – See system uptime and load

uptime  

  • free – Check memory usage

free -h  


12. SSH and Remote Access

  • ssh – Securely connect to remote servers

ssh user@hostname  

  • scp – Copy files over SSH

scp file.txt user@hostname:/path/to/destination  


13. Archiving and Compression

  • tar – Archive files

tar -cvf archive.tar file.txt    # Create an archive file

tar -xvf archive.tar      # Extract an archive file

  • gzip / gunzip – Compress and decompress files

gzip file.txt     # Create a ZIP archive

gunzip file.txt.gz     # Extract a ZIP archive








Comments

Popular posts from this blog

Sharing is caring - Intro to Jenkins shared libraries

Intro to Terraform and how it is related to test automation infrastructure

Test Automation, Security, and other vegetables