Linux Aliases You Didn’t Know You Needed: Practical Shortcuts for Every User
Welcome back to our deep dive into Linux shell aliases! In our previous article, we explored the basics of aliases and how they can streamline your workflow by creating shortcuts for repetitive commands.
Now, we’re taking it a step further by introducing more powerful and useful aliases tailored for both novice and advanced Linux users.
This guide will walk you through each alias featured in the image, explaining how to use it and the specific situations where it shines.
Let’s get into it!
Navigating Directories with Ease
alias ..="cd .."
- Description: Moves up one directory level.
- Use Case: Instead of typing
cd ..
each time, you can simply use..
to move up a level in your directory structure. This is especially helpful when you're navigating through deeply nested directories.
alias ...="cd ../.."
- Description: Moves up two directory levels.
- Use Case: This alias lets you quickly jump two levels up in your file hierarchy, saving you time and keystrokes.
alias ....="cd ../../.."
- Description: Moves up three directory levels.
- Use Case: If you’re several layers deep in directories, this shortcut quickly takes you three levels up without needing to type each
../
.
Efficient Directory Listing
alias ll="ls -al --color=auto"
- Description: Lists files with detailed information, including permissions, ownership, and size, and applies color coding.
- Use Case: The
ls -al
command provides more file details than a simplels
, making it perfect for checking permissions and file sizes at a glance.
alias lt="ls -ltr"
- Description: Lists files sorted by modification time in increasing order.
- Use Case: This is particularly useful when you want to view files based on the most recent modifications, with the oldest at the top and the newest at the bottom.
Creating and Removing Files & Directories
mkd() { mkdir -p "$1" && cd "$1"; }
- Description: Creates a new directory and immediately navigates into it.
- Use Case: Perfect for quickly setting up a new directory and moving into it without typing two separate commands.
alias rm="rm -i"
- Description: Prompts for confirmation before deleting files.
- Use Case: Adds a layer of protection to prevent accidental deletions, which is invaluable when working with important files.
Disk and Memory Usage Check
alias du="du -ch --max-depth=1"
- Description: Summarizes disk usage by directory at a one-level depth.
- Use Case: This alias helps you analyze disk usage for each directory in the current path, making it easier to identify space hogs.
alias mem="free -h"
- Description: Summarizes memory usage in a human-readable format.
- Use Case: Quickly check how much memory is being used and how much is available, formatted for easy readability.
System Performance Monitoring
alias topcpu="ps -eo pid,cmd,%mem,%cpu --sort=-%cpu | head"
- Description: Lists processes using the most CPU resources.
- Use Case: Ideal for troubleshooting performance issues when the system is under heavy load.
alias topmem="ps -eo pid,cmd,%mem,%cpu --sort=-%mem | head"
- Description: Lists processes using the most memory resources.
- Use Case: Use this alias to identify memory-hogging processes, useful in diagnosing slow performance due to memory limitations.
Finding Processes and Files
alias psg="ps aux | grep -v grep | grep -i"
- Description: Searches for running processes by keyword.
- Use Case: Quickly find specific processes without including the
grep
command itself in the search results, helpful for process management and debugging.
alias f="find . -type f -name"
- Description: Finds files by name in the current directory and subdirectories.
- Use Case: Quickly locate files with a specific name in the current directory tree. It’s a faster alternative to typing out the full
find
command.
Enhanced Search and Reload Configurations
alias grep="grep --color=auto -i"
- Description: Runs case-insensitive
grep
with colorized output for matched terms. - Use Case: Highlighted search results improve visibility when searching through logs or code.
alias rreload="source ~/.bashrc"
- Description: Reloads the shell configuration.
- Use Case: After making changes to
.bashrc
, this alias allows you to reload the configuration without restarting the terminal.
alias hgrep="history | grep"
- Description: Searches through shell command history.
- Use Case: Helps you locate previously used commands that contain specific keywords, perfect for recalling long or complex commands.
Protecting Important Commands
alias chown="chown --preserve-root"
- Description: Prevents
chown
from being applied to the root directory by accident. - Use Case: Protects against potentially destructive recursive changes to ownership across the entire filesystem.
alias chmod="chmod --preserve-root"
- Description: Similar to the above but for
chmod
, preventing permission changes to the root directory. - Use Case: This helps prevent accidental permission modifications to essential system files.
alias chgrp="chgrp --preserve-root"
- Description: Prevents
chgrp
from affecting the root directory. - Use Case: Ensures group ownership modifications don’t inadvertently affect the root directory.
Networking and System Updates
alias ports="sudo ss -tulnqp"
- Description: Displays all open ports on the system with additional details.
- Use Case: This alias helps diagnose network issues by showing active network connections.
alias ipa() { ip -4 a show "$1" | grep -oP '(?<=inet\s)\d+(\.\d+){3}'; }
- Description: Displays IP addresses for a specified network interface.
- Use Case: Useful for checking the IP address of specific network adapters, such as
eth0
orwlan0
.
alias cpv="rsync -ah --info=progress2"
- Description: Copies files with a progress indicator.
- Use Case: Ideal for tracking the progress of file transfers, especially for large files or directories.
System Maintenance and Package Management
alias update="sudo apt update && sudo apt upgrade -y"
- Description: Updates and upgrades the system in one command.
- Use Case: Essential for regular system maintenance on Debian-based distributions, keeping the system secure and up-to-date.
alias clean="sudo apt autoremove && sudo apt clean"
- Description: Removes unnecessary packages and clears the cache.
- Use Case: Helps to free up disk space by cleaning up residual files from package installations.
Service and System Monitoring
alias status="sudo systemctl status"
- Description: Checks the status of a specified system service.
- Use Case: Quickly verify the status of services such as
nginx
,apache2
, ordocker
without typing out the full command.
alias restart="sudo systemctl restart"
- Description: Restarts a specified system service.
- Use Case: Restart services like web servers or database servers to apply configuration changes without rebooting the entire system.
alias please="sudo !!"
- Description: Re-runs the last command with
sudo
. - Use Case: Great for times when you forget to add
sudo
to a command that requires it. Simply typeplease
to re-run the previous command with elevated privileges.
These aliases are designed to make your time in the terminal faster and more efficient, helping you avoid common pitfalls, streamline repetitive tasks, and take better control of system management. By incorporating these aliases, you can greatly enhance your productivity in the Linux environment.
Don’t forget to add these aliases to your .bashrc
or .zshrc
file and reload your configuration with source ~/.bashrc
to start using them right away.
By incorporating these aliases into your Linux workflow, you’ll be working smarter and more efficiently. Be sure to revisit our previous post on Linux aliases if you’re just getting started and let us know in the comments how these shortcuts are helping you streamline your work!
Stay tuned for more Linux tips and tutorials. Until next time, happy aliasing!
If you found this guide helpful, then do click on 👏 the button.
Follow for more Tutorials like this 😊
If there’s a specific article or how to you’re curious about, feel free to drop a personal note or comment. I’m here to help you explore whatever interests you!
Recent Articles
The Ultimate Guide to Aliases in the Linux Terminal
Every Linux User Should Know!!!
graphpe.medium.com
🔗 Support my Work
▶️ Support by Subscribing my YouTube