DEV Community

Cover image for 100 Commands in Linux Every Developer Should knowπŸ’―πŸŒŸ
Anand Das for Bito

Posted on • Updated on • Originally published at bito.co

100 Commands in Linux Every Developer Should knowπŸ’―πŸŒŸ

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/local 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 mydir in the current working directory.
  4. rmdir β€” Remove an empty directory.
    • rmdir mydir: This will remove the empty directory called mydir from the current working directory.
  5. touch β€” Create a new file.
    • touch myfile.txt: This will create a new, empty file called myfile.txt in the current working directory.
  6. cp β€” Copy a file or directory.
    • cp myfile.txt myfile_copy.txt: This will create a copy of myfile.txt called myfile_copy.txt in the current working directory.
    • cp -r mydir mydir_copy: This will create a copy of the directory mydir called mydir_copy in the current working directory, including all the files and subdirectories in mydir.
  7. mv β€” Move a file or directory.
    • mv myfile.txt mydir: This will move the file myfile.txt from the current working directory to the directory mydir.
    • mv mydir newname: This will rename the directory mydir to newname.
  8. rm β€” Delete a file.
    • rm myfile.txt: This will delete the file myfile.txt from the current working directory.
  9. cat β€” Display the contents of a file.
    • cat myfile.txt: This will display the contents of the file 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 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.
  11. head β€” Display the first few lines of a file.
    • head myfile.txt: This will display the first 10 lines of the file myfile.txt.
    • head -n 5 myfile.txt: This will display the first 5 lines of the file myfile.txt.
  12. tail β€” Display the last few lines of a file.
    • tail myfile.txt: This will display the last 10 lines of the file myfile.txt.
    • tail -n 5 myfile.txt: This will display the last 5 lines of the file myfile.txt.
  13. grep β€” Search for a pattern in a file.
    • grep β€œhello” myfile.txt*: This will search for the pattern β€œhello” in the file 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 a file called myfile.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.
  15. sort β€” Sort the lines of a file.
    • sort myfile.txt: This will sort the lines of the file myfile.txt in alphabetical order.
    • sort -n myfile.txt: This will sort the lines of the file myfile.txt in numerical order.
  16. uniq β€” Remove duplicate lines from a file.
    • uniq myfile.txt: This will remove any duplicate lines from the file myfile.txt.
    • sort -n myfile.txt: This will remove any duplicate lines from the file myfile.txt and print the count of the number of times each line appears in the file.
  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 the file myfile.txt.
    • wc -l myfile.txt: This will print the number of lines in the file 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 the file 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 of file1.txt and file2.txt side by side and print the combined lines.
    • paste -d β€œ,” file1.txt file2.txt: This will combine the lines of file1.txt and file2.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 the file myfile.txt to uppercase and print the translated lines.
    • tr -d β€œ0–9” < myfile.txt : This will translate all lowercase letters in the file myfile.txt to uppercase and print the translated lines.
  21. 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 file myfile.txt and print the resulting lines.
    • sed β€œs/^#//” myfile.txt: This will remove all leading # characters from the beginning of each line in the file 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 the file myfile.txt.
    • awk -F β€œ,” β€˜{print $2}’ myfile.txt: This will print the second field (delimited by a comma) of each line in the file myfile.txt.
  23. tar β€” Create or extract a tarball (a compressed archive file).
    • tar -cvf mydir.tar mydir : This will create a tarball called mydir.tar from the directory mydir.
    • tar -xvf mydir.tar: This will extract the contents of the tarball mydir.tar to the current working directory.
  24. gzip β€” Compress or decompress a file usinggzip.
    • gzip myfile.txt : This will compress the file myfile.txt using gzip, creating a new file called myfile.txt.gz.
    • gunzip myfile.txt.gz : This will decompress the file myfile.txt.gz using gzip, creating a new file called myfile.txt.
  25. bzip2 β€” Compress or decompress a file using bzip2.
    • bzip2 myfile.txt: This will compress the file myfile.txt using bzip2, creating a new file called myfile.txt.bz2.
    • bunzip2 myfile.txt.bz2: This will decompress the file myfile.txt.bz2 using bzip2, creating a new file called myfile.txt.
  26. xz β€” Compress or decompress a file using xz.
    • xz myfile.txt : This will compress the file myfile.txt using xz, creating a new file called myfile.txt.xz.
    • unxz myfile.txt.xz : This will decompress the file myfile.txt.xz using xz, creating a new file called myfile.txt.
  27. zip β€” Compress or decompress a file using zip.
    • zip [myfile.zip](http://myfile.zip/) myfile.txt : This will create a zip archive called [myfile.zip](http://myfile.zip/) from the file myfile.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.
  28. 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 directory mydir.
  29. chown β€” Change the owner and/or group of a file or directory.
    • chown user1 myfile.txt : This will change the owner of the file myfile.txt to user1.
    • chown user1:group1 mydir: This will change the owner of the directory mydir to user1 and the group owner togroup1.
  30. passwd β€” Change the password of a user.
    • passwd : This will prompt the user to enter and confirm a new password.
  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 for user1.
    • 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 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.
  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 the file /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 command history 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”: 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.”
  39. 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 the HOME environment variable.
  40. 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 variable NEWVAR.
  41. unset β€” Unset an environment variable.
    • unset NEWVAR: This will unset the environment variable NEWVAR, removing it from the environment.
  42. set β€” Set shell options.
    • set -o vi: This will set the vi editing mode for the current shell.
    • set -o noclobber: This will set the noclobber option, which prevents the shell from overwriting files with the > operator.
  43. unalias β€” Remove an alias.
    • alias ll=”ls -l”: This will create an alias called ll that is equivalent to the command ls -l.
    • unalias ll: This will remove the alias ll
  44. 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.
  45. . β€” Same as source.
    • [myscript.sh](http://myscript.sh/): This will execute the script [myscript.sh](http://myscript.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 to return to the original shell unless they exit vim.
  47. exit β€” Exit the current shell.
    • exit: This will exit 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 and reboot it in 5 minutes.
  49. reboot β€” Reboot the system.
    • reboot: This will reboot the system immediately.
  50. init β€” Change the system runlevel.
    • init 0: This will shut down the system.
    • init 6: This will reboot the system.
  51. 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 /mntin 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.
  53. 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.
  54. 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 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 group vg01.
  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: his will display information about the logical volume lvol1 in 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 of 10 GB
    • lvcreate -l 100%FREE -n lvol2 vg01: This will create a logical volume called lvol2 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 group vg01 from the system.
    • vgremove vg02 vg03: This will remove the volume groups 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 group vg01 by 5 GB.
    • lvresize -l +100%FREE /dev/vg02/lvol2: This will increase the size of the logical volume lvol2 in the volume group vg02 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 group vg01 by 5 GB.
    • lvreduce -l -100%FREE /dev/vg02/lvol2:This will reduce the size of the logical volume lvol2 in the volume group vg02by 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 label swap01.
  72. 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 label swap01.
  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 label swap01.
  74. chmod β€” Change the permissions of a file or directory.
    • chmod 755 file.txt: This will set the permissions of file .txt to rwxr-xr-x.
    • chmod u+x [file.sh](http://file.sh/):This will add execute permission for the owner of [file.sh](http://file.sh/).
  75. chown β€” Change the owner and/or group of a file or directory.
    • chown user1 file.txt: This will set the owner of file.txt to user1.
    • chown user1:group1 file.txt:This will set the owner of file.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 of file.txt to group1.
    • chgrp -R group1 dir:This will recursively set 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 will set the default permissions for newly created files and directories to rw-r β€” r β€” .
    • umask 077:This will set the default permissions for newly created files and directories to rwx β€” β€” β€”.
  78. su β€” Change the current user.
    • su user1: This will switch the current user to user1.
    • 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 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 user user1.
  80. 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 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 called group1.
    • addgroup β€” system group1: This will create a new system group called group1.
  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 will add the user user1 to the sudo group, allowing the user to execute commands with sudo.
    • delgroup β€” only-if-empty group1: This will lock the user user1 account, preventing the user from logging in.
  86. groupmod β€” Modify a group.
    • groupmod -n group2 group1: This will rename the group group1 to group2.
    • delgroup β€” only-if-empty 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 called user1.
    • useradd -m -s /bin/bash user1: This will create a new user called user1 with a home directory and the bash shell.
  88. userdel β€” Delete a user account.
    • userdel user1: This will delete the user user1 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.
  89. groupadd β€” Create a new group.
    • groupadd group1: This will create a new group called group1.
    • userdel β€” force β€” remove user1: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 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.
  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 will install the packages package1 and package2.
    • apt remove package1 package2:This will remove the packages package1 and package2 from the system.
  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 will install the packages package1 and package2.
    • apt-get remove package1 package2:This will remove 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 all installed packages to their latest versions.
    • yum install package1 package2:This will install the packages package1 and package2.
    • yum remove package1 package2:This will remove 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 all installed packages to their latest versions.
    • dnf install package1 package2:This will install the packages package1 and package2.
    • dnf remove package1 package2:This will remove 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 all installed packages to their latest versions.
    • pacman -S package1 package2:This will install the packages package1 and package2.
    • pacman -R package1 package2:This will remove 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 will install 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 will install 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 will install 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.

Top comments (0)