route2open

Linux Cheat Sheet

Discover essential Linux commands to enhance your networking skills. Perfect for both beginners and pros, start exploring now!

Linux Cheat Sheet Commands

Network engineers and system administrators frequently rely on these essential Linux commands for their daily tasks and critical operations.

To assist you, we've created a comprehensive Linux Cheat Sheet for your network or system management tasks. No more searching the internet for Linux commands—everything you need is right here. This cheat sheet will help you perform configuration tasks efficiently, much like other resources such as SONiC or ONiE Cheat Sheets.

System Information Commands

  • uname -a Shows Linux system info
  • uname -r Shows kernel release info
  • cat /etc/redhat-release Shows installed redhat version
  • uptime Displays system running/life time
  • hostname Shows system host name
  • hostname -I Shows ip addresses of the host
  • last reboot Displays system reboot history
  • date Displays current date and time
  • cal Displays monthly calendar
  • mount Shows mounted filesystems

Ls Options

  • -a Display hidden files
  • -R Recursive list
  • -r Reverse order
  • -t Sort by last modified
  • -S Sort by file size
  • -l Long listing format
  • -1 One file per line
  • -m Comma-separated output
  • -Q Quoted output

Command Lists & Pipes

  • cmd1 ; cmd2 Run cmd1 then cmd2
  • cmd1 && cmd2 Run cmd2 if cmd1 is successful
  • cmd1 || cmd2 Run cmd2 if cmd1 is not successful
  • cmd& Run cmd in a subshell
  • cmd1 | cmd2 Stdout of cmd1 to cmd2
  • cmd1 |& cmd2 Stderr of cmd1 to cmd2

IO Redirection

  • cmd< file Input of cmd from file
  • cmd1 <(cmd2) Output of cmd2 as file input to cmd1
  • cmd> file Standard output (stdout) of cmd to file
  • cmd> /dev/null Discard stdout of cmd
  • cmd>> file Append stdout to file
  • cmd 2> file Error output (stderr) of cmd to file
  • cmd 1>&2 Stdout to the same place as stderr
  • cmd 2>&1 Stderr to the same place as stdout
  • cmd&> file Every output of cmd to file

File Operations

  • touch file1 Create file1
  • cat file1 file2 Concatenate files and output
  • less file1 View and paginate file1
  • file file1 Get the type of file1
  • cp file1 file2 Copy file1 to file2
  • mv file1 file2 Move file1 to file2
  • rm file1 Delete file1
  • head file1 Show the first 10 lines of file1
  • tail file1 Show the last 10 lines of file1
  • tail -F file1 Output the last lines of file1 as it changes

Search Files

  • grep pattern files Search for pattern in files
  • grep -i pattern files Case-insensitive search
  • grep -r pattern dir Recursive search in dir
  • grep -v pattern files Inverted search
  • grep -o pattern files Show matched part of the file only
  • find /dir/ -name name* Find files starting with name in dir
  • find /dir/ -user name Find files owned by name in dir
  • find /dir/ -mmin num Find files modified less than num
  • find /home -size +500M Find files larger than 500MB in /home
  • whereis command Locate the binary and source
  • locate file: x Find the location of file quickly

Bash Shortcuts

  • CTRL-c Stop current command
  • CTRL-z Sleep program
  • CTRL-a Go to the start of the line
  • CTRL-e Go to the end of the line
  • CTRL-u Cut from the start of the line
  • CTRL-k Cut to the end of the line
  • CTRL-r Search history
  • !! Repeat the last command
  • !abc Run the last command starting with "abc”
  • !abc:p Print the last command starting with "abc"
  • !$ Last argument of the previous command
  • ALT-. Last argument of the previous command
  • !* All arguments of the previous command
  • ^abc^123 Run the previous command, replacing "abc" with "123"

Process Management

  • ps Show snapshot of processes
  • top Show real-time processes
  • kill pid: Kill the process with ID pid
  • pkill name: Kill processes with the name name
  • killall name Kill all processes with names
  • program & Start program in the background
  • bg List and resume stopped background jobs
  • fg Bring the most recent background job
  • fg x Bring job x to the foreground
  • nice Start a process with a given priority
  • renice Change the priority of an running process
  • pstree Display processes in a tree-like diagram
  • pmap Display a memory usage process map
  • lsof List files opened by running processes

Help Commands

  • command -h or command --help Review all available options of command
  • info command Find info documents about the command
  • whatis command Display a single-line command description
  • man UNIXCOMMAND View the detailed man page of command
  • apropos Search man pages for available commands

