MEHDI.
RETURN_TO_INDEX

Linux Commands Every Developer Should Know by Heart

4 min read
#DevOps#Linux#Terminal#Productivity

Introduction

As a developer, I have found that having a strong grasp of Linux commands is essential for efficient workflow and troubleshooting. In this article, I will cover the essential Linux commands that every developer should know by heart, including file navigation, text processing, process management, networking basics, and SSH.

File Navigation

Mastering file navigation is crucial for any developer working with Linux. The following commands are must-knows:

  • cd: change directory. For example, cd Documents will take you to the Documents directory.
  • pwd: print working directory. This command displays the current directory path.
  • ls: list files and directories. The -l option displays detailed information about each file, including permissions, owner, and timestamp.
  • mkdir: make a directory. For example, mkdir NewFolder will create a new directory named NewFolder.
  • rm: remove files or directories. The -r option is used to remove directories and their contents.

Practical Example

To create a new directory and navigate into it, you can use the following one-liner:

mkdir NewProject && cd NewProject

This command creates a new directory named NewProject and immediately navigates into it.

Text Processing

Text processing is a fundamental aspect of Linux command-line programming. The following commands are essential:

  • grep: global regular expression print. This command is used to search for patterns in text files. For example, grep 'error' log.txt will display all lines in log.txt that contain the word 'error'.
  • awk: a powerful text processing language. For example, awk '{print $1}' file.txt will print the first column of file.txt.
  • sed: stream editor. This command is used to perform text transformations. For example, sed 's/old/new/g' file.txt will replace all occurrences of 'old' with 'new' in file.txt.

Practical Example

To extract all email addresses from a text file, you can use the following one-liner:

grep -oE '[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,}' file.txt

This command uses grep with a regular expression to extract all email addresses from file.txt.

Process Management

Process management is critical for developers to monitor and control system resources. The following commands are must-knows:

  • ps: process status. This command displays information about running processes. The -ef option displays all processes in standard syntax.
  • kill: kill a process. For example, kill 1234 will terminate the process with PID 1234.
  • bg: run a process in the background. For example, mycommand & will run mycommand in the background.
  • fg: bring a process to the foreground. For example, fg %1 will bring the first background process to the foreground.

Practical Example

To kill all processes that match a certain pattern, you can use the following one-liner:

pkill -f pattern

This command uses pkill with the -f option to kill all processes that match the specified pattern.

Networking Basics

Networking basics are essential for developers to configure and troubleshoot network connections. The following commands are must-knows:

  • ip: display and manage network interfaces. For example, ip addr show will display information about all network interfaces.
  • ping: test network connectivity. For example, ping google.com will test connectivity to google.com.
  • ssh: secure shell. This command is used to establish secure connections to remote servers. For example, ssh user@remote-server will establish a secure connection to remote-server as user.

Practical Example

To scan for open ports on a remote server, you can use the following one-liner:

nmap -sT remote-server

This command uses nmap with the -sT option to perform a TCP connect scan on remote-server.

SSH

SSH is a fundamental tool for developers to manage remote servers. The following commands are essential:

  • ssh-keygen: generate SSH keys. For example, ssh-keygen -t rsa will generate a new RSA key pair.
  • ssh-copy-id: copy SSH keys to a remote server. For example, ssh-copy-id user@remote-server will copy the public key to remote-server.

Practical Example

To establish a secure connection to a remote server using SSH keys, you can use the following one-liner:

ssh -i private-key user@remote-server

This command uses ssh with the -i option to specify the private key file.

Practical Takeaways

  • Mastering Linux commands is essential for efficient workflow and troubleshooting.
  • File navigation, text processing, process management, networking basics, and SSH are fundamental aspects of Linux command-line programming.
  • One-liners can be used to perform complex tasks with a single command.
  • Practice and repetition are key to committing these commands to memory.