Linux: Top used commands

Nischal ChudalNischal Chudal
10 min read

This are the most used command in the field of DevOps. Before moving towards any other tools and technologies one should know how to implement these commands in the Linux Terminal.

Basic Commands

  1. pwd: Print working directory.

    • Example: pwd (Displays the current directory path).
  2. ls: List directory contents.

    • Example: ls -l (Lists files in long format).
  3. cd: Change directory.

    • Example: cd /home/user (Changes to the /home/user directory).
  4. mkdir: Make directories.

    • Example: mkdir mydir (Creates a directory named mydir).
  5. rmdir: Remove empty directories.

    • Example: rmdir mydir (Removes the directory named mydir).
  6. rm: Remove files or directories.

    • Example: rm -r mydir (Removes directory mydir and its contents).
  7. cp: Copy files or directories.

    • Example: cp file1 file2 (Copies file1 to file2).
  8. mv: Move/rename files or directories.

    • Example: mv file1 newfile1 (Renames/moves file1 to newfile1).
  9. touch: Create an empty file or update the timestamp of a file.

    • Example: touch newfile (Creates an empty file named newfile).
  10. cat: Concatenate and display file content.

    • Example: cat file1 (Displays the content of file1).
  11. echo: Display a line of text.

    • Example: echo "Hello, World!" (Prints "Hello, World!" to the terminal).
  12. less: View file content one screen at a time.

    • Example: less file1 (Views the content of file1 page by page).
  13. more: View file content one screen at a time.

    • Example: more file1 (Displays the content of file1 page by page).
  14. head: Output the first part of a file.

    • Example: head -n 5 file1 (Displays the first 5 lines of file1).
  15. tail: Output the last part of a file.

    • Example: tail -n 5 file1 (Displays the last 5 lines of file1).
  16. grep: Search text using patterns.

    • Example: grep "hello" file1 (Searches for "hello" in file1).
  17. find: Search for files in a directory hierarchy.

    • Example: find /home -name file1 (Searches for file1 in /home).
  18. locate: Find files by name.

    • Example: locate file1 (Finds file1 in the filesystem).
  19. which: Locate a command.

    • Example: which ls (Shows the path of the ls command).
  20. man: Display the user manual of a command.

    • Example: man ls (Displays the manual for the ls command).
  21. chmod: Change file permissions.

    • Example: chmod 755 file1 (Sets the permissions of file1 to 755).
  22. chown: Change file owner and group.

    • Example: chown user1:group1 file1 (Changes the owner and group of file1).
  23. df: Report file system disk space usage.

    • Example: df -h (Displays disk space usage in a human-readable format).
  24. du: Estimate file space usage.

    • Example: du -sh /home/user (Displays the size of the /home/user directory).
  25. ps: Report a snapshot of current processes.

    • Example: ps aux (Displays all running processes).
  26. top: Display Linux tasks.

    • Example: top (Displays real-time system information).
  27. kill: Send a signal to a process.

    • Example: kill 1234 (Sends the default signal to process 1234).
  28. killall: Kill processes by name.

    • Example: killall firefox (Kills all firefox processes).
  29. ping: Send ICMP ECHO_REQUEST to network hosts.

  30. wget: Non-interactive network downloader.


