Common Linux Commands

Linux runs a large share of the world’s servers, cloud infrastructure, and production systems. For developers, system administrators, and DevOps engineers, the command line is not just a convenience. It is where much of the real work happens.

Although graphical interfaces exist, many tasks are faster, repeatable, and automatable through the shell. Learning a focused set of Linux commands can significantly improve daily efficiency and make troubleshooting much easier.

In Linux, the filesystem is organized like a tree. Understanding paths and directory operations is often the first practical step.

  • pwd prints the current working directory as an absolute path.
  • ls lists directory contents. Useful options include:
    • -l for long format with details.
    • -a to show hidden files.
    • -h for human-readable file sizes.
  • cd changes the working directory. Common forms:
    • cd /var/log moves into the log directory.
    • cd ~ returns to the current user’s home directory.
    • cd .. moves to the parent directory.
  • mkdir creates a directory. Use -p to create nested directories, such as mkdir -p /app/logs/2023.
  • cp copies files or directories. Add -r when copying a directory.
  • mv moves or renames files and directories.
  • rm removes files or directories. Use -r for directories and -f to force removal. Be careful with rm -rf.

Viewing and Searching Files

Once you know how to move around, you often need to inspect files and locate specific content.

  • cat displays file contents. It works well for small files.
  • less opens files in a pager. Use Space to scroll down, b to scroll up, and /keyword to search forward.
  • head and tail show file beginnings or endings. For example, head -n 20 file.txt shows the first 20 lines, while tail -n 50 file.txt shows the last 50.
  • tail -f /var/log/syslog follows a log file in real time. This is a common tool when debugging issues.
  • grep searches file content. For example, grep "ERROR" app.log finds lines containing ERROR. Useful options include -i, -n, and -v.

Monitoring Processes and System Resources

System administrators regularly check CPU, memory, processes, and disk usage.

  • ps shows a snapshot of running processes. A common combination is ps aux.
  • top and htop provide real-time resource monitoring. In top, you can press k and enter a process ID to terminate a process.
  • df shows disk space usage. df -h uses human-readable sizes.
  • du estimates disk usage. For example, du -sh /var/log shows the total size of a directory.
  • free shows memory usage. free -h presents it in human-readable form.

Network and Communication Commands

Network troubleshooting is a routine part of Linux work.

  • ping tests connectivity. For example, ping -c 4 www.baidu.com sends four packets before stopping.
  • curl and wget handle HTTP requests and downloads. curl -I https://www.example.com shows response headers, while wget https://example.com/file.zip downloads a file.
  • netstat or ss displays network information. A useful command is ss -tuln to view listening ports.

Permissions and User Management

Linux is multi-user and permission-aware.

  • chmod changes file or directory permissions. For example, chmod 755 script.sh gives the owner read, write, and execute permissions, while the group and others get read and execute.
  • chown changes ownership and group. For example, chown -R www:www /var/www/html recursively assigns an owner and group.
  • sudo runs a command with superuser privileges. Prefix a command with sudo when needed.

Building Practical Confidence

The commands above cover a useful starting point, but real-world work often involves combining them with text editors, package managers, service commands, and scripting tools.

To become comfortable, practice in a safe environment. Use man pages, test options, and build small scripts. Over time, these commands move from conscious effort to muscle memory.