DEV Community

Kanani Nirav
Kanani Nirav

Posted on • Updated on

50 Linux Commands every developer NEED to know with example

Here are 50 useful Linux commands that every developer should know, along with a brief description and an example of each command:

Buy Linux Commands Cheat Sheet (PDF)

  1. ls - Lists the contents of a directory.

    • Example: ls will list the contents of the current directory. ls /usr/local will list the contents of the /usr/local directory.
  2. pwd - Prints the current working directory.

    • Example: pwd will print the full path of the current working directory.
  3. cd - Changes the current working directory.

    • Example: cd /usr/local will change the current working directory to /usr/local.
  4. mkdir - Creates a new directory.

    • Example: mkdir mydir will create a new directory called mydir.
  5. mv - Moves a file or directory.

    • Example: mv file.txt /usr/local/ will move the file file.txt to the /usr/local directory.
  6. cp - Copies a file or directory.

    • Example: cp file.txt /usr/local/ will copy the file file.txt to the /usr/local directory.
  7. rm - Removes a file or directory.

    • Example: rm file.txt will remove the file file.txt, while rm -r mydir will remove the directory mydir and all of its contents.
  8. touch - Creates a new empty file.

    • Example: touch file.txt will create a new empty file called file.txt.
  9. ln - Creates a link to a file or directory.

    • Example: ln -s /usr/local/file.txt file.txt will create a symbolic link to /usr/local/file.txt called file.txt in the current directory.
  10. cat - Displays the contents of a file.

    • Example: cat file.txt will display the contents of the file file.txt in the terminal.
  11. clear - Clears the terminal screen.

    • Example: clear will clear the contents of the terminal screen.
  12. echo - Prints a message to the terminal.

    • Example: echo "Hello, world!" will print the message "Hello, world!" to the terminal.
  13. less - Views a file with pagination.

    • Example: less file.txt will allow you to view the contents of file.txt one page at a time.
  14. man - Displays the manual page for a command.

    • Example: man ls will display the manual page for the ls command, which describes its usage and options.
  15. uname - Displays information about the current system.

    • Example: uname -a will display all information about the current system, including the kernel version and machine hardware name.
  16. whoami - Displays the current user.

    • Example: whoami will display the username of the current user.
  17. tar - Archives and compresses files and directories.

    • Example: tar -czf archive.tar.gz directory/ will create a compressed archive called archive.tar.gz from the contents of the directory directory.
  18. grep - Searches for a pattern in a file.

    • Example: grep "error" log.txt will search the file log.txt for the pattern "error" and print any lines that match.
  19. head - Displays the first few lines of a file.

    • Example: head -n 10 file.txt will display the first 10 lines of file.txt.
  20. tail - Displays the last few lines of a file.

    • Example: tail -n 10 file.txt will display the last 10 lines of file.txt.
  21. diff - Compares the differences between two files.

    • Example: diff file1.txt file2.txt will compare the contents of file1.txt and file2.txt and print the differences between them.
  22. cmp - Compares the contents of two files byte by byte.

    • Example: cmp file1.txt file2.txt will compare the contents of file1.txt and file2.txt byte by byte and report any differences.
  23. comm - Compares the contents of two sorted files line by line.

    • Example: comm file1.txt file2.txt will compare the contents of file1.txt and file2.txt, which should both be sorted, and print the lines that are unique to each file.
  24. sort - Sorts the lines of a file.

    • Example: sort file.txt will sort the lines of file.txt alphabetically.
  25. export - Exports a shell variable.

    • Example: export VARNAME="value" will create a shell variable called VARNAME with the value "value".
  26. zip - Compresses files into a ZIP archive.

    • Example: zip archive.zip file1.txt file2.txt will create a ZIP archive called archive.zip containing the files file1.txt and file2.txt.
  27. unzip - Extracts files from a ZIP archive.

    • Example: unzip archive.zip will extract the contents of the archive.zip ZIP archive.
  28. ssh - Connects to a remote server using the SSH protocol.

    • Example: ssh user@example.com will connect to the server at example.com as the user user.
  29. service - Controls system services.

    • Example: service apache2 start will start the Apache web server.
  30. ps - Displays information about running processes.

    • Example: ps aux will display a list of all running processes and their resource usage.
  31. kill - Sends a signal to a process to terminate it.

    • Example: kill 12345 will send the signal to terminate the process with the process ID 12345.
  32. killall - Terminates all processes with a specified name.

    • Example: killall firefox will terminate all processes with the name firefox.
  33. df - Displays information about available disk space on mounted filesystems.

    • Example: df -h will display the available disk space in a human-readable format (e.g., in gigabytes or megabytes).
  34. mount - Mounts a filesystem.

    • Example: mount /dev/sda1 /mnt/mydisk will mount the partition /dev/sda1 at the mount point /mnt/mydisk.
  35. chmod - Changes the permissions of a file or directory.

    • Example: chmod 755 file.txt will give read, write, and execute permissions to the owner and read and execute permissions to everyone else for the file file.txt.
  36. chown - Changes the ownership of a file or directory.

    • Example: chown user:group file.txt will change the owner of file.txt to user and the group ownership to group.
  37. ifconfig - Configures network interface parameters.

    • Example: ifconfig eth0 up will enable the network interface eth0.
  38. traceroute - Traces the path of packets to a destination.

    • Example: traceroute example.com will trace the path of packets from the current system to the destination example.com.
  39. wget - Downloads a file from the internet.

    • Example: wget https://example.com/file.zip will download the file file.zip from https://example.com.
  40. ufw - A frontend for managing a firewall.

    • Example: ufw allow ssh will allow incoming connections to the SSH service.
  41. iptables - A firewall management tool for Linux.

    • Example: iptables -A INPUT -p tcp --dport 80 -j ACCEPT will allow incoming connections to TCP port 80 (the default port for HTTP).
  42. apt - A package manager for Debian-based systems.

    • Example: apt update will update the list of available packages.
  43. sudo - Allows a user to run a command with the privileges of the superuser (root).

    • Example: sudo apt update will update the list of available packages with root privileges.
  44. cal - Displays a calendar.

    • Example: cal will display the current month's calendar.
  45. alias - Creates an alias for a command.

    • Example: alias ll='ls -alF' will create an alias ll that runs the command ls -alF.
  46. dd - Copies data from one location to another.

    • Example: dd if=/dev/sda of=disk.img will create an image file called disk.img of the contents of the device /dev/sda.
  47. whereis - Shows the locations of a command.

    • Example: whereis ls will show the locations of the ls command on the system.
  48. whatis - Shows a short description of a command.

    • Example: whatis ls will show a short description of the ls command.
  49. top - Displays information about running processes.

    • Example: top will display a list of running processes and their resource usage in real-time.
  50. passwd - Changes the password for a user.

    • Example: passwd user1 will prompt you to enter and confirm a new password for the user user1.