Intermediate Commands

  1. scp: Secure copy (remote file copy program).

    • Example: scp file1 user@remote:/path (Copies file1 to a remote server).
  2. ssh: OpenSSH client (remote login program).

  3. rsync: Remote file and directory synchronization.

    • Example: rsync -av /src /dest (Synchronizes /src to /dest).
  4. tar: Archive files.

    • Example: tar -cvf myarchive.tar mydir (Creates a tar archive of mydir).
  5. gzip: Compress files.

    • Example: gzip file1 (Compresses file1).
  6. gunzip: Decompress files.

    • Example: gunzip file1.gz (Decompresses file1.gz).
  7. zip: Package and compress files.

    • Example: zip myarchive.zip mydir (Creates a zip archive of mydir).
  8. unzip: Extract compressed files.

  9. curl: Transfer data from or to a server.

  10. nano: Simple text editor.

    • Example: nano file1 (Opens file1 in the nano editor).
  11. vim: Advanced text editor.

    • Example: vim file1 (Opens file1 in the vim editor).
  12. crontab: Schedule commands to run at a later time.

    • Example: crontab -e (Edits the current user's cron jobs).
  13. systemctl: Control the systemd system and service manager.

    • Example: systemctl start nginx (Starts the nginx service).
  14. journalctl: Query the systemd journal.

    • Example: journalctl -xe (Displays system logs).
  15. hostname: Show or set the system's hostname.

    • Example: hostname (Displays the current hostname).
  16. ifconfig: Configure a network interface.

    • Example: ifconfig eth0 (Displays the configuration of eth0).
  17. netstat: Print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.

    • Example: netstat -an (Displays all active network connections).
  18. ss: Utility to investigate sockets.

    • Example: ss -tuln (Displays listening sockets).
  19. iptables: Administration tool for IPv4 packet filtering and NAT.

    • Example: iptables -L (Lists the current iptables rules).
  20. ufw: Uncomplicated Firewall, a frontend for iptables.

    • Example: ufw enable (Enables the firewall).
  21. useradd: Create a new user or update default new user information.

    • Example: useradd john (Creates a new user named john).
  22. usermod: Modify a user account.

    • Example: usermod -aG sudo john (Adds john to the sudo group).
  23. userdel: Delete a user account and related files.

    • Example: userdel john (Deletes the user named john).
  24. groupadd: Create a new group.

    • Example: groupadd developers (Creates a new group named developers).
  25. groupdel: Delete a group.

    • Example: groupdel developers (Deletes the group named developers).
  26. passwd: Change user password.

    • Example: passwd john (Changes the password for john).
  27. su: Substitute user identity.

    • Example: su root (Switches to the root user).
  28. sudo: Execute a command as another user.

    • Example: sudo apt update (Runs apt update with superuser privileges).
  29. alias: Create an alias for a command.

    • Example: alias ll='ls -la' (Creates an alias ll for ls -la).
  30. unalias: Remove an alias.

    • Example: unalias ll (Removes the ll alias).

Advanced Commands

  1. awk: Pattern scanning and processing language.

    • Example: awk '{print $1}' file1 (Prints the first column of file1).
  2. sed: Stream editor for filtering and transforming text.

    • Example: sed 's/hello/hi/g' file1 (Replaces all occurrences of "hello" with "hi" in file1).
  3. xargs: Build and execute command lines from standard input.

    • Example: echo file1 file2 | xargs rm (Removes file1 and file2).
  4. cut: Remove sections from each line of files.

    • Example: cut -d':' -f1 /etc/passwd (Displays the first field from /etc/passwd).
  5. sort: Sort lines of text files.

    • Example: sort file1 (Sorts the lines in file1).
  6. uniq: Report or omit repeated lines.

    • Example: uniq file1 (Removes duplicate lines in file1).
  7. tr: Translate or delete characters.

    • Example: tr 'a-z' 'A-Z' (Converts lowercase to uppercase).
  8. wc: Print newline, word, and byte counts for each file.

    • Example: wc -l file1 (Counts the number of lines in file1).
  9. tee: Read from standard input and write to standard output and files.

    • Example: echo "hello" | tee file1 (Writes "hello" to file1 and standard output).
  10. diff: Compare files line by line.

    • Example: diff file1 file2 (Displays differences between file1 and file2).
  11. cmp: Compare two files byte by byte.

    • Example: cmp file1 file2 (Displays the first byte difference between file1 and file2).
  12. comm: Compare two sorted files line by line.

    • Example: comm file1 file2 (Displays common lines between file1 and file2).
  13. bc: An arbitrary precision calculator language.

    • Example: echo "2+2" | bc (Calculates 2+2).
  14. expr: Evaluate expressions.

    • Example: expr 2 + 2 (Calculates 2+2).
  15. factor: Display prime factors of numbers.

    • Example: factor 12 (Displays factors of 12).
  16. seq: Print a sequence of numbers.

    • Example: seq 1 10 (Displays numbers from 1 to 10).
  17. date: Display or set the system date and time.

    • Example: date (Displays the current date and time).
  18. cal: Display a calendar.

    • Example: cal (Displays the current month’s calendar).
  19. uptime: Tell how long the system has been running.

    • Example: uptime (Displays the system uptime).
  20. uname: Print system information.

    • Example: uname -a (Displays all system information).
  21. dmesg: Print or control the kernel ring buffer.

    • Example: dmesg (Displays kernel messages).
  22. lsblk: List information about block devices.

    • Example: lsblk (Displays information about block devices).
  23. fdisk: Partition table manipulator for Linux.

    • Example: fdisk -l (Lists partition tables).
  24. mkfs: Build a Linux file system.

    • Example: mkfs.ext4 /dev/sda1 (Formats /dev/sda1 as ext4).
  25. mount: Mount a file system.

    • Example: mount /dev/sda1 /mnt (Mounts /dev/sda1 to /mnt).
  26. umount: Unmount file systems.

    • Example: umount /mnt (Unmounts the /mnt directory).
  27. fsck: File system consistency check and repair.

    • Example: fsck /dev/sda1 (Checks and repairs the /dev/sda1 file system).
  28. blkid: Locate/print block device attributes.

    • Example: blkid (Displays block device attributes).
  29. parted: A partition manipulation program.

    • Example: parted /dev/sda (Starts the parted utility for /dev/sda).
  30. lsof: List open files.

    • Example: lsof /dev/sda1 (Displays open files on /dev/sda1).
  31. iostat: Report CPU and I/O statistics.

    • Example: iostat (Displays CPU and I/O statistics).
  32. vmstat: Report virtual memory statistics.

    • Example: vmstat (Displays virtual memory statistics).
  33. sar: Collect, report, or save system activity information.

    • Example: sar -u 1 3 (Displays CPU usage statistics 3 times at 1-second intervals).
  34. mpstat: Report per-processor or per-core statistics.

    • Example: mpstat (Displays per-processor statistics).
  35. ip: Show/manipulate routing, devices, policy routing, and tunnels.

    • Example: ip addr show (Displays IP addresses).
  36. ethtool: Display or change Ethernet device settings.

    • Example: ethtool eth0 (Displays settings of eth0).
  37. iwconfig: Configure wireless network interfaces.

    • Example: iwconfig wlan0 (Displays settings of wlan0).
  38. nmcli: Command-line client for NetworkManager.

    • Example: nmcli dev status (Displays the status of network devices).
  39. nmap: Network exploration tool and security/port scanner.

    • Example: nmap -sP 192.168.1.0/24 (Scans the 192.168.1.0/24 subnet for live hosts).
  40. traceroute: Print the route packets take to the network host. - Example: traceroute google.com (Displays the route to google.com).


Specialized Commands

  1. docker: Manage Docker containers. - Example: docker ps (Lists running Docker containers).

  2. kubectl: Manage Kubernetes clusters. - Example: kubectl get pods (Lists Kubernetes pods).

  3. helm: Manage Helm charts (Kubernetes applications). - Example: helm install myapp (Installs a Helm chart named myapp).

  4. minikube: Run Kubernetes locally. - Example: minikube start (Starts a local Kubernetes cluster).

  5. terraform: Infrastructure as Code tool. - Example: terraform apply (Applies Terraform configurations).

  6. ansible: Automation tool for managing configurations. - Example: ansible-playbook myplaybook.yml (Runs an Ansible playbook).

  7. vagrant: Tool for building and managing virtualized development environments. - Example: vagrant up (Starts the virtual environment).

  8. packer: Create machine images for multiple platforms. - Example: packer build template.json (Builds an image from the template).

  9. vault: Manage secrets and protect sensitive data. - Example: vault kv get secret/mysecret (Retrieves a secret from Vault).

  10. consul: Service discovery and configuration tool. - Example: consul members (Lists members of the Consul cluster).

  11. jenkins: Automation server for building CI/CD pipelines. - Example: jenkins-cli build myjob (Triggers a build of the job named myjob).

  12. git: Distributed version control system. - Example: git clone https://github.com/user/repo (Clones a repository).

  13. svn: Centralized version control system. - Example: svn checkout https://svnrepo.com/repo (Checks out a repository).

  14. cvs: Concurrent Versions System. - Example: cvs checkout mymodule (Checks out a module).

  15. bzr: Bazaar version control system. - Example: bzr branch https://bzrrepo.com/repo (Creates a branch of a repository).

  16. mercurial: Another distributed version control system. - Example: hg clone https://hgrepo.com/repo (Clones a repository).

  17. pip: Python package installer. - Example: pip install numpy (Installs the numpy package).

  18. npm: Node.js package manager. - Example: npm install express (Installs the express package).

  19. yarn: Another Node.js package manager. - Example: yarn add express (Adds the express package).

  20. brew: Package manager for macOS. - Example: brew install wget (Installs wget on macOS).

  21. apt: Package manager for Debian-based systems. - Example: apt install htop (Installs htop on Debian-based systems).

  22. yum: Package manager for RPM-based systems. - Example: yum install htop (Installs htop on RPM-based systems).

  23. dnf: Another package manager for RPM-based systems. - Example: dnf install htop (Installs htop on RPM-based systems).

  24. zypper: Package manager for SUSE-based systems. - Example: zypper install htop (Installs htop on SUSE-based systems).

  25. pacman: Package manager for Arch-based systems. - Example: pacman -S htop (Installs htop on Arch-based systems).

  26. snap: Package management system for Linux. - Example: snap install vscode (Installs Visual Studio Code).

Even though these are many commands but learning is fun right. It is better to learn these because you may need in somedays while troubleshooting system .

I hope this blog is helpful to you. It may have some specialized commands but i know you can do it.

1
Subscribe to my newsletter

Read articles from Nischal Chudal directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Nischal Chudal
Nischal Chudal

HI i am a cloud computing aspirant. I am on journey to excel in the field of cloud computing by continuously learning and implementing my new cloud tools and technologies.