MEHDI.
RETURN_TO_INDEX

Linux Commands Every Developer Should Know by Heart

3 min read
#DevOps#Linux#Terminal#Productivity

Introduction

As a developer, having a solid grasp of Linux commands is essential for efficient workflow and troubleshooting. In this article, I will cover the must-know commands for file navigation, text processing, process management, networking basics, and SSH.

File Navigation

To navigate through the file system, you should be familiar with the following commands:

  • cd: change directory. For example, cd ~/Documents will take you to the Documents directory in your home folder.
  • pwd: print working directory. This command displays the current directory path.
  • ls: list files and directories. You can use ls -l for a detailed list or ls -a to include hidden files.
  • mkdir: make a directory. Use mkdir mydirectory to create a new directory.
  • rm: remove files or directories. Be cautious with rm -r as it deletes directories recursively.

Practical Example

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

mkdir myproject && cd myproject

Text Processing

Text processing is a crucial aspect of Linux command-line usage. The following tools are indispensable:

  • grep: global regular expression print. Use grep keyword file.txt to search for a keyword in a file.
  • awk: a programming language for processing data. For example, awk '{print $1}' file.txt prints the first column of a file.
  • sed: stream editor. The command sed 's/old/new/g' file.txt replaces all occurrences of 'old' with 'new' in a file.

Practical Example

To find all lines containing a specific word in a file and save the result to a new file, you can use:

grep keyword file.txt > result.txt

Process Management

Managing processes is vital for system maintenance and troubleshooting:

  • ps: process status. Use ps aux to list all running processes.
  • kill: send a signal to a process. For example, kill 1234 terminates the process with the ID 1234.
  • bg and fg: background and foreground. These commands are used to manage jobs.

Practical Example

To kill a process by name, you can use:

kill $(pgrep processname)

Networking Basics

Understanding basic networking commands is necessary for diagnosing and configuring network settings:

  • ping: test network connectivity. Use ping google.com to check if you can reach a host.
  • ssh: secure shell. The command ssh user@host connects you to a remote host.
  • scp: secure copy. Use scp file.txt user@host:/path to copy a file to a remote host.

Practical Example

To copy a file from a remote host to your local machine, you can use:

scp user@host:/path/file.txt .

SSH

SSH is a secure way to access remote hosts. Key commands include:

  • ssh-keygen: generate a new SSH key pair. Use ssh-keygen -t rsa to create an RSA key.
  • ssh-copy-id: copy the public key to a remote host. The command ssh-copy-id user@host sets up key-based authentication.

Practical Example

To connect to a remote host without entering a password, you can use key-based authentication:

ssh user@host

after setting up the key pair and copying the public key to the host.

Practical Takeaways

  • Familiarize yourself with file navigation commands to efficiently move through the file system.
  • Master text processing tools like grep, awk, and sed for data manipulation.
  • Understand process management commands to control and troubleshoot system processes.
  • Learn basic networking commands for diagnosing and configuring network settings.
  • Use SSH for secure remote access and consider setting up key-based authentication for convenience and security.