50 Linux Commands every developer NEED to know with example
Kanani Nirav
Posted on December 22, 2022
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:
ls
will list the contents of the current directory.ls /usr/local
will list the contents of the/usr/local
directory.
- Example:
-
pwd
- Prints the current working directory.- Example:
pwd
will print the full path of the current working directory.
- Example:
-
cd
- Changes the current working directory.- Example:
cd /usr/local
will change the current working directory to/usr/local
.
- Example:
-
mkdir
- Creates a new directory.- Example:
mkdir mydir
will create a new directory calledmydir
.
- Example:
-
mv
- Moves a file or directory.- Example:
mv file.txt /usr/local/
will move the filefile.txt
to the/usr/local
directory.
- Example:
-
cp
- Copies a file or directory.- Example:
cp file.txt /usr/local/
will copy the filefile.txt
to the/usr/local
directory.
- Example:
-
rm
- Removes a file or directory.- Example:
rm file.txt
will remove the filefile.txt
, whilerm -r mydir
will remove the directorymydir
and all of its contents.
- Example:
-
touch
- Creates a new empty file.- Example:
touch file.txt
will 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.txt
will create a symbolic link to/usr/local/file.txt
calledfile.txt
in the current directory.
- Example:
-
cat
- Displays the contents of a file.- Example:
cat file.txt
will display the contents of the filefile.txt
in the terminal.
- Example:
-
clear
- Clears the terminal screen.- Example:
clear
will 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.txt
will allow you to view the contents offile.txt
one page at a time.
- Example:
-
man
- Displays the manual page for a command.- Example:
man ls
will display the manual page for thels
command, which describes its usage and options.
- Example:
-
uname
- Displays information about the current system.- Example:
uname -a
will display all information about the current system, including the kernel version and machine hardware name.
- Example:
-
whoami
- Displays the current user.- Example:
whoami
will 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.gz
from the contents of thedirectory
directory.
- Example:
-
grep
- Searches for a pattern in a file.- Example:
grep "error" log.txt
will search the filelog.txt
for the pattern"error"
and print any lines that match.
- Example:
-
head
- Displays the first few lines of a file.- Example:
head -n 10 file.txt
will display the first 10 lines offile.txt
.
- Example:
-
tail
- Displays the last few lines of a file.- Example:
tail -n 10 file.txt
will display the last 10 lines offile.txt
.
- Example:
-
diff
- Compares the differences between two files.- Example:
diff file1.txt file2.txt
will compare the contents offile1.txt
andfile2.txt
and print the differences between them.
- Example:
-
cmp
- Compares the contents of two files byte by byte.- Example:
cmp file1.txt file2.txt
will compare the contents offile1.txt
andfile2.txt
byte by byte and report any differences.
- Example:
-
comm
- Compares the contents of two sorted files line by line.- Example:
comm file1.txt file2.txt
will compare the contents offile1.txt
andfile2.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.txt
will sort the lines offile.txt
alphabetically.
- Example:
-
export
- Exports a shell variable.- Example:
export VARNAME="value"
will create a shell variable calledVARNAME
with the value"value"
.
- Example:
-
zip
- Compresses files into a ZIP archive.- Example:
zip archive.zip file1.txt file2.txt
will create a ZIP archive calledarchive.zip
containing the filesfile1.txt
andfile2.txt
.
- Example:
-
unzip
- Extracts files from a ZIP archive.- Example:
unzip archive.zip
will extract the contents of thearchive.zip
ZIP archive.
- Example:
-
ssh
- Connects to a remote server using the SSH protocol.- Example:
ssh user@example.com
will connect to the server atexample.com
as the useruser
.
- Example:
-
service
- Controls system services.- Example:
service apache2 start
will start the Apache web server.
- Example:
-
ps
- Displays information about running processes.- Example:
ps aux
will display a list of all running processes and their resource usage.
- Example:
-
kill
- Sends a signal to a process to terminate it.- Example:
kill 12345
will send the signal to terminate the process with the process ID12345
.
- Example:
-
killall
- Terminates all processes with a specified name.- Example:
killall firefox
will terminate all processes with the namefirefox
.
- Example:
-
df
- Displays information about available disk space on mounted filesystems.- Example:
df -h
will 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/mydisk
will mount the partition/dev/sda1
at the mount point/mnt/mydisk
.
- Example:
-
chmod
- Changes the permissions of a file or directory.- Example:
chmod 755 file.txt
will 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.txt
will change the owner offile.txt
touser
and the group ownership togroup
.
- Example:
-
ifconfig
- Configures network interface parameters.- Example:
ifconfig eth0 up
will enable the network interfaceeth0
.
- Example:
-
traceroute
- Traces the path of packets to a destination.- Example:
traceroute example.com
will 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.zip
will download the filefile.zip
fromhttps://example.com
.
- Example:
-
ufw
- A frontend for managing a firewall.- Example:
ufw allow ssh
will allow incoming connections to the SSH service.
- Example:
-
iptables
- A firewall management tool for Linux.- Example:
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
will allow incoming connections to TCP port 80 (the default port for HTTP).
- Example:
-
apt
- A package manager for Debian-based systems.- Example:
apt update
will 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 update
will update the list of available packages with root privileges.
- Example:
-
cal
- Displays a calendar.- Example:
cal
will display the current month's calendar.
- Example:
-
alias
- Creates an alias for a command.- Example:
alias ll='ls -alF'
will create an aliasll
that runs the commandls -alF
.
- Example:
-
dd
- Copies data from one location to another.- Example:
dd if=/dev/sda of=disk.img
will create an image file calleddisk.img
of the contents of the device/dev/sda
.
- Example:
-
whereis
- Shows the locations of a command.- Example:
whereis ls
will show the locations of thels
command on the system.
- Example:
-
whatis
- Shows a short description of a command.- Example:
whatis ls
will show a short description of thels
command.
- Example:
-
top
- Displays information about running processes.- Example:
top
will display a list of running processes and their resource usage in real-time.
- Example:
-
passwd
- Changes the password for a user.- Example:
passwd user1
will 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!
Posted on December 22, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.