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 solid grasp of Linux commands is essential for efficient workflow and troubleshooting. In this article, I will cover the most critical Linux commands that every developer should know by heart.

File Navigation

File navigation is a fundamental aspect of working with Linux. The following commands are essential for navigating the file system:

  • cd: change directory
  • pwd: print working directory
  • ls: list files and directories
  • mkdir: make a directory
  • rmdir: remove a directory
  • touch: create a new file

For example, to create a new directory and navigate into it, you can use the following command:

mkdir myproject && cd myproject

File Permissions

Understanding file permissions is crucial for managing access to files and directories. The following commands are used to manage file permissions:

  • chmod: change file mode
  • chown: change file owner
  • chgrp: change file group

For example, to change the permissions of a file to allow the owner to read, write, and execute, you can use the following command:

chmod 700 myfile

Text Processing

Text processing is a common task in Linux, and the following commands are essential for searching, manipulating, and processing text:

  • grep: search for a pattern in a file
  • awk: pattern scanning and processing language
  • sed: stream editor for filtering and transforming text

For example, to search for a pattern in a file, you can use the following command:

grep 'pattern' myfile

To extract the first column of a CSV file, you can use the following command:

awk -F, '{print $1}' myfile.csv

To replace a pattern in a file, you can use the following command:

sed 's/pattern/replacement/' myfile

Process Management

Process management is critical for managing system resources and troubleshooting issues. The following commands are essential for managing processes:

  • ps: display process information
  • kill: send a signal to a process
  • killall: send a signal to all processes with a given name
  • bg: run a process in the background
  • fg: bring a process to the foreground

For example, to display all running processes, you can use the following command:

ps aux

To kill a process with a given PID, you can use the following command:

kill 1234

Networking Basics

Networking basics are essential for managing network connections and troubleshooting issues. The following commands are critical for managing network connections:

  • ping: test network connectivity
  • ssh: secure shell for remote access
  • scp: secure copy for transferring files
  • netstat: display network statistics

For example, to test network connectivity to a given host, you can use the following command:

ping google.com

To establish a secure shell connection to a remote server, you can use the following command:

ssh user@remote-server

SSH

SSH is a secure protocol for remote access to Linux systems. The following commands are essential for managing SSH connections:

  • ssh-keygen: generate a public/private key pair
  • ssh-copy-id: copy a public key to a remote server
  • ssh-agent: manage SSH agents

For example, to generate a public/private key pair, you can use the following command:

ssh-keygen -t rsa

To copy a public key to a remote server, you can use the following command:

ssh-copy-id user@remote-server

Practical Takeaways

In conclusion, mastering Linux commands is essential for efficient workflow and troubleshooting. By memorizing the commands outlined in this article, you will be able to navigate the file system, process text, manage processes, and establish secure connections to remote servers. Some practical one-liners to keep in mind include:

  • find . -name 'filename': search for a file recursively
  • du -sh *: display the size of all files and directories
  • htop: display system resources and process information
  • ssh user@remote-server 'command': execute a command on a remote server By incorporating these commands into your workflow, you will be able to work more efficiently and effectively as a developer.