Hardware Information Commands

  • dmesg Display messages in the kernel ring buffer
  • cat /proc/cpuinfo Display CPU information
  • cat /proc/meminfo Display memory information
  • lspci -tv Display PCI devices
  • lsusb -tv Display USB devices
  • dmidecode Display DMI/SMBIOS information
  • hdparm -i /dev/sda Display information about disk sda
  • hdparm -tT /dev/sda Perform a read speed test on disk sda
  • badblocks -s /dev/sda Test for unreadable blocks on disk sda

Networking Commands

  • arp Display the ARP table of the device
  • arpwatch Display Ethernet activity and Ethernet/IP
  • bmon Display bandwidth captures
  • curl Used for file transfer
  • dhclient Analyze clients' IP address, gateway, DNS
  • dig Used for simple DNS lookup
  • dstat Collect and show system resources
  • ethtool Check settings of your NIC
  • ftp Used for file transfer
  • host Used for DNS lookup
  • hping3 Used for packet analysis
  • ifconfig Monitor and configure network interface
  • ip address Check network interfaces and routing
  • iptables Used for IP packet filtering
  • iftop Display current bandwidth usage
  • ifup Enable interfaces
  • ifdown Disable interfaces
  • iwconfig Monitor and configure wireless interfaces

Networking Commands

  • nload Used as a bandwidth monitoring tool
  • nmap Used for security audits
  • nslookup Used for DNS queries
  • ip route Routing table management
  • netstat Check network connections
  • route Display and manipulate IP routing table
  • ping Check reachability
  • sftp Secure file transfer
  • ss Give detailed information about sockets
  • ssh Used for secure connections
  • scp Secure file transfer
  • tcpdump Used for analyzing and capturing
  • telnet Used for classical unsecured connections
  • tshark Used for packet analysis and capturing
  • traceroute Used for path tracking
  • w Show who is logged in and what they do
  • wget Used to download content from servers
  • whois Check the WHOIS database and return IP and domain info

File Management

  • mkdir dir1 Create a new directory dir1
  • rmdir dir1 Remove an empty directory dir1
  • rm -r dir1 Remove a directory dir1
  • ln -s file1 link1 Create a symbolic link link1 to file1
  • chown user:group file1 Change the owner and group of file1
  • chmod 755 file1 Change permissions of file1 to 755
  • df -h Display disk space usage
  • du -sh dir1 Display the size of directory dir1
  • stat file1 Display detailed information about file1

User Management

  • adduser username Add a new user with username
  • deluser username Remove a user with username
  • passwd username Change the password for username
  • usermod -aG groupname username Add username to groupname
  • id username Display user ID and group ID for username
  • groups username Display group memberships for username
  • whoami Display the current logged-in username

Package Management

  • apt-get update Update the package lists
  • apt-get upgrade Upgrade all installed packages
  • apt-get install package Install a new package
  • apt-get remove package Remove an installed package
  • apt-get purge package Remove a package and its configuration
  • apt-get autoremove Remove automatically all packages
  • dpkg -i package.deb Install a package from a .deb file
  • dpkg -r package Remove an installed package

Disk Management

  • fdisk -l List disk partitions
  • mkfs -t ext4 /dev/sda1 Create an ext4 filesystem on /dev/sda1
  • mount /dev/sda1 /mnt Mount /dev/sda1 to /mnt
  • umount /mnt Unmount the filesystem mounted at /mnt
  • fsck /dev/sda1 Check and repair the filesystem on sda1
  • parted /dev/sda Partition a disk using GNU Parted
  • dd if=/dev/sda of=/dev/sdb Clone disk /dev/sda to /dev/sdb
  • lsblk List information about all available block devices

SSH and Remote Management

  • ssh user@hostname Connect to hostname as user
  • scp file1 user@hostname:/path Copy file1 to /path on hostname
  • rsync -avz file1 user@hostname:/path Synchronize file1 to /path on hostname
  • ssh-keygen Generate SSH key pairs
  • screen Start a screen session
  • tmux Start a tmux session
  • vncserver Start a VNC server session
  • ssh-copy-id user@hostname Copy SSH key to hostname for password-less login

System Monitoring

  • htop Interactive process viewer
  • free -h Display free and used memory
  • iostat Report CPU and I/O statistics
  • vmstat Report virtual memory statistics
  • sar Collect and report system activity info.
  • mpstat Report CPU usage
  • nmon Performance monitoring tool
  • uptime Display the system uptime

File Compression and Archiving

  • tar -cvf archive.tar dir1 Create a tarball of dir1
  • tar -xvf archive.tar Extract a tarball
  • tar -czvf archive.tar.gz dir1 Create a gzipped tarball of dir1
  • tar -xzvf archive.tar.gz Extract a gzipped tarball
  • gzip file Compress file
  • gunzip file.gz Decompress file.gz
  • zip archive.zip file1 file2 Create a zip archive of file1 and file2
  • unzip archive.zip Extract a zip archive

Text Processing

  • awk '{print $1}' file Print the first column of each line in file
  • sed 's/old/new/g' file Replace all occurrences of old with new
  • cut -d' ' -f1 file Cut the first field from each line in file
  • sort file Sort the contents of file
  • uniq file Remove duplicate lines from file
  • tr 'a-z' 'A-Z' < file Translate lowercase to uppercase in file
  • wc -l file Count the number of lines in file
  • split -l 1000 file Split file into chunks of 1000 lines each

What is Linux?

Linux is an open-source operating system kernel that serves as the foundation for various distributions, enabling users to manage hardware resources and run applications. Known for its stability and security, Linux is widely used in servers, desktops, and embedded systems around the world. Its flexibility and customization options make it a popular choice among developers and tech enthusiasts.

Is Linux an Operating System?

Yes, Linux is an operating system, specifically a Unix-like OS renowned for its robustness, flexibility, and security. It was developed by Linus Torvalds in 1991 and is built on the Linux kernel, which supports a wide variety of hardware platforms. Linux is open-source, meaning its source code is freely available for anyone to view, modify, and distribute. This open-source nature has fostered a vast community of developers who contribute to its continuous improvement, resulting in numerous Linux distributions (distros). Popular distros include Red Hat, Ubuntu, Fedora, Debian, and SUSE, each catering to different user needs and preferences.

For instance: Ubuntu is known for its user-friendly interface and is popular among desktop users and beginners, while Red Hat is widely used in enterprise environments for its stability and support. Fedora serves as a testing ground for new features that eventually make their way into Red Hat. Debian is valued for its stability and extensive software repositories, and SUSE is known for its excellent enterprise solutions and robust administrative tools. Linux powers a significant portion of the internet's infrastructure, including servers, supercomputers, and cloud environments. It is also prevalent in embedded systems, such as routers and smart devices, and has a growing presence on desktops. Its versatility, reliability, and cost-effectiveness make Linux a preferred choice for both personal and enterprise-level applications.

GNS3 Knowledge Base

Discover a wealth of information and expert tips in our GNS3 Knowledge Base, your go-to resource for mastering network simulations. Whether you need detailed tutorials, expert tips, or troubleshooting advice, our Knowledge Base has everything to enhance your skills and solve any challenges. Dive in now to enhance your skills and troubleshoot any challenges with ease!

Explore more

Basic Linux Commands

Basic Linux commands are fundamental for anyone using the Linux operating system, whether for personal use, development, or system administration. These commands allow users to interact with the system, perform tasks, and manage files efficiently. Here are 17 examples of basic Linux commands:

  • Remove a directory: rmdir directory_name
  • Delete a directory: rm -r directory_name
  • Delete a file: rm file_name
  • Change a password: passwd username
  • Unzip files: unzip file.zip
  • Copy a directory: cp -r source_directory destination_directory
  • Add a user to a group: usermod -aG group_name username
  • Add a user: adduser username
  • Copy a file: cp source_file destination_file
  • List users: cut -d: -f1 /etc/passwd
  • Search for a file: find /path/to/search -name file_name
  • List user accounts: cat /etc/passwd
  • Perform a traceroute: traceroute hostname
  • Use grep to search within files: grep 'search_term' file_name
  • Create a user: useradd username
  • Create a file: touch file_name
  • Move a file: mv source_file destination_file

Understanding these basic commands is crucial for effectively managing and navigating a Linux system. They form the foundation for more advanced operations and scripts, making daily tasks more streamlined and efficient. By mastering these commands, users can enhance their productivity and proficiency in using Linux.

Free Cheat Sheets

Click here to access free cheat sheets for networking and system administration

Download essential guides for SONiC, ONIE, Linux, networking protocols, and subnetting to enhance your technical skills

Explore more

Share the Knowledge: Spread the Word About Our Linux Cheat Sheet!

If you find this page helpful for your networking knowledge and skills, please consider sharing it with your friends, colleagues, and social media followers. Your support helps us create more valuable resources and enhance our courses.

You can share this page on your social media accounts like Facebook, LinkedIn, Twitter, and any related networking and programming forums or blogs. By sharing, you assist other networking enthusiasts in their learning journey, making their work easier and more efficient. So, if you'd like to help others, kindly share this page.

For more in-depth networking knowledge, visit our route2open courses.

Linux Cheat Sheet!

Simply provide us with your name and email address, and we’ll send you our cheat sheet straight to your inbox