DEV Community

Cover image for Linux: Essential Commands for Software Engineers
Marcio Mendes
Marcio Mendes

Posted on

1

Linux: Essential Commands for Software Engineers

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
Enter fullscreen mode Exit fullscreen mode

cd – Navigate directories:

cd /path/to/directory  # Access a specific directory
cd ..                 # Move up one directory
cd -                  # Return to the previous directory
Enter fullscreen mode Exit fullscreen mode

pwd – Display the absolute path of the current directory:

pwd
Enter fullscreen mode Exit fullscreen mode

mkdir – Create new directories:

mkdir new_directory
mkdir -p folder1/folder2  # Create nested directories
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

find – Search for files and directories:

find /home -name "*.txt"         # Find .txt files in /home
find . -type d -name "projects"  # Find directories named "projects"
Enter fullscreen mode Exit fullscreen mode

locate – Quickly find files by name:

locate file.txt
Enter fullscreen mode Exit fullscreen mode

df – Show disk usage:

df -h  # Display disk usage in a readable format
Enter fullscreen mode Exit fullscreen mode

du – Display file and directory sizes:

du -sh folder/  # Show the total size of a directory
Enter fullscreen mode Exit fullscreen mode

3. Reading and Manipulating Text Files

cat – Display file content:

cat file.txt
Enter fullscreen mode Exit fullscreen mode

less – Navigate large files efficiently:

less file.txt
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

4. Process Management

ps – List running processes:

ps aux
Enter fullscreen mode Exit fullscreen mode

top / htop – Monitor CPU and memory usage in real-time:

top
Enter fullscreen mode Exit fullscreen mode

kill – Terminate processes by ID:

kill -9 1234  # End process with PID 1234
Enter fullscreen mode Exit fullscreen mode

5. Executing Files and Package Management

Running scripts directly:

./script.sh
Enter fullscreen mode Exit fullscreen mode

Running scripts with a specific interpreter:

bash script.sh
python3 script.py
Enter fullscreen mode Exit fullscreen mode

Making HTTP requests with curl:

curl -X POST -H "Content-Type: application/json" -d '{"key":"value"}' https://api.example.com
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

6. User and Permissions Management

Users and superusers:

whoami   # Display the current user
sudo su  # Switch to superuser (root)
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

AWS Q Developer image

Your AI Code Assistant

Generate and update README files, create data-flow diagrams, and keep your project fully documented. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE