Get ready to add some powerful Linux commands to your toolkit and take your coding skills up a notch.
Whether youβre an experienced Linux user or just starting out, this list of 100 must-know Linux commands for developers will help you tackle any task with ease. Weβll start out with the basics, and then get to the more interesting ones.
By incorporating AI tools like Bito AI, which helps you understand and optimize your code, youβll be able to work smarter, not harder and become a 10x developer.
So get ready to unlock the power of Linux in your development workflow with these commands!
-
ls
β List the contents of the current directory.-
ls
: This will list the files and directories in the current working directory. -
ls /usr/local
: This will list the files and directories in the/usr/local directory
.
-
-
cd
β Change the current working directory.-
cd /usr/local
: This will change the current working directory to/usr/local
. -
cd ..
: This will change the current working directory to the parent directory of the current working directory.
-
-
mkdir
β Create a new directory.-
mkdir mydir
: This will create a new directory calledmydir
in the current working directory.
-
-
rmdir
β Remove an empty directory.-
rmdir mydir
: This will remove the empty directory calledmydir
from the current working directory.
-
-
touch
β Create a new file.-
touch myfile.txt
: This will create a new, empty file calledmyfile.txt
in the current working directory.
-
-
cp
β Copy a file or directory.-
cp myfile.txt myfile_copy.txt
: This will create a copy ofmyfile.txt
calledmyfile_copy.txt
in the current working directory. -
cp -r mydir mydir_copy
: This will create a copy of the directorymydir
calledmydir_copy
in the current working directory, including all the files and subdirectories inmydir
.
-
-
mv
β Move a file or directory.-
mv myfile.txt mydir
: This will move the filemyfile.txt
from the current working directory to the directorymydir
. -
mv mydir newname
: This will rename the directorymydir
to newname.
-
-
rm
β Delete a file.-
rm myfile.txt
: This will delete the filemyfile.txt
from the current working directory.
-
-
cat
β Display the contents of a file.-
cat myfile.txt
: This will display the contents of the filemyfile.txt
in the terminal.
-
-
less
β View the contents of a file one page at a time.-
less myfile.txt
: This will display the contents of the file myfile.txt one page at a time in the terminal, allowing you to scroll through the file using the arrow keys. Press q to quit.
-
-
head
β Display the first few lines of a file.-
head myfile.txt
: This will display the first 10 lines of the filemyfile.txt
. -
head -n 5 myfile.txt
: This will display the first 5 lines of the filemyfile.txt
.
-
-
tail
β Display the last few lines of a file.-
tail myfile.txt
: This will display the last 10 lines of the filemyfile.txt
. -
tail -n 5 myfile.txt
: This will display the last 5 lines of the filemyfile.txt
.
-
-
grep
β Search for a pattern in a file.-
grep βhelloβ myfile.txt
*: This will search for the pattern βhelloβ in the filemyfile.txt
and print any lines that contain the pattern. -
grep -r βhelloβ
*: This will search for the pattern
βhelloβ in all files in the current working directory and its subdirectories, and print the names of the files and the lines that contain the pattern.
-
-
find
β Search for a file by name.-
find . -name βmyfile.txt
: This will search for a file calledmyfile.txt
in the current working directory and its subdirectories. -
find / -name β*.txtβ
: This will search for all files with a.txt
extension in the entire file system.
-
-
sort
β Sort the lines of a file.-
sort myfile.txt
: This will sort the lines of the filemyfile.txt
in alphabetical order. -
sort -n myfile.txt
: This will sort the lines of the filemyfile.txt
in numerical order.
-
-
uniq
β Remove duplicate lines from a file.-
uniq myfile.txt
: This will remove any duplicate lines from the filemyfile.txt
. -
sort -n myfile.txt
: This will remove any duplicate lines from the filemyfile.txt
and print the count of the number of times each line appears in the file.
-
-
wc
β Count the number of lines, words, and characters in a file.-
wc myfile.txt
: This will print the number of lines, words, and characters in the filemyfile.txt
. -
wc -l myfile.txt
: This will print the number of lines in the filemyfile.txt
.
-
-
cut
β Extract specific fields from a file.-
cut -d β,β -f 2 myfile.txt
: This will extract the second field (delimited by a comma) from each line of the file myfile.txt and print the fields.
-
-
paste
β Combine the lines of two or more files.-
paste file1.txt file2.txt
: This will combine the lines offile1.txt
andfile2.txt
side by side and print the combined lines. -
paste -d β,β file1.txt file2.txt
: This will combine the lines offile1.txt
andfile2.txt
and separate them with a comma, and print the combined lines.
-
-
tr
β Translate or delete specific characters from a file.-
tr βa-zβ βA-Zβ < myfile.txt
: This will translate all lowercase letters in the filemyfile.txt
to uppercase and print the translated lines. -
tr -d β0β9β < myfile.txt
: This will translate all lowercase letters in the filemyfile.txt
to uppercase and print the translated lines.
-
-
sed
β Edit a file using regular expressions.-
sed βs/hello/hi/β myfile.txt
: his will replace all occurrences of the wordβhelloβ
withβhiβ
in the filemyfile.txt
and print the resulting lines. -
sed βs/^#//β myfile.txt
: This will remove all leading # characters from the beginning of each line in the filemyfile.txt
and print the resulting lines.
-
-
awk
β Process and analyze a file using patterns and actions.-
awk β{print $1}β myfile.txt
: This will print the first field (delimited by whitespace) of each line in the filemyfile.txt
. -
awk -F β,β β{print $2}β myfile.txt
: This will print the second field (delimited by a comma) of each line in the filemyfile.txt
.
-
-
tar
β Create or extract a tarball (a compressed archive file).-
tar -cvf mydir.tar mydir
: This will create a tarball calledmydir.tar
from the directorymydir
. -
tar -xvf mydir.tar
: This will extract the contents of the tarballmydir.tar
to the current working directory.
-
-
gzip
β Compress or decompress a file usinggzip
.-
gzip myfile.txt
: This will compress the filemyfile.txt
usinggzip
, creating a new file calledmyfile.txt.gz
. -
gunzip myfile.txt.gz
: This will decompress the filemyfile.txt.gz
usinggzip
, creating a new file calledmyfile.txt
.
-
-
bzip2
β Compress or decompress a file usingbzip2
.-
bzip2 myfile.txt
: This will compress the filemyfile.txt
usingbzip2
, creating a new file calledmyfile.txt.bz2
. -
bunzip2 myfile.txt.bz2
: This will decompress the filemyfile.txt.bz2
usingbzip2
, creating a new file calledmyfile.txt
.
-
-
xz
β Compress or decompress a file usingxz
.-
xz myfile.txt
: This will compress the filemyfile.txt
usingxz
, creating a new file calledmyfile.txt.xz
. -
unxz myfile.txt.xz
: This will decompress the filemyfile.txt.xz
usingxz
, creating a new file calledmyfile.txt
.
-
-
zip
β Compress or decompress a file usingzip
.-
zip [myfile.zip](http://myfile.zip/) myfile.txt
: This will create a zip archive called[myfile.zip](http://myfile.zip/)
from the filemyfile.txt
. -
unzip [myfile.zip](http://myfile.zip/)
: This will extract the contents of the zip archive[myfile.zip](http://myfile.zip/)
to the current working directory.
-
-
chmod
β Change the permissions of a file or directory.-
chmod u+x [myfile.sh](http://myfile.sh/)
: This will add execute permission for the owner of the file[myfile.sh](http://myfile.sh/)
. -
chmod g-w mydir
:This will remove write permission for the group owner of the directorymydir
.
-
-
chown
β Change the owner and/or group of a file or directory.-
chown user1 myfile.txt
: This will change the owner of the filemyfile.txt
touser1
. -
chown user1:group1 mydir
: This will change the owner of the directorymydir
touser1
and the group owner togroup1
.
-
-
passwd
β Change the password of a user.-
passwd
: This will prompt the user to enter and confirm a new password.
-
-
su
β Change the current user to another user.-
su user1
: This will change the current user touser1
. The user will be prompted to enter the password foruser1
. -
su -
: This will change the current user to the root user. The user will be prompted to enter the root password.
-
-
sudo
β Execute a command as another user, usually the root user.-
sudo apt-get update
: This will update the package list for the package manager apt-get as the root user. The user will be prompted to enter their own password.
-
-
whoami
β Print the current username.-
whoami
: This will print the username of the current user.
-
-
who
β Print information about logged-in users.-
who
: This will print the username, terminal, and login time for all logged-in users. -
who -u
: This will print the username, terminal, and login time for all users with processes on the system.
-
-
last
β Print information about previous logins.-
last
: This will print a list of all previous logins to the system. -
last -f /var/log/wtmp
: This will print a list of all previous logins to the system using thefile /var/log/wtmp
as the source of the login information.
-
-
history
β Print a list of previously executed commands.-
history
: This will print a list of the previously executed commands for the current user. -
history -c
: This will clear the command history for the current user.
-
-
echo
β Print a message.-
echo βHello, world!β
: This will print the messageβHello, world!β
. -
echo $SHELL
: This will print the path to the current shell.
-
-
printf
β Print a formatted message.-
printf βHello, %s!\nβ βworldβ
: his will print the messageβHello, world!β
. -
printf βThe value of pi is approximately
%.2f.\n 3.14159:This will print the message
βThe value of pi is approximately 3.14.β
-
-
env
β Print the current environment variables.-
env
: This will print a list of all the current environment variables and their values. -
env | grep HOME
: This will print the value of theHOME
environment variable.
-
-
export
β Set an environment variable.-
export NEWVAR=βhelloβ
: This will set the environment variable NEWVAR to the valueβhelloβ
. -
export NEWVAR
: This will print the value of the environment variableNEWVAR
.
-
-
unset
β Unset an environment variable.-
unset NEWVAR
: This will unset the environment variableNEWVAR
, removing it from the environment.
-
-
set
β Set shell options.-
set -o vi
: This will set the vi editing mode for the current shell. -
set -o noclobber
: This will set thenoclobber
option, which prevents the shell from overwriting files with the > operator.
-
-
unalias
β Remove an alias.-
alias ll=βls -lβ
: This will create an alias calledll
that is equivalent to the commandls -l
. -
unalias ll
: This will remove the aliasll
-
-
source
β Execute a script in the current shell.-
source [myscript.sh](http://myscript.sh/)
: This will execute the script[myscript.sh](http://myscript.sh/)
in the current shell.
-
-
.
β Same as source.-
[myscript.sh](http://myscript.sh/)
: This will execute the script[myscript.sh](http://myscript.sh/)
in the current shell.
-
-
exec
β Replace the current shell with a command.-
exec vim
: This will replace the current shell with the vim text editor. The user will not be able to return to the original shell unless they exit vim.
-
-
exit
β Exit the current shell.-
exit
: This will exit the current shell.
-
-
shutdown
β Shutdown the system.-
shutdown -h now
: This will shut down the system immediately. -
shutdown -r +5
: This will shut down the system and reboot it in 5 minutes.
-
-
reboot
β Reboot the system.-
reboot
: This will reboot the system immediately.
-
-
init
β Change the system runlevel.-
init 0
: This will shut down the system. -
init 6
: This will reboot the system.
-
-
mount
β Mount a filesystem.-
mount /dev/sda1 /mnt
: This will mount the filesystem on/dev/sda1
to the mount point/mnt
. -
mount -o ro /dev/sda1 /mnt
: This will mount the filesystem on/dev/sda1
to the mount point/mnt
in read-only mode.
-
-
umount
β Unmount a filesystem.-
umount /mnt
: This will unmount the filesystem mounted on/mnt
. -
umount -l /mnt
: This willβlazy unmountβ
the filesystem mounted on/mnt
, allowing it to be unmounted even if there are open files on the filesystem.
-
-
fdisk
β Modify a disk partition table.-
fdisk /dev/sda
: This will open the fdisk utility for the disk/dev/sda
, allowing the user to create, delete, or modify the partitions on the disk. -
fdisk -l
: This will list the partition table for all disks on the system.
-
-
mkfs
β Create a filesystem.-
mkfs.ext4 /dev/sda1
: This will create an ext4 filesystem on the partition/dev/sda1
. -
mkfs.xfs /dev/sdb2
: This will create anxfs
filesystem on the partition/dev/sdb2
.
-
-
fsck
β Check and repair a filesystem.-
fsck /dev/sda1
: This will check and repair the filesystem on/dev/sda1
if necessary. -
fsck -a /dev/sdb2
: This will check and repair the filesystem on/dev/sdb2
if necessary, automatically fixing any errors that are found.
-
-
tune2fs
β Modify the parameters of anext2
orext3
filesystem.-
tune2fs -l /dev/sda1
: This will display the current parameters of theext2
orext3
filesystem on/dev/sda1
. -
tune2fs -c 5 /dev/sda1
: This will set the maximum number of mount counts before a filesystem check is required to 5 for theext2
orext3
filesystem on/dev/sda1
.
-
-
dumpe2fs
β Display the superblock and blocks group information of anext2
orext3
filesystem.-
dumpe2fs /dev/sda1
: This will display the superblock and blocks group information of theext2
orext3
filesystem on/dev/sda1
. -
dumpe2fs -h /dev/sda1
: This will display the superblock and blocks group information in a more human-readable format for theext2
orext3
filesystem on/dev/sda1
.
-
-
resizefs
β Resize anext2
orext3
filesystem.-
resizefs /dev/sda1
: This will resize theext2
orext3
filesystem on/dev/sda1
to fill the entire partition. -
resizefs -M /dev/sda1
: This will resize theext2
orext3
filesystem on/dev/sda1
to the minimum size required to hold the current files.
-
-
pvdisplay
β Display information about physical volumes in a LVM setup.-
pvdisplay
: This will display information about all physical volumes on the system. -
pvdisplay /dev/sda1
: This will display information about the physical volume on/dev/sda1
.
-
-
vgdisplay
β Display information about volume groups in a LVM setup.-
vgdisplay
: This will display information about all volume groups on the system. -
vgdisplay vg01
: This will display information about the volume groupvg01
.
-
-
lvdisplay
β Display information about logical volumes in a LVM setup.-
lvdisplay
: This will display information about all logical volumes on the system. -
lvdisplay /dev/vg01/lvol1
: his will display information about the logical volume lvol1 in the volume groupvg01
.
-
-
pvcreate
β Create a physical volume in a LVM setup.-
pvcreate /dev/sda1
: This will create a physical volume on/dev/sda1
. -
pvcreate /dev/sdb2 /dev/sdc3
: This will create physical volumes on/dev/sdb2
and/dev/sdc3
-
-
vgcreate
β Create a volume group in a LVM setup.-
vgcreate vg01 /dev/sda1
: This will create a volume group called vg01 using the physical volume on/dev/sda1
. -
vgcreate vg02 /dev/sdb2 /dev/sdc3
: This will create a volume group calledvg02
using the physical volumes on/dev/sdb2
and/dev/sdc3
.
-
-
lvcreate
β Create a logical volume in a LVM setup.-
lvcreate -L 10G -n lvol1 vg01
: This will create a logical volume calledlvol1
in the volume groupvg01
with a size of 10 GB -
lvcreate -l 100%FREE -n lvol2 vg01
: This will create a logical volume called lvol2 in the volume groupvg01
using all remaining free space in the volume group.
-
-
pvremove
β Remove a physical volume from a LVM setup.-
pvremove /dev/sda1
: This will remove the physical volume on/dev/sda1
from the system. -
pvremove /dev/sdb2 /dev/sdc3
: This will remove the physical volumes on/dev/sdb2
and/dev/sdc3
from the system.
-
-
vgremove
β Remove a volume group from a LVM setup.-
vgremove vg01
: This will remove the volume groupvg01
from the system. -
vgremove vg02 vg03
: This will remove the volume groupsvg02
andvg03
from the system.
-
-
lvremove
β Remove a logical volume from a LVM setup.-
lvremove /dev/vg01/lvol1
: This will remove the logical volumelvol1
from the volume groupvg01
. -
lvremove /dev/vg02/lvol2 /dev/vg03/lvol3
: This will remove the logical volumeslvol2
andlvol3
from the volume groupsvg02
andvg03
, respectively.
-
-
lvresize
β Resize a logical volume in a LVM setup.-
lvresize -L +5G /dev/vg01/lvol1
: This will increase the size of the logical volumelvol1
in the volume groupvg01
by 5 GB. -
lvresize -l +100%FREE /dev/vg02/lvol2
: This will increase the size of the logical volumelvol2
in the volume groupvg02
by the amount of free space in the volume group.
-
-
lvextend
β Extend a logical volume with additional physical volumes in a LVM setup.-
lvextend -L +5G /dev/vg01/lvol1 /dev/sda1
: This will extend the logical volumelvol1
in the volume groupvg01
by 5 GB using the physical volume on/dev/sda1
. -
lvextend -l +100%FREE /dev/vg02/lvol2 /dev/sdb2 /dev/sdc3
: This will extend the logical volume lvol2 in the volume group vg02 by the amount of free space in the volume group using the physical volumes on/dev/sdb2
and/dev/sdc3
.
-
-
lvreduce
β Reduce the size of a logical volume in a LVM setup.-
lvreduce -L -5G /dev/vg01/lvol1
: This will reduce the size of the logical volumelvol1
in the volume groupvg01
by 5 GB. -
lvreduce -l -100%FREE /dev/vg02/lvol2
:This will reduce the size of the logical volumelvol2
in the volume groupvg02
by the amount of free space in the volume group.
-
-
mkswap
β Create a swap area on a device.-
mkswap /dev/sda1
: This will create a swap area on the partition/dev/sda1
. -
mkswap /dev/sdb2 -L swap01
:This will create a swap area on the partition/dev/sdb2
with the labelswap01
.
-
-
swapon
β Enable a swap area.-
swapon /dev/sda1
: This will enable the swap area on the partition/dev/sda1
. -
swapon -L swap01
:This will enable the swap area with the labelswap01
.
-
-
swapoff
β Disable a swap area.-
swapoff /dev/sda1
: This will disable the swap area on the partition/dev/sda1
. -
swapoff -L swap01
:This will disable the swap area with the labelswap01
.
-
-
chmod
β Change the permissions of a file or directory.-
chmod 755 file.txt
: This will set the permissions of file.txt
torwxr-xr-x.
-
chmod u+x [file.sh](http://file.sh/)
:This will add execute permission for the owner of[file.sh](http://file.sh/)
.
-
-
chown
β Change the owner and/or group of a file or directory.-
chown user1 file.txt
: This will set the owner offile.txt
touser1
. -
chown user1:group1 file.txt
:This will set the owner offile.txt
to user1 and the group togroup1
.
-
-
chgrp
β Change the group of a file or directory.-
chgrp group1 file.txt
: This will set the group offile.txt
togroup1
. -
chgrp -R group1 dir
:This will recursively set the group of all files and directories indir
togroup1
.
-
-
umask
β Set the default permissions for newly created files and directories.-
umask 022
: This will set the default permissions for newly created files and directories torw-r β r β
. -
umask 077
:This will set the default permissions for newly created files and directories torwx β β β
.
-
-
su
β Change the current user.-
su user1
: This will switch the current user touser1
. -
su -
:This will switch to the root user and also load the root userβs environment.
-
-
sudo
β Execute a command as another user, typically the root user.-
sudo ls /root
: This will execute the ls command as the root user, allowing the user to view the contents of the root userβs home directory. -
sudo -u user1 command
:This will execute command as the useruser1
.
-
-
passwd
β Change the password for a user.-
passwd
: This will change the password for the current user. -
passwd user1
:This will change the password for the useruser1
.
-
-
adduser
β Add a new user to the system.-
adduser user1
: This will create a new user called user1. -
adduser β disabled-password user1
: This will create a new user calleduser1
with a disabled password.
-
-
deluser
β Remove a user from the system.-
deluser user1
: This will remove the user user1 from the system. -
deluser
β remove-home user1: This will remove the useruser1
from the system and also delete the userβs home directory.
-
-
addgroup
β Add a new group to the system.-
addgroup group1
: This will create a new group calledgroup1
. -
addgroup β system group1
: This will create a new system group calledgroup1
.
-
-
delgroup
β Remove a group from the system.-
delgroup group1
: This will remove the groupgroup1
from the system. -
delgroup β only-if-empty group1
: This will only remove the groupgroup1
if it is empty.
-
-
usermod
β Modify a user account.-
usermod -aG sudo user1
: This will add the useruser1
to the sudo group, allowing the user to execute commands with sudo. -
delgroup β only-if-empty group1
: This will lock the useruser1
account, preventing the user from logging in.
-
-
groupmod
β Modify a group.-
groupmod -n group2 group1
: This will rename the groupgroup1
togroup2
. -
delgroup β only-if-empty group1
: This will change the group ID ofgroup1
to 2001.
-
-
useradd
β Create a new user account.-
useradd user1
: This will create a new user calleduser1
. -
useradd -m -s /bin/bash user1
: This will create a new user called user1 with a home directory and the bash shell.
-
-
userdel
β Delete a user account.-
userdel user1
: This will delete the useruser1
from the system. -
userdel β force β remove user1
: This will delete the user user1 from the system, including the userβs home directory and files, and force the deletion even if the user is still logged in.
-
-
groupadd
β Create a new group.-
groupadd group1
: This will create a new group calledgroup1
. -
userdel β force β remove user1
:This will create a new group calledgroup1
and mark it as a system group.
-
-
groupdel
β Delete a group.-
groupdel group1
: This will delete the groupgroup1
from the system. -
groupdel β force group1
:This will delete the groupgroup1
from the system, even if the group is not empty.
-
-
visudo
β Edit the sudoers file.-
visudo
: This will open the sudoers file in the default editor, allowing the user to edit the file. -
visudo -f /etc/sudoers.d/custom
:This will open the custom file in the/etc/sudoers.d
directory in the default editor, allowing the user to edit the file.
-
-
apt
β Advanced Package Tool. A package manager for Debian and Ubuntu systems.-
apt update
: This will update the list of available packages and their versions. -
apt install package1 package2
:This will install the packagespackage1
andpackage2
. -
apt remove package1 package2
:This will remove the packagespackage1
andpackage2
from the system.
-
-
apt-get
β Advanced Package Tool. A package manager for Debian and Ubuntu systems.-
apt-get update
: This will update the list of available packages and their versions. -
apt-get install package1 package2
:This will install the packagespackage1
andpackage2
. -
apt-get remove package1 package2
:This will remove the packagespackage1
andpackage2
from the system.
-
-
yum
β Yellowdog Updater, Modified. A package manager for CentOS, Fedora, and Red Hat systems.-
yum update
: This will update all installed packages to their latest versions. -
yum install package1 package2
:This will install the packagespackage1
andpackage2
. -
yum remove package1 package2
:This will remove the packagespackage1
andpackage2
from the system.
-
-
dnf
β Dandified Yum. A package manager for CentOS and Fedora systems.-
dnf update
: This will update all installed packages to their latest versions. -
dnf install package1 package2
:This will install the packagespackage1
andpackage2
. -
dnf remove package1 package2
:This will remove the packagespackage1
andpackage2
from the system.
-
-
pacman β Package Manager
β A package manager for Arch Linux and Manjaro systems.-
pacman -Syu
: This will synchronize the package database and update all installed packages to their latest versions. -
pacman -S package1 package2
:This will install the packagespackage1
andpackage2
. -
pacman -R package1 package2
:This will remove the packagespackage1
andpackage2
from the system.
-
-
zypper β ZYpp Package Manager
β A package manager foropenSUSE
andSLE systems
.-
zypper update
: This will update all installed packages to their latest versions. -
zypper install package1 package2
:This will install the packagespackage1
andpackage2
. -
zypper remove package1 package2
:This will remove the packagespackage1
andpackage2
from the system.
-
-
apk β Alpine Linux Package Manager
β A package manager for Alpine Linux systems.-
apk update
: This will update the package database -
apk add package1 package2
: This will install the packagespackage1
andpackage2
. -
apk del package1 package2
: This will remove the packagespackage1
andpackage2
from the system.
-
-
emerge β Gentoo Package Manager
β A package manager for Gentoo systems.-
emerge β update world
: This will update all installed packages to their latest versions. -
emerge package1 package2
: This will install the packagespackage1
andpackage2
. -
emerge β unmerge package1 package2
: This will remove the packagespackage1
andpackage2
from the system.
-
-
pkg β Package Manager
- A package manager forFreeBSD
systems.
Alright, thatβs 100! Hope you find it helpful. Please let me know what you think.
Top comments (0)