← Back Published on

5 Key Linux Command Line Tricks for Improved Efficiency

As a regular user of the Linux command line, I have found several efficient shortcuts that have greatly optimized my workflow and saved me time. In this blog post, I will share 5 key command line tricks that have proven to be helpful in my everyday tasks.

1. cd -: Switch Between Directories

One handy shortcut I use is the 'cd -' command, which allows me to quickly switch between the current and previous directories.

$ cd /home/user/documents $ cd /var/www/html $ cd -

The last command takes me back to the /home/user/documents directory. This is especially helpful when I'm working with files in different directories.

2. !test: Run Commands With A Specific Prefix

The '!' operator has been a game changer for me. It lets me re-execute a previous command that starts with a given prefix, saving me the time of typing the entire line again.

$ test-command-1 $ test-command-2 $ !test

The last command re-executes the most recent command that starts with 'test', in this case, 'test-command-2'.

3. !!: Re-execute The Previous Command

When I need to run the same command multiple times in a row, the '!!' shortcut is a lifesaver. It enables me to re-execute the previous command with ease.

$ ls $ !!

The second command runs 'ls' again, displaying the contents of the current directory.

4. alias: Create Custom Shortcuts

Creating aliases has allowed me to define short, memorable names for longer commands, making my work more efficient.

$ alias ll='ls -la' $ ll

After creating the 'll' alias, I can use it to run the 'ls -la' command, which displays a detailed list of files and directories in the current folder.

5. $_: Use The Last Argument Of The Previous Command

The '$_' shortcut has proven to be quite useful when I need to use the last argument of the previous command in my current command.

$ mkdir new-folder $ cd $_

The second command changes the directory to 'new-folder', which was the last argument of the previous command.

Conclusion

By using these five command line tricks, I've been able to save time and improve my overall efficiency while working with the terminal on Linux. If you're someone who often works with the command line, I encourage you to explore and practice these shortcuts. They can make a significant difference in your daily tasks.