Here are 50 Linux commands that every developer should know, along with a brief description and an example of each command:
-
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:
If this guide has been helpful to you and your team please share it with others!