Here are 50 useful Linux commands that every developer should know, along with a brief description and an example of each command:
Buy Linux Commands Cheat Sheet (PDF)
-
ls- Lists the contents of a directory.- Example:
lswill list the contents of the current directory.ls /usr/localwill list the contents of the/usr/localdirectory.
- Example:
-
pwd- Prints the current working directory.- Example:
pwdwill print the full path of the current working directory.
- Example:
-
cd- Changes the current working directory.- Example:
cd /usr/localwill change the current working directory to/usr/local.
- Example:
-
mkdir- Creates a new directory.- Example:
mkdir mydirwill create a new directory calledmydir.
- Example:
-
mv- Moves a file or directory.- Example:
mv file.txt /usr/local/will move the filefile.txtto the/usr/localdirectory.
- Example:
-
cp- Copies a file or directory.- Example:
cp file.txt /usr/local/will copy the filefile.txtto the/usr/localdirectory.
- Example:
-
rm- Removes a file or directory.- Example:
rm file.txtwill remove the filefile.txt, whilerm -r mydirwill remove the directorymydirand all of its contents.
- Example:
-
touch- Creates a new empty file.- Example:
touch file.txtwill create a new empty file calledfile.txt.
- Example:
-
ln- Creates a link to a file or directory.- Example:
ln -s /usr/local/file.txt file.txtwill create a symbolic link to/usr/local/file.txtcalledfile.txtin the current directory.
- Example:
-
cat- Displays the contents of a file.- Example:
cat file.txtwill display the contents of the filefile.txtin the terminal.
- Example:
-
clear- Clears the terminal screen.- Example:
clearwill clear the contents of the terminal screen.
- Example:
-
echo- Prints a message to the terminal.- Example:
echo "Hello, world!"will print the message"Hello, world!"to the terminal.
- Example:
-
less- Views a file with pagination.- Example:
less file.txtwill allow you to view the contents offile.txtone page at a time.
- Example:
-
man- Displays the manual page for a command.- Example:
man lswill display the manual page for thelscommand, which describes its usage and options.
- Example:
-
uname- Displays information about the current system.- Example:
uname -awill display all information about the current system, including the kernel version and machine hardware name.
- Example:
-
whoami- Displays the current user.- Example:
whoamiwill display the username of the current user.
- Example:
-
tar- Archives and compresses files and directories.- Example:
tar -czf archive.tar.gz directory/will create a compressed archive calledarchive.tar.gzfrom the contents of thedirectorydirectory.
- Example:
-
grep- Searches for a pattern in a file.- Example:
grep "error" log.txtwill search the filelog.txtfor the pattern"error"and print any lines that match.
- Example:
-
head- Displays the first few lines of a file.- Example:
head -n 10 file.txtwill display the first 10 lines offile.txt.
- Example:
-
tail- Displays the last few lines of a file.- Example:
tail -n 10 file.txtwill display the last 10 lines offile.txt.
- Example:
-
diff- Compares the differences between two files.- Example:
diff file1.txt file2.txtwill compare the contents offile1.txtandfile2.txtand print the differences between them.
- Example:
-
cmp- Compares the contents of two files byte by byte.- Example:
cmp file1.txt file2.txtwill compare the contents offile1.txtandfile2.txtbyte by byte and report any differences.
- Example:
-
comm- Compares the contents of two sorted files line by line.- Example:
comm file1.txt file2.txtwill compare the contents offile1.txtandfile2.txt, which should both be sorted, and print the lines that are unique to each file.
- Example:
-
sort- Sorts the lines of a file.- Example:
sort file.txtwill sort the lines offile.txtalphabetically.
- Example:
-
export- Exports a shell variable.- Example:
export VARNAME="value"will create a shell variable calledVARNAMEwith the value"value".
- Example:
-
zip- Compresses files into a ZIP archive.- Example:
zip archive.zip file1.txt file2.txtwill create a ZIP archive calledarchive.zipcontaining the filesfile1.txtandfile2.txt.
- Example:
-
unzip- Extracts files from a ZIP archive.- Example:
unzip archive.zipwill extract the contents of thearchive.zipZIP archive.
- Example:
-
ssh- Connects to a remote server using the SSH protocol.- Example:
ssh user@example.comwill connect to the server atexample.comas the useruser.
- Example:
-
service- Controls system services.- Example:
service apache2 startwill start the Apache web server.
- Example:
-
ps- Displays information about running processes.- Example:
ps auxwill display a list of all running processes and their resource usage.
- Example:
-
kill- Sends a signal to a process to terminate it.- Example:
kill 12345will send the signal to terminate the process with the process ID12345.
- Example:
-
killall- Terminates all processes with a specified name.- Example:
killall firefoxwill terminate all processes with the namefirefox.
- Example:
-
df- Displays information about available disk space on mounted filesystems.- Example:
df -hwill display the available disk space in a human-readable format (e.g., in gigabytes or megabytes).
- Example:
-
mount- Mounts a filesystem.- Example:
mount /dev/sda1 /mnt/mydiskwill mount the partition/dev/sda1at the mount point/mnt/mydisk.
- Example:
-
chmod- Changes the permissions of a file or directory.- Example:
chmod 755 file.txtwill give read, write, and execute permissions to the owner and read and execute permissions to everyone else for the filefile.txt.
- Example:
-
chown- Changes the ownership of a file or directory.- Example:
chown user:group file.txtwill change the owner offile.txttouserand the group ownership togroup.
- Example:
-
ifconfig- Configures network interface parameters.- Example:
ifconfig eth0 upwill enable the network interfaceeth0.
- Example:
-
traceroute- Traces the path of packets to a destination.- Example:
traceroute example.comwill trace the path of packets from the current system to the destinationexample.com.
- Example:
-
wget- Downloads a file from the internet.- Example:
wget https://example.com/file.zipwill download the filefile.zipfromhttps://example.com.
- Example:
-
ufw- A frontend for managing a firewall.- Example:
ufw allow sshwill allow incoming connections to the SSH service.
- Example:
-
iptables- A firewall management tool for Linux.- Example:
iptables -A INPUT -p tcp --dport 80 -j ACCEPTwill allow incoming connections to TCP port 80 (the default port for HTTP).
- Example:
-
apt- A package manager for Debian-based systems.- Example:
apt updatewill update the list of available packages.
- Example:
-
sudo- Allows a user to run a command with the privileges of the superuser (root).- Example:
sudo apt updatewill update the list of available packages with root privileges.
- Example:
-
cal- Displays a calendar.- Example:
calwill display the current month's calendar.
- Example:
-
alias- Creates an alias for a command.- Example:
alias ll='ls -alF'will create an aliasllthat runs the commandls -alF.
- Example:
-
dd- Copies data from one location to another.- Example:
dd if=/dev/sda of=disk.imgwill create an image file calleddisk.imgof the contents of the device/dev/sda.
- Example:
-
whereis- Shows the locations of a command.- Example:
whereis lswill show the locations of thelscommand on the system.
- Example:
-
whatis- Shows a short description of a command.- Example:
whatis lswill show a short description of thelscommand.
- Example:
-
top- Displays information about running processes.- Example:
topwill display a list of running processes and their resource usage in real-time.
- Example:
-
passwd- Changes the password for a user.- Example:
passwd user1will prompt you to enter and confirm a new password for the useruser1.
- Example:
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
For example, to view the man page for the ls command, you can follow this link: https://linux.die.net/man/1/ls
The man page for a command includes a comprehensive reference guide for that specific command or utility, which is available on a Linux or Unix-like operating system. It includes a description of the command and its options, as well as examples of how to use the command. It may also include information about the command's syntax, return values, and any errors that may occur when the command is used.
You can access the man page for a command by typing man followed by the name of the command at the command prompt. The man pages are organized into sections, with each section covering a specific topic. The first section numbered 1, contains commands that are available to all users. The second section numbered 2, contains system calls, which are functions provided by the operating system's kernel that allow programs to request services from the kernel. The third section numbered 3, contains library functions, which are functions provided by libraries that are used by programs.
If You are using Medium Please support and follow me for interesting articles. Medium Profile
If this guide has been helpful to you and your team please share it with others!
Top comments (7)
Nice list!
Would be good maybe to mention
umountandwhich. I findwhich -a(e.g.which -a bash) helpful to find out if I have multiple installations of the same tool in different directories.touchis actually for updating the last modification date of the given file. The fact that it creates the file if it does not exist is merely a useful side effectThat is correct. The
touchcommand is primarily used to update the timestamps (i.e., the last modification date and the last access date) of a file. If the file does not exist,touchwill create an empty file with the specified name.very insightful
Nice Job!
Very useful, Thanks !
A Perfect List You have covered most of the basics command that every developer should know.
Thank you....
Keep it up @kanani_nirav