Linux Commands Every Developer Should Know by Heart
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 ~/Documentswill 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 usels -lfor a detailed list orls -ato include hidden files.mkdir: make a directory. Usemkdir mydirectoryto create a new directory.rm: remove files or directories. Be cautious withrm -ras 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. Usegrep keyword file.txtto search for a keyword in a file.awk: a programming language for processing data. For example,awk '{print $1}' file.txtprints the first column of a file.sed: stream editor. The commandsed 's/old/new/g' file.txtreplaces 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. Useps auxto list all running processes.kill: send a signal to a process. For example,kill 1234terminates the process with the ID 1234.bgandfg: 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. Useping google.comto check if you can reach a host.ssh: secure shell. The commandssh user@hostconnects you to a remote host.scp: secure copy. Usescp file.txt user@host:/pathto 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. Usessh-keygen -t rsato create an RSA key.ssh-copy-id: copy the public key to a remote host. The commandssh-copy-id user@hostsets 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.