5 tips and tricks to speed up your bash experience
Sometimes performing certain tasks on command line could be time consuming. This article introduces you to five tricks that can speed up your experience with bash. This article is mostly for new Linux users, but experienced users may find some of them interesting.
- Executing commands in history using Ctrl+r
Just press Ctrl+R and start typing a command that you executed a while ago. It will automatically shows you the exact command.
Example:
If you have used a long command to create a backup of your database using mysqldump command and you need to executed it again, all you need to do is to press Ctrl+R and type "dump". Your full command will appear. Now you can press enter to execute the command again. - Clearing your command using Ctrl+u
Sometimes you're writing a long command, but instead of executing it, you want to clear it. You can press Ctrl+u to do so. This command is particularly useful when you enter a wrong password and want to start writing it from the beginning. - Finding a keyword using / in man page
You have probably seen a lot of long man pages. Sometimes you're looking for certain keywords in them. Just press / and start typing your search and press enter. Pressing n will take you to the next occurrence of that keyword and N will take you back. This feature is similar to that of vim. - Creating a multiple hierarchy directory using mkdir -p option
You can create a directory using mkdir. However, if the directory you're creating is going to be in a directory hierarchy that doesn't exist, instead of creating every single of them you can make them all at once using mkdir -p option.
Example:
mkdir dir1/dir2/dir3/dir4
This command will create dir1, dir2, dir3 if they don't exist before it creates dir4. Hopefully, you won't create each of such directories using a separate command from now on. - Running a command on multiple files using for loop.
Suppose you have more than 100 files in a directory and you need to do something with all of them. You can use the for loop command to perform an action on them. The syntax is the following:
for file in directory; do command $file any-extra-parameter-if-necessary; done Example:
Suppose you have a few hundred pictures in a directory and you need to reduce their size by half. Instead of opening them one by one using your favorite image editor, you can issue the following command to convert all the jpg files in pics directory:
for file in pics/*.jpg; do convert -resize 50% $file; done
Published On: Aug. 23, 2010 --- Views: 517
Tags:
If you found this article helpful, I strongly recommend reading this article:
How to work with tabs in vim
There are 0 comment(s):
My Favorite Bloggers:
Categories:
Related:
- How to work with tabs in vim
- Arch Linux sound problem in Firefox and amarok
- How to create common folders for all users in Linux
- How to fix intel video card freezing problem in Ubuntu 10.04
- Starting Gmote at startup on Linux
- How to test Android apps on your phone on Arch Linux
- Top 4 Android Apps for Linux Lovers
- Moonlight vs Flash - on Linux Support
- My Thoughts on Ubuntu 10.10
- Google Chrome OS, Useful or Useless?
- Block Selecting, The Killer Feature of Vim