More details about a specific command can be found by following the link below:

Bash URL: https://linux.die.net/man/1/change_command_name

For example, to view the man page for the ls command, you can follow this link: https://linux.die.net/man/1/ls

The man page for a command includes a comprehensive reference guide for that specific command or utility, which is available on a Linux or Unix-like operating system. It includes a description of the command and its options, as well as examples of how to use the command. It may also include information about the command's syntax, return values, and any errors that may occur when the command is used.

You can access the man page for a command by typing man followed by the name of the command at the command prompt. The man pages are organized into sections, with each section covering a specific topic. The first section numbered 1, contains commands that are available to all users. The second section numbered 2, contains system calls, which are functions provided by the operating system's kernel that allow programs to request services from the kernel. The third section numbered 3, contains library functions, which are functions provided by libraries that are used by programs.

If You are using Medium Please support and follow me for interesting articles. Medium Profile

If this guide has been helpful to you and your team please share it with others!

Top comments (7)

Collapse
 
tempestrock profile image
Tempest Rock

Nice list!
Would be good maybe to mention umount and which. I find which -a (e.g. which -a bash) helpful to find out if I have multiple installations of the same tool in different directories.

Collapse
 
jonrandy profile image
Jon Randy 🎖️

touch is actually for updating the last modification date of the given file. The fact that it creates the file if it does not exist is merely a useful side effect

Collapse
 
kanani_nirav profile image
Kanani Nirav

That is correct. The touch command is primarily used to update the timestamps (i.e., the last modification date and the last access date) of a file. If the file does not exist, touch will create an empty file with the specified name.

Collapse
 
osahenru profile image
Osahenru

very insightful

Collapse
 
imkrunalkanojiya profile image
Krunal Kanojiya

Nice Job!

Collapse
 
cedricjacquot profile image
Cédric

Very useful, Thanks !

Collapse
 
umangnaik profile image
umangnaik

A Perfect List You have covered most of the basics command that every developer should know.
Thank you....
Keep it up @kanani_nirav