Home Linux Tips & TricksLinux Tips and Tricks: 20 Command-Line Shortcuts That Save Time

Linux Tips and Tricks: 20 Command-Line Shortcuts That Save Time

By sk
707 views 8 mins read

Linux power users spend most of their time in the terminal. They don't repeat long commands, retype paths, and fix mistakes the hard way. Instead, the experienced Linux admins use some effective command line tricks to get things done quickly.

In this guide, we will learn 20 practical Linux tips and tricks that experienced admins use daily. These shortcuts work on Bash and most Linux shells.

These tips help you:

  • work faster in the terminal
  • avoid retyping commands
  • recover from mistakes safely
  • improve daily Linux productivity

Let us get started!

Linux Tips and Tricks for Faster Command Execution

1. Re-run the Last Command with sudo

This shortcut helps you rerun the last command with root privileges.

sudo !!

Adds sudo to your previous command.

Example:

Let us say you forget to use sudo in the following command:

apt update

The shell returns a permission error.

Now, run and see what happens:

sudo !!

This expands to:

sudo apt update

Now, the command runs successfully.

Use this trick to avoid retyping long commands when you forget sudo.

2. Open the Last File You Typed

This shortcut helps you open the last file you referenced without typing its name again.

vim !$

!$ expands to the last argument. In other words, it opens the last argument from the previous command in Vim.

Example:

You create a file:

touch config.yaml

Then open it for editing:

vim !$

This expands to:

vim config.yaml

3. Search Command History Instantly

Reverse incremental search through command history is one of the most useful shell features.

  • Reverse: It searches backward in history
  • Incremental: Results update as you type
  • Search: It matches text in past commands It is a Readline feature. Bash, and many other shells, use Readline for line editing.

It is also known as:

  • reverse history search
  • Ctrl-R history search

To find and reuse past commands quickly, press:

Ctrl + R

Type a few letters to find past commands. It starts a reverse search through your command history as you type.

4. Edit the Last Command Safely

Fix mistakes in an editor instead of retyping.

fc

Opens your last command in your default editor, lets you fix it, and then runs it again.

Example:

You run a long command and notice a mistake:

rsync -ah --progess src/ dest/

Instead of retyping, run:

fc

Your editor opens with:

rsync -ah --progess src/ dest/

Fix the typos:

rsync -ah --progress src/ dest/

Save and exit. The corrected command runs immediately.

For more details fc command, refer the following guide:

5. Toggle Between Two Directories

You can switch back to your previous directory instantly with this command:

cd -

Moves back to the last directory.

Example:

You move to a different path:

cd /etc/nginx

Then go somewhere else:

cd /var/log

Go back to the previous directory:

cd -

You return to:

/etc/nginx

It is faster than typing full paths again.

Linux Directory Navigation Tips

6. Save and Return to Paths

Use pushd and popd commands when you switch between deep directories often.

pushd /var/log
popd

They save time and reduce typing errors.

Related Read: How To Navigate Directories Faster In Linux

7. View Folder Structure Clearly

This tree command displays the folder hierarchy up to two levels deep in a clear tree format.

tree -L 2

Shows a readable directory layout.

Use this to understand project layout quickly without running multiple ls commands.

8. Create and Enter a Directory Quickly

You can create and move into that directory immediately like below:

mkdir project && cd $_

$_ reuses the last argument.

You can use this trick to avoid typing the directory name twice and to move faster when setting up new project folders.

Related Read: [Bash Tips] How To cd and ls in One Command

Linux Shell Editing Shortcuts

9. Fix a Typo Without Retyping

You can replace the first occurrence of old with new in the previous command and runs it again like below.

^old^new

This tip is used correct simple mistakes in the last command fast, without editing or retyping the full command.

Example:

You type a command with a typo:

sl

The shell says the command is not found.

Instead of retyping, run:

^sl^ls

Here's what happens under the hood:

  • The shell takes your last command: sl
  • It replaces sl with ls
  • It runs ls immediately

Another Example:

You mistype a filename:

cat /var/log/sylog

Fix it like this:

^sylog^syslog

This works best for small, obvious mistakes in the previous command.

10. Reuse the Last Argument

Press:

Alt + .

This shortcut helps you reuse the last argument from previous commands without typing it again.

This inserts the last argument of the previous command at your cursor.

Example 1: Reuse a File Name

You run:

tar -xzf backup.tar.gz

Next, you want to move that file:

mv Alt + .

After pressing Alt + ., the command becomes:

mv backup.tar.gz

Example 2: Reuse a Path

You run:

cd /var/log/nginx

Then type:

ls Alt + .

It expands to:

ls /var/log/nginx

Note: Press Alt + . multiple times to cycle through arguments from earlier commands.

This shortcut saves a lot of typing when working with long paths or filenames.

11. Move Faster in the Command Line

  • Alt + B → back one word
  • Alt + F → forward one word
  • Ctrl + W → delete word
  • Ctrl + U → clear line

For more shell shortcuts, refer our Linux command line tricks guide.

Linux File and Process Management Tips

12. Copy Files with Progress

Use this rsync command to copy files reliably with visible progress while preserving permissions and timestamps, especially for large or important data transfers.

rsync -ah --progress src/ dest/

13. Create Quick Backups

It is always recommended to back up some important config files before editing them. To do so, you can use this quick tip:

cp file.conf{,.bak}

It creates a backup copy of file.conf named file.conf.bak in the same directory.

14. Follow Logs Without Losing Scroll

You can watch a log file live while keeping the ability to scroll back.

less +F /var/log/syslog

This opens the syslog file in follow mode, similar to tail -f, but allows you to scroll and search through earlier log entries.

15. Find What Uses a Port

Want to identify which process is listening on a specific port? Use the ss command like below:

ss -lntp | grep :8080

This command shows the process and PID that are listening on TCP port 8080.

16. Kill a Process by Name

pkill -f nginx

This command stops all running processes whose command line contains the word nginx.

Please note that this can stop all Nginx-related processes, so use it carefully on production systems.

17. Watch System Changes Live

watch -d df -h

This command helps you monitor disk usage changes in real time. It is useful when you copy files, run backups, or troubleshoot low disk space issues.

Related Read: Why Every Linux Admin Should Monitor the var Directory Closely

Cleaner Linux Command Usage

18. Avoid Useless Pipes

Instead of:

cat file | grep error

Use:

grep error file

Recommended Read: Grep Command Usage with Examples

19. Check What a Command Really Is

The type command enables the users to easily find whether the given command is an alias, shell built-in, file, function, or keyword.

type ls

20. Edit Any Command from History

The fc command, short for fix commands, is a shell built-in command. It allows you to list, edit and re-execute the most recently entered commands into an interactive shell.

You can edit the recently entered commands in your favorite editor and run them without having to retype the entire command.

For instance, the following commands list the recently executed commands and edit the 105th command and finally execute it immediately, all without having to retype the command:

fc -l
fc 105

Simple Rule for Linux Users

If you type the same long command more than twice:

This habit separates beginners from experts.

Frequently Asked Questions (FAQ)

Q: What are the most useful Linux command-line tips?

A: History search (Ctrl + R), sudo !!, cd -, and fc save the most time for daily Linux work.

Q: Do these Linux tips work on all distributions?

A: Yes. These commands work on most Linux systems using Bash, including Ubuntu, Debian, RHEL, Fedora, and Arch.

Q: Are these tips safe for production servers?

A: Yes, when used carefully. Commands like fc and rsync reduce mistakes compared to retyping.

Q: Which Linux shell supports these shortcuts?

A: Bash supports all listed shortcuts. Many also work in Zsh with minor differences.

Conclusion

In this detailed guide, you learned 20 powerful Linux tips and tricks to work faster in the terminal. These practical command-line shortcuts are used by real Linux admins and power users.

By learning these tips, you can:

  • work faster in the Linux terminal,
  • reuse command history efficiently,
  • navigate directories with less typing,
  • manage files and processes safely,
  • avoid common shell mistakes.

These skills compound over time. Practice these commands and tips whenever you can.

Of course, there are more. I have included a few more useful resources below. Make use of them!

Recommended Read:

You May Also Like

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More