Introduction
Hey everyone, how’s it going?
In this article, I’ll cover some simple yet incredibly impactfull Linux commands that every software engineer should know.
Mastering the Linux command line is crucial for developers of all experience levels. The terminal gives you full control over your environment, enabling automation, process management, file handling, and much more.
So, here’s a guide showcasing the most important commands every programmer should know to boost productivity.
Let’s dive in!
1. File and Directory Management
ls
– List files and directories with details:
ls -l # Displays file details, like permissions and ownership
ls -la # Displays all files, including hidden ones
ls -lh # Shows file sizes in human-readable format
ls -ltr # Lists files sorted by modification date
cd
– Navigate directories:
cd /path/to/directory # Access a specific directory
cd .. # Move up one directory
cd - # Return to the previous directory
pwd
– Display the absolute path of the current directory:
pwd
mkdir
– Create new directories:
mkdir new_directory
mkdir -p folder1/folder2 # Create nested directories
rm
– Remove files and directories:
rm file.txt # Remove a file
rm -r directory/ # Remove a directory and its contents
rm -f file.txt # Remove a file without confirmation
2. Everyday Useful Commands
touch
– Create empty files or update modification dates:
touch file.txt # Create an empty file
touch -t 202401010101 file.txt # Set modification date to Jan 1, 2024
find
– Search for files and directories:
find /home -name "*.txt" # Find .txt files in /home
find . -type d -name "projects" # Find directories named "projects"
locate
– Quickly find files by name:
locate file.txt
df
– Show disk usage:
df -h # Display disk usage in a readable format
du
– Display file and directory sizes:
du -sh folder/ # Show the total size of a directory
3. Reading and Manipulating Text Files
cat
– Display file content:
cat file.txt
less
– Navigate large files efficiently:
less file.txt
grep
– Search and filter patterns in files:
grep "term" file.txt # Return lines containing "term"
grep -i "term" file.txt # Ignore case differences
grep -r "error" /var/log/ # Recursively search directories
awk
– Process and extract text columns:
awk '{print $1}' file.txt # Display the first word of each line
awk -F: '{print $1, $3}' /etc/passwd # Show user and UID from a password file
sed
– Programmatically edit files:
sed 's/old_word/new_word/g' file.txt # Replace all occurrences in a file
sed -n '2,4p' file.txt # Show only lines 2 to 4
4. Process Management
ps
– List running processes:
ps aux
top
/ htop
– Monitor CPU and memory usage in real-time:
top
kill
– Terminate processes by ID:
kill -9 1234 # End process with PID 1234
5. Executing Files and Package Management
Running scripts directly:
./script.sh
Running scripts with a specific interpreter:
bash script.sh
python3 script.py
Making HTTP requests with curl
:
curl -X POST -H "Content-Type: application/json" -d '{"key":"value"}' https://api.example.com
Package management with dpkg
(Debian-based distros):
dpkg -i package.deb # Install a package
dpkg -r package # Remove a package
dpkg -l | grep name # List installed packages filtered by name
6. User and Permissions Management
Users and superusers:
whoami # Display the current user
sudo su # Switch to superuser (root)
Managing permissions:
chmod 755 script.sh # Grant execution permission to owner and read to others
ls -l script.sh # Show file permissions as rwxr-xr-x
Using symbols to set permissions:
chmod u+x script.sh # Add execution permission for owner
chmod go-r file.txt # Remove read permission for group and others
chmod u+w file.txt # Add write permission for owner
chmod a+r file.txt # Grant read permission to everyone
Using numbers to set permissions:
chmod 755 script.sh # Owner: read/write/execute (7), Group/Others: read/execute (5)
chmod 644 file.txt # Owner: read/write (6), Group/Others: read (4)
chmod 777 script.sh # Full permissions for everyone
7. Managing Compressed Files and File Transfers
Creating and handling compressed files:
tar -cvf archive.tar file1.txt file2.txt # Create a tar archive
tar -czvf archive.tar.gz file1.txt file2.txt # Create a gzip-compressed tar file
tar -xvf archive.tar # Extract tar files
tar -xzvf archive.tar.gz # Extract tar.gz files
Compressing and decompressing with gzip
and gunzip
:
gzip file.txt # Compress file.txt to file.txt.gz
gunzip file.txt.gz # Decompress file.txt.gz
Unzipping .zip
files:
unzip file.zip # Extract the contents of file.zip
unzip file.zip -d /path/to/dir # Extract to a specific directory
unzip -l file.zip # List files in a zip archive
Connecting to a remote server with ssh
:
ssh user@server.com # Connect to a remote server
ssh -p 2222 user@server.com # Connect using a specific port
ssh user@server.com 'ls -l /path' # Run a command on the remote server
8. Using Aliases to Boost Productivity
Creating an alias:
alias ll='ls -lh' # Create an alias for detailed and readable file listing
alias gs='git status' # Create an alias for "git status"
Making aliases permanent:
nano ~/.bashrc # For Bash
nano ~/.zshrc # For Zsh
alias ll='ls -lh' # Add your alias to the file
source ~/.bashrc # Apply changes for Bash
source ~/.zshrc # Apply changes for Zsh
Conclusion
Thanks for read this Article, I hope you found this guide helpful.
Feel free to suggest other essential commands, and let’s keep learning together.
By the way, if you're interested, check out my other article:
GitHub Repositories Every Software Engineer Should Know.
It's packed with resources to level up your skills!
Thanks again, and see you in the next one!
References
- Linux Command Line Basics - Linux Foundation
- https://www.stationx.net/linux-command-line-cheat-sheet/
- https://www.geeksforgeeks.org/basic-linux-commands/
- https://linuxcommand.org/lc3_man_page_index.php
- The Linux Command Line: A Complete Introduction* by William E. Shotts Jr.
- https://ubuntu.com/tutorials/command-line-for-beginners
- https://help.ubuntu.com/community/FilePermissions
- https://help.ubuntu.com/community/UsingTheTerminal#Commands
Top comments (0)