Table of Contents#
- Command Line Keyboard Shortcuts
- Using Aliases and Functions
- Managing Processes Efficiently
- Automating Tasks with Cron Jobs
- Package Management Tricks
- Searching Files Faster
- Using Screen and Tmux
1. Command Line Keyboard Shortcuts#
Common Shortcuts#
- Ctrl + A: Move the cursor to the beginning of the line. For example, if you've typed a long command and want to edit the start, this shortcut saves time compared to using the arrow keys.
# Typed a long command
ls -l /usr/local/bin/some/long/path/to/files
# Press Ctrl + A to go to the start and add something- Ctrl + E: Move the cursor to the end of the line. Useful when you need to append something to an existing long command.
- Ctrl + U: Delete from the cursor position to the beginning of the line. If you want to completely re - write a part of the command you've already typed, this is quicker than backspacing.
- Ctrl + K: Delete from the cursor position to the end of the line.
- Ctrl + R: Reverse search through your command history. Suppose you used a complex
grepcommand a few hours ago. You can pressCtrl + Rand start typing a part of the command to quickly find and re - execute it.
(reverse-i-search)`grep': grep -r "error" /var/logNavigation Shortcuts#
- Alt + F: Move one word forward.
- Alt + B: Move one word backward.
2. Using Aliases and Functions#
Aliases#
Aliases are shorthand notations for longer commands. You can define them in your shell profile (e.g., .bashrc or .zshrc).
To create an alias that lists files in a detailed format with color coding:
# Add this line to your .bashrc or .zshrc
alias ll='ls -l --color=auto'
# Then source the file to apply the changes
source ~/.bashrcNow, instead of typing ls -l --color = auto, you can simply type ll.
Functions#
Functions can be more complex than aliases and can accept parameters. For example, a function to create a directory and immediately change into it:
# Add this to your shell profile
mkcd() {
mkdir -p "$1" && cd "$1"
}
# Source the file
source ~/.bashrcYou can then use it like this:
mkcd new_directory3. Managing Processes Efficiently#
Killing Processes#
killCommand: Thekillcommand is used to send a signal to a process. By default, it sends theSIGTERMsignal, which asks the process to terminate gracefully.
# Find the process ID (PID) of a program
ps -ef | grep firefox
# Then kill the process using its PID
kill 1234 # Replace 1234 with the actual PIDkill -9: If a process is unresponsive and doesn't terminate withkill, you can usekill -9, which sends theSIGKILLsignal. This forces the process to terminate immediately.
kill -9 1234Screen - like Suspension#
You can suspend a running process in the terminal using Ctrl + Z. Then, use the bg command to send it to the background.
# Start a long - running process
tar -zxvf large_file.tar.gz
# Press Ctrl + Z to suspend it
# Send it to the background
bg
# Check the jobs list
jobs4. Automating Tasks with Cron Jobs#
Cron is a time - based job scheduler in Linux. To edit your cron jobs, use the crontab -e command.
Example Cron Jobs#
- Run a backup script every night at 2:00 AM:
0 2 * * * /path/to/backup_script.sh- Update the system packages every Sunday at 3:00 AM:
0 3 * * 0 apt update && apt upgrade -y5. Package Management Tricks#
APT (Debian - based Systems)#
- Update and Upgrade in One Step: Instead of running
apt updateand thenapt upgradeseparately, you can use a single command.
apt update && apt upgrade -yThe -y option automatically answers "yes" to any prompts, saving you the need to confirm the upgrade.
YUM (Red Hat - based Systems)#
- To update all packages and clean up the cache:
yum update -y && yum clean all6. Searching Files Faster#
find Command#
The find command is very powerful for searching files. For example, to find all .txt files in the /home directory:
find /home -name "*.txt"grep Command#
If you want to search for a specific string within files, use grep. To search for the word "error" in all .log files in the /var/log directory:
grep -r "error" /var/log/The -r option makes the search recursive.
7. Using Screen and Tmux#
Screen#
Screen is a terminal multiplexer. You can start a new screen session using:
screenThen, you can detach from the session using Ctrl + A followed by d. To re - attach to the session later:
screen -rTmux#
Tmux is another popular terminal multiplexer. Start a new tmux session:
tmux new -s mysessionDetach from the session using Ctrl + B followed by d. Re - attach:
tmux attach -t mysessionConclusion#
By implementing these time - saving tips, Linux users can significantly improve their productivity and efficiency. Whether it's using keyboard shortcuts, creating aliases, automating tasks, or managing processes, these techniques can make your Linux experience more enjoyable and less time - consuming.
References#
- Linux Documentation Project: https://tldp.org/
- Ubuntu Documentation: https://help.ubuntu.com/
- Red Hat Documentation: https://access.redhat.com/documentation/en - us/