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 calledmydirin the current working directory.
-
-
rmdirβ Remove an empty directory.-
rmdir mydir: This will remove the empty directory calledmydirfrom the current working directory.
-
-
touchβ Create a new file.-
touch myfile.txt: This will create a new, empty file calledmyfile.txtin the current working directory.
-
-
cpβ Copy a file or directory.-
cp myfile.txt myfile_copy.txt: This will create a copy ofmyfile.txtcalledmyfile_copy.txtin the current working directory. -
cp -r mydir mydir_copy: This will create a copy of the directorymydircalledmydir_copyin 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.txtfrom the current working directory to the directorymydir. -
mv mydir newname: This will rename the directorymydirto newname.
-
-
rmβ Delete a file.-
rm myfile.txt: This will delete the filemyfile.txtfrom the current working directory.
-
-
catβ Display the contents of a file.-
cat myfile.txt: This will display the contents of the filemyfile.txtin 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.txtand 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.txtin the current working directory and its subdirectories. -
find / -name β*.txtβ: This will search for all files with a.txtextension in the entire file system.
-
-
sortβ Sort the lines of a file.-
sort myfile.txt: This will sort the lines of the filemyfile.txtin alphabetical order. -
sort -n myfile.txt: This will sort the lines of the filemyfile.txtin 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.txtand 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.txtandfile2.txtside by side and print the combined lines. -
paste -d β,β file1.txt file2.txt: This will combine the lines offile1.txtandfile2.txtand 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.txtto uppercase and print the translated lines. -
tr -d β0β9β < myfile.txt: This will translate all lowercase letters in the filemyfile.txtto 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.txtand print the resulting lines. -
sed βs/^#//β myfile.txt: This will remove all leading # characters from the beginning of each line in the filemyfile.txtand 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.tarfrom the directorymydir. -
tar -xvf mydir.tar: This will extract the contents of the tarballmydir.tarto the current working directory.
-
-
gzipβ Compress or decompress a file usinggzip.-
gzip myfile.txt: This will compress the filemyfile.txtusinggzip, creating a new file calledmyfile.txt.gz. -
gunzip myfile.txt.gz: This will decompress the filemyfile.txt.gzusinggzip, creating a new file calledmyfile.txt.
-
-
bzip2β Compress or decompress a file usingbzip2.-
bzip2 myfile.txt: This will compress the filemyfile.txtusingbzip2, creating a new file calledmyfile.txt.bz2. -
bunzip2 myfile.txt.bz2: This will decompress the filemyfile.txt.bz2usingbzip2, creating a new file calledmyfile.txt.
-
-
xzβ Compress or decompress a file usingxz.-
xz myfile.txt: This will compress the filemyfile.txtusingxz, creating a new file calledmyfile.txt.xz. -
unxz myfile.txt.xz: This will decompress the filemyfile.txt.xzusingxz, 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.txttouser1. -
chown user1:group1 mydir: This will change the owner of the directorymydirtouser1and 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/wtmpas 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 theHOMEenvironment 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 thenoclobberoption, which prevents the shell from overwriting files with the > operator.
-
-
unaliasβ Remove an alias.-
alias ll=βls -lβ: This will create an alias calledllthat 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/sda1to the mount point/mnt. -
mount -o ro /dev/sda1 /mnt: This will mount the filesystem on/dev/sda1to the mount point/mntin 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 anxfsfilesystem on the partition/dev/sdb2.
-
-
fsckβ Check and repair a filesystem.-
fsck /dev/sda1: This will check and repair the filesystem on/dev/sda1if necessary. -
fsck -a /dev/sdb2: This will check and repair the filesystem on/dev/sdb2if necessary, automatically fixing any errors that are found.
-
-
tune2fsβ Modify the parameters of anext2orext3filesystem.-
tune2fs -l /dev/sda1: This will display the current parameters of theext2orext3filesystem 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 theext2orext3filesystem on/dev/sda1.
-
-
dumpe2fsβ Display the superblock and blocks group information of anext2orext3filesystem.-
dumpe2fs /dev/sda1: This will display the superblock and blocks group information of theext2orext3filesystem on/dev/sda1. -
dumpe2fs -h /dev/sda1: This will display the superblock and blocks group information in a more human-readable format for theext2orext3filesystem on/dev/sda1.
-
-
resizefsβ Resize anext2orext3filesystem.-
resizefs /dev/sda1: This will resize theext2orext3filesystem on/dev/sda1to fill the entire partition. -
resizefs -M /dev/sda1: This will resize theext2orext3filesystem on/dev/sda1to 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/sdb2and/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 calledvg02using the physical volumes on/dev/sdb2and/dev/sdc3.
-
-
lvcreateβ Create a logical volume in a LVM setup.-
lvcreate -L 10G -n lvol1 vg01: This will create a logical volume calledlvol1in the volume groupvg01with a size of 10 GB -
lvcreate -l 100%FREE -n lvol2 vg01: This will create a logical volume called lvol2 in the volume groupvg01using 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/sda1from the system. -
pvremove /dev/sdb2 /dev/sdc3: This will remove the physical volumes on/dev/sdb2and/dev/sdc3from the system.
-
-
vgremoveβ Remove a volume group from a LVM setup.-
vgremove vg01: This will remove the volume groupvg01from the system. -
vgremove vg02 vg03: This will remove the volume groupsvg02andvg03from the system.
-
-
lvremoveβ Remove a logical volume from a LVM setup.-
lvremove /dev/vg01/lvol1: This will remove the logical volumelvol1from the volume groupvg01. -
lvremove /dev/vg02/lvol2 /dev/vg03/lvol3: This will remove the logical volumeslvol2andlvol3from the volume groupsvg02andvg03, respectively.
-
-
lvresizeβ Resize a logical volume in a LVM setup.-
lvresize -L +5G /dev/vg01/lvol1: This will increase the size of the logical volumelvol1in the volume groupvg01by 5 GB. -
lvresize -l +100%FREE /dev/vg02/lvol2: This will increase the size of the logical volumelvol2in the volume groupvg02by 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 volumelvol1in the volume groupvg01by 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/sdb2and/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 volumelvol1in the volume groupvg01by 5 GB. -
lvreduce -l -100%FREE /dev/vg02/lvol2:This will reduce the size of the logical volumelvol2in the volume groupvg02by 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/sdb2with 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.txttorwxr-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.txttouser1. -
chown user1:group1 file.txt:This will set the owner offile.txtto user1 and the group togroup1.
-
-
chgrpβ Change the group of a file or directory.-
chgrp group1 file.txt: This will set the group offile.txttogroup1. -
chgrp -R group1 dir:This will recursively set the group of all files and directories indirtogroup1.
-
-
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 calleduser1with 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 useruser1from 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 groupgroup1from the system. -
delgroup β only-if-empty group1: This will only remove the groupgroup1if it is empty.
-
-
usermodβ Modify a user account.-
usermod -aG sudo user1: This will add the useruser1to the sudo group, allowing the user to execute commands with sudo. -
delgroup β only-if-empty group1: This will lock the useruser1account, preventing the user from logging in.
-
-
groupmodβ Modify a group.-
groupmod -n group2 group1: This will rename the groupgroup1togroup2. -
delgroup β only-if-empty group1: This will change the group ID ofgroup1to 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 useruser1from 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 calledgroup1and mark it as a system group.
-
-
groupdelβ Delete a group.-
groupdel group1: This will delete the groupgroup1from the system. -
groupdel β force group1:This will delete the groupgroup1from 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.ddirectory 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 packagespackage1andpackage2. -
apt remove package1 package2:This will remove the packagespackage1andpackage2from 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 packagespackage1andpackage2. -
apt-get remove package1 package2:This will remove the packagespackage1andpackage2from 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 packagespackage1andpackage2. -
yum remove package1 package2:This will remove the packagespackage1andpackage2from 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 packagespackage1andpackage2. -
dnf remove package1 package2:This will remove the packagespackage1andpackage2from 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 packagespackage1andpackage2. -
pacman -R package1 package2:This will remove the packagespackage1andpackage2from the system.
-
-
zypper β ZYpp Package Managerβ A package manager foropenSUSEandSLE systems.-
zypper update: This will update all installed packages to their latest versions. -
zypper install package1 package2:This will install the packagespackage1andpackage2. -
zypper remove package1 package2:This will remove the packagespackage1andpackage2from 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 packagespackage1andpackage2. -
apk del package1 package2: This will remove the packagespackage1andpackage2from 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 packagespackage1andpackage2. -
emerge β unmerge package1 package2: This will remove the packagespackage1andpackage2from the system.
-
-
pkg β Package Manager- A package manager forFreeBSDsystems.
Alright, thatβs 100! Hope you find it helpful. Please let me know what you think.
Top comments (0)