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!
1. 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/loca directory
.
2. 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.
3. mkdir
– Create a new directory.
mkdir
mydir
: This will create a new directory called mydirin
the current working directory.
4. rmdir
– Remove an empty directory.
rmdir
mydir
: This will remove the empty directory calledmydir
from the current working directory.
5. touch
– Create a new file.
touch myfile.txt
: This will create a new, emptyfile
calledmyfile.txt
in the current working directory.
6. 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
.
7. mv
– Move a file or directory.
mv myfile.txt mydir
: This will move thefile
myfile.txt
from the current working directory to the directorymydir
.mv mydir newname
: This willrename
the directory mydir to newname.
8. rm
– Delete a file.
rm myfile.txt
: This will delete thefile myfile.txt
from the current working directory.
9. cat
– Display the contents of a file.
cat myfile.txt
: This will display the contents of thefile myfile.txt
in the terminal.
10. less
– View the contents of a file one page at a time.
less myfile.txt
: This will display the contents of thefile 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.
11. head
– Display the first few lines of a file.
head myfile.txt
: This will display the first10
lines of thefile myfile.txt
.head -n 5 myfile.txt
: This will display the first5
lines of thefile myfile.txt
.
12. tail
– Display the last few lines of a file.
tail myfile.txt
: This will display the last10
lines of thefile myfile.txt
.tail -n 5 myfile.txt
: This will display the last5
lines of thefile myfile.txt
.
13. grep
– Search for a pattern in a file.
grep "hello" myfile.txt
: This will search for the pattern"hello"
in thefile myfile.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.
14. find
– Search for a file by name.
find . -name "myfile.txt"
: This will search for afile
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.
15. sort
– Sort the lines of a file.
sort myfile.txt
: This will sort the lines of thefile myfile.txt
in alphabetical order.sort -n myfile.txt
: This will sort the lines of thefile myfile.txt
in numerical order.
16. uniq
– Remove duplicate lines from a file.
uniq myfile.txt
: This will remove any duplicate lines from thefile myfile.txt
.uniq -c myfile.txt
: This will remove any duplicate lines from thefile myfile.txt
and print the count of the number of times each line appears in thefile
.
17. 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 thefile myfile.txt
.wc -l myfile.txt
: This will print the number of lines in thefile myfile.txt
.
18. 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 thefile myfile.txt
and print the fields.
19. 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.
20. tr
– Translate or delete specific characters from a file.
tr "a-z" "A-Z" < myfile.txt
: This will translate all lowercase letters in thefile myfile.txt
to uppercase and print the translated lines.tr -d "0-9" < myfile.txt
: This will delete all digits from thefile myfile.txt
and print the resulting lines.
21. sed
– Edit a file using regular expressions.
sed "s/hello/hi/" myfile.txt
: This will replace all occurrences of the word"hello"
with"hi"
in thefile myfile.txt
and print the resulting lines.sed "s/^#//" myfile.txt
: This will remove all leading # characters from the beginning of each line in thefile myfile.txt
and print the resulting lines.
22. 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 thefile myfile.txt.
awk -F "," '{print $2}' myfile.txt
: This will print the second field (delimited by a comma) of each line in thefile myfile.txt
.
23. ar
– 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.
24. gzip
– Compress or decompress a file using gzip.
gzip myfile.txt
: This will compress thefile myfile.txt
using gzip, creating a new file calledmyfile.txt.gz
.gunzip myfile.txt.gz
: This will decompress thefile myfile.txt.gz using gzip
, creating a new file calledmyfile.txt
.
25. bzip2
– Compress or decompress a file using bzip2.
bzip2 myfile.txt
: This will compress thefile myfile.txt
usingbzip2
, creating a new file calledmyfile.txt.bz2
.bunzip2 myfile.txt.bz2
: This will decompress thefile myfile.txt.bz2
usingbzip2
, creating a new file calledmyfile.txt
.
26. xz
– Compress or decompress a file using xz.
xz myfile.txt
: This will compress thefile myfile.txt using xz
, creating a new file calledmyfile.txt.xz
.unxz myfile.txt.xz
: This will decompress thefile myfile.txt.xz using xz
, creating a new file calledmyfile.txt
.
27. zip
– Compress or decompress a file using zip.
zip myfile.zip myfile.txt
: This will create a zip archive calledmyfile.zip
from thefile myfile.txt
.unzip myfile.zip
: This will extract the contents of the zip archivemyfile.zip
to the current working directory.
28. chmod
– Change the permissions of a file or directory.
chmod u+x myfile.sh
.chmod g-w mydir
: This will remove write permission for the group owner of the directorymydir
.
29. chown
– Change the owner and/or group of a file or directory.
chown user1 myfile.tx
t: This will change the owner of thefile myfile.txt
touser1
.chown user1:group1 mydir
: This will change the owner of the directorymydir
to user1 and the group owner to group1.
30. passwd
– Change the password of a user.
passwd
: This will prompt the user to enter and confirm a newpassword
.
31. su
– Change the current user to another user.
su user1
: This will change the current user to user1. 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.
32. 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.
33. whoami
– Print the current username.
whoami
: This will print the username of the current user.
34. who
– Print information about logged-in users.
who
: This will print the username, terminal, and logintime for
all logged-in users.who -u
: This will print the username, terminal, and logintime for
all users with processes on the system.
35. 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.
36. 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 commandhistory
for the current user.
37. 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.
38. printf
– Print a formatted message.
printf "Hello, %s!n" "world"
: This 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."
39. env
– Print the current environment variables.
export NEWVAR="hello"
: This will set the environment variableNEWVAR
to the value"hello"
.export NEWVAR
: This will print the value of the environment variableNEWVAR
.
40. export
– Set an environment variable.
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.
41. unset
– Unset an environment variable.
unset NEWVAR
: This will unset the environment variableNEWVAR
, removing it from the environment.
42. set
– Set shell options.
set
-o vi: This willset
the vi editing mode for the current shell.set -o noclobber
: This willset
the noclobber option, which prevents the shell from overwriting files with the > operator.
43. unalias
– Remove an alias.
alias ll="ls -l"
: Teate analias
callehis will crd ll that is equivalent to thecommand ls -l
.unalias ll
: This will remove thealias ll
.
44. source
– Execute a script in the current shell.
source myscript.sh
: This will execute the scriptmyscript.sh
in the current shell.env | grep HOME
: This will print the value of theHOME
environment variable.
45. . – Same as source.
- .
myscript.sh
: This will execute the scriptmyscript.sh
in the current shell.
46. 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 toreturn
to the original shell unless theyexit
vim.
47. exit
– Exit the current shell.
exit
: This willexit
the current shell.
48. shutdown
– Shutdown the system.
shutdown -h now
: This will shut down the system immediately.shutdown -r +5
: This will shut down the system andreboot
it in5
minutes.
50. init
– Change the system runlevel.
init 0
: This will shut down the system.init 6
: This willreboot
the system.
51. mount
– Mount a filesystem.
mount /dev/sda1 /mnt
: This willmount
the filesystem on/dev/sda1
to themount point /mnt
.mount -o ro /dev/sda1 /mnt
: This willmount
the filesystem on /dev/sda1 to themount
point /mnt in read-only mode.
52. 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.
53. disk
– Modify a disk partition table.
fdisk /dev/sda
: This willopen
thefdisk
utility for thedisk /dev/sda
, allowing the user to create, delete, or modify the partitions on the disk.fdisk -l
: This will list the partition tablefor
all disks on the system.
54. mkfs
– Create a filesystem.
mkfs.ext4 /dev/sda1
: This will create anext4
filesystem on the partition/dev/sda1
.mkfs.xfs /dev/sdb2
: This will create an xfs filesystem on the partition/dev/sdb2
.
55. 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.
56. tune2fs
– Modify the parameters of an ext2 or ext3 filesystem.
tune2fs -l /dev/sda1
: This will display the current parameters of the ext2 or ext3 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 the ext2 or ext3 filesystem on/dev/sda1
.
57. dumpe2fs
– Display the superblock and blocks group information of an ext2 or ext3 filesystem.
dumpe2fs /dev/sda1
: This will display the superblock and blocks group information of the ext2 or ext3 filesystem on/dev/sda1
.dumpe2fs -h /dev/sda1
: This will display the superblock and blocks group information in a more human-readable format for the ext2 or ext3 filesystem on/dev/sda1
.
58. resizefs
– Resize an ext2 or ext3 filesystem.
resizefs /dev/sda1
: This will resize the ext2 or ext3 filesystem on/dev/sda1
to fill the entire partition.resizefs -M /dev/sda1
: This will resize the ext2 or ext3 filesystem on/dev/sda1
to the minimum size required to hold the current files.
59. 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
.
60. 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
.
61. 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
: This will display information about the logical volume lvol1in
the volume group vg01.
62. 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
.
63. 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 called vg02 using the physical volumes on/dev/sdb2
and/dev/sdc3
.
64. lvcreate
– Create a logical volume in a LVM setup.
lvcreate -L 10G -n lvol1 vg01
: This will create a logical volume called lvol1 in the volume group vg01 with a size of10 GB
.lvcreate -l 100%FREE -n lvol2 vg01
: This will create a logical volume calledlvol2
in the volume group vg01 using all remaining free space in the volume group.
65. 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.
66. 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 volumegroups vg02 and vg03
from the system.
67. lvremove
– Remove a logical volume from a LVM setup.
lvremove /dev/vg01/lvol1
: This will remove the logical volume lvol1 from the volume group vg01.lvremove /dev/vg02/lvol2 /dev/vg03/lvol3
: This will remove the logical volumes lvol2 and lvol3 from the volume groups vg02 and vg03, respectively.
68. lvresize
– Resize a logical volume in a LVM setup.
lvresize -L +5G /dev/vg01/lvol1
: This will increase the size of the logical volume lvol1 in the volume groupvg01
by5 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.
69. 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 volume lvol1 in the volume group vg01 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
.
70. 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 volume lvol1 in the volume groupvg01
by5 GB
.lvreduce -l -100%FREE /dev/vg02/lvol2
: This will reduce the size of the logical volume lvol2 in the volume group vg02 by the amount of free space in the volume group.
71. 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
.
72. swapon
– Enable a swap area.
swapon /dev/sda1
: This willenable
the swap area on the partition/dev/sda1
.swapon -L swap01
: This will enable the swap area with the labelswap01
.
73. 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
.
74. chmod
– Change the permissions of a file or directory.
chmod 755 file.txt
: This will set the permissions offile.txt
torwxr-xr-x
.chmod u+x file.sh
: This willadd
execute permission for the owner offile.sh
.
75. chown
– Change the owner and/or group of a file or directory.
chown user1 file.txt
: This will set the owner offile.txt
to user1.chown user1:group1 file.txt
: This will set the owner offile.txt
to user1 and the group to group1.
76. chgrp
– Change the group of a file or directory.
chgrp group1 file.txt
: This will set the group offile.txt
to group1.chgrp -R group1 dir
: This will recursivelyset
the group of all files and directories in dir to group1.
77. umask
– Set the default permissions for newly created files and directories.
umask 022
: This willset
the default permissions for newly created files and directories torw-r--r--
.umask 077
: This willset
the default permissions for newly created files and directories torwx------
.
78. 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.
79. sudo
– Execute a command as another user, typically the root user.
sudo ls /root
: This will execute thels 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
.
80. passwd
– Change the password for a user.
passwd
: This will change the passwordfor
the current user.passwd user1
: This will change the passwordfor
the user user1.
81. 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 called user1 with a disabled password.
82. 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 user user1 from the system and also delete the user’s home directory.
83. 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
.
84. delgroup
– Remove a group from the system.
delgroup group1
: This will remove the group group1 from the system.delgroup --only-if-empty group1
: This will only remove the group group1 if it is empty.
85. usermod
– Modify a user account.
usermod -aG sudo user1
: This willadd
the user user1 to thesudo
group, allowing the user to execute commands withsudo
.usermod -L user1
: This will lock the user user1 account, preventing the user from logging in.
86. groupmod
– Modify a group.
groupmod -n group2 group1
: This willrename
the group group1 to group2.groupmod -g 2001 group1
: This will change the group ID of group1 to 2001.
87. 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 bashshell
.
88. userdel
– Delete a user account.
userdel user1
: This will delete the useruser1
from the system.userdel --force --remove user1
: This will delete the useruser1
from the system, including the user’s home directory and files, and force the deletion even if the user is still logged in.
89. groupadd
– Create a new group.
groupadd group1
: This will create a new group called group1.groupadd -r group1
: This will create a new group called group1 and mark it as a system group.
90. groupdel
– Delete a group.
groupdel group1
: This will delete the group group1 from the system.groupdel --force group1
: This will delete the group group1 from the system, even if the group is not empty.
91. visudo
– Edit the sudoers file.
visudo
: This willopen
the sudoersfile
in the default editor, allowing the user to edit thefile
.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 thefile
.
92. 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 willinstall
the packages package1 and package2.apt install package1 package2
: This willinstall
the packages package1 and package2.
93. 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 willinstall
the packages package1 and package2.apt-get remove package1 package2
: This willremove
the packages package1 and package2 from the system.
94. yum
– Yellowdog Updater, Modified. A package manager for CentOS, Fedora, and Red Hat systems.
yum update
: This will update allinstalled
packages to their latest versions.yum install package1 package2
: This williinstall
i the packages package1 and package2.yum remove package1 package2
This willremove
i the packages package1 and package2 from the system.
95. dnf - Dandified
Yum. A package manager for CentOS and Fedora systems.
dnf update
: This will update allinstalled
packages to their latest versions.dnf install package1 package2
: This willinstall
the packages package1 and package2.dnf remove package1 package2
: This willremove
the packages package1 and package2 from the system.
96. pacman
– Package Manager. A package manager for Arch Linux and Manjaro systems.
pacman -Syu
: This will synchronize the package database and update allinstalled
packages to their latest versions.pacman -S package1 package2
: This willinstall
the packages package1 and package2.pacman -R package1 package2
: This willremove
the packages package1 and package2 from the system.
97. zypper
– ZYpp Package Manager. A package manager for openSUSE and SLE systems.
zypper update
: This will update all installed packages to their latest versions.zypper install package1 package2
: This willinstall
the packages package1 and package2.zypper remove package1 package2
: This will remove the packages package1 and package2 from the system.
98. 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 willinstall
the packages package1 and package2.apk del package1 package2
: This will remove the packages package1 and package2 from the system.
99. 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 willinstall
the packages package1 and package2.emerge --unmerge package1 package2
: This will remove the packages package1 and package2 from the system.
100. pkg
– Package Manager. A package manager for FreeBSD systems.
Alright, that’s 100! Hope you find it helpful. Please let me know what you think.