Linux Commands Cheat Sheet

Linux commands that every developer should know, along with a brief description and an example of each command:
CommandExplanationexample
lsLists the contents of a directory.ls will list the contents of the current directory. ls /usr/local will list the contents of the /usr/local directory.
pwdPrints the current working directory.pwd will print the full path of the current working directory.
cdChanges the current working directory.cd /usr/local will change the current working directory to /usr/local.
mkdirCreates a new directory.mkdir mydir will create a new directory called mydir.
mvMoves a file or directory.mv file.txt /usr/local/ will move the file file.txt to the /usr/local directory.
cpCopies a file or directory.cp file.txt /usr/local/ will copy the file file.txt to the /usr/local directory.
rmRemoves a file or directory.rm file.txt will remove the file file.txt, while rm -r mydir will remove the directory mydir and all of its contents.
touchCreates a new empty file.touch file.txt will create a new empty file called file.txt.
lnCreates a link to a file or directory.ln -s /usr/local/file.txt file.txt will create a symbolic link to /usr/local/file.txt called file.txt in the current directory.
catDisplays the contents of a file.cat file.txt will display the contents of the file file.txt in the terminal.
clearClears the terminal screen.clear will clear the contents of the terminal screen.
echoPrints a message to the terminal.echo "Hello, world!" will print the message "Hello, world!" to the terminal.
lessViews a file with pagination.less file.txt will allow you to view the contents of file.txt one page at a time.
manDisplays the manual page for a command.man ls will display the manual page for the ls command, which describes its usage and options.
unameDisplays information about the current system.uname -a will display all information about the current system, including the kernel version and machine hardware name.
whoamiDisplays the current user.whoami will display the username of the current user.
tarArchives and compresses files and directories.tar -czf archive.tar.gz directory/ will create a compressed archive called archive.tar.gz from the contents of the directory directory.
grepSearches for a pattern in a file.grep "error" log.txt will search the file log.txt for the pattern "error" and print any lines that match.
headDisplays the first few lines of a file.head -n 10 file.txt will display the first 10 lines of file.txt.
tailDisplays the last few lines of a file.tail -n 10 file.txt will display the last 10 lines of file.txt.
diffCompares the differences between two files.diff file1.txt file2.txt will compare the contents of file1.txt and file2.txt and print the differences between them.
cmpCompares the contents of two files byte by byte.cmp file1.txt file2.txt will compare the contents of file1.txt and file2.txt byte by byte and report any differences.
commCompares the contents of two sorted files line by line.comm file1.txt file2.txt will compare the contents of file1.txt and file2.txt, which should both be sorted, and print the lines that are unique to each file.
sortSorts the lines of a file.sort file.txt will sort the lines of file.txt alphabetically.
exportExports a shell variable.export VARNAME="value" will create a shell variable called VARNAME with the value "value".
zipCompresses files into a ZIP archive.zip archive.zip file1.txt file2.txt will create a ZIP archive called archive.zip containing the files file1.txt and file2.txt.
unzipExtracts files from a ZIP archive.unzip archive.zip will extract the contents of the archive.zip ZIP archive.
sshConnects to a remote server using the SSH protocol.ssh [email protected] will connect to the server at example.com as the user user.
serviceControls system services.service apache2 start will start the Apache web server.
psDisplays information about running processes.ps aux will display a list of all running processes and their resource usage.
killSends a signal to a process to terminate it.kill 12345 will send the signal to terminate the process with the process ID 12345.
killallTerminates all processes with a specified namekillall firefox will terminate all processes with the name firefox.
dfDisplays information about available disk space on mounted filesystems.df -h will display the available disk space in a human-readable format (e.g., in gigabytes or megabytes).
mountMounts a filesystem.mount /dev/sda1 /mnt/mydisk will mount the partition /dev/sda1 at the mount point /mnt/mydisk.
chmodChanges the permissions of a file or directory.chmod 755 file.txt will give read, write, and execute permissions to the owner and read and execute permissions to everyone else for the file file.txt.
chownChanges the ownership of a file or directory.chown user:group file.txt will change the owner of file.txt to user and the group ownership to group.
ifconfigConfigures network interface parameters.ifconfig eth0 up will enable the network interface eth0.
tracerouteTraces the path of packets to a destination.traceroute example.com will trace the path of packets from the current system to the destination example.com.
wgetDownloads a file from the internet.wget https://example.com/file.zip will download the file file.zip from https://example.com.
ufwA frontend for managing a firewall.ufw allow ssh will allow incoming connections to the SSH service.
iptablesA firewall management tool for Linux.iptables -A INPUT -p tcp --dport 80 -j ACCEPT will allow incoming connections to TCP port 80 (the default port for HTTP).
aptA package manager for Debian-based systems.apt update will update the list of available packages.
sudoAllows a user to run a command with the privileges of the superuser (root).sudo apt update will update the list of available packages with root privileges.
calDisplays a calendar.cal will display the current month’s calendar.
aliasCreates an alias for a command.alias ll='ls -alF' will create an alias ll that runs the command ls -alF.
ddCopies data from one location to another.dd if=/dev/sda of=disk.img will create an image file called disk.img of the contents of the device /dev/sda.
whereisShows the locations of a command.whereis ls will show the locations of the ls command on the system.
whatisShows a short description of a command.whatis ls will show a short description of the ls command.
topDisplays information about running processes.top will display a list of running processes and their resource usage in real-time.
passwdChanges the password for a user.passwd user1 will prompt you to enter and confirm a new password for the user user1.

Reference

More details about a specific command can be found by following the link below:

  • Bash URL: https://linux.die.net/man/1/change_command_name