A few tips and tricks on the terminal to make you more efficient when using it. If you know of any other tips, add it in the comments section.
1. ls Without ls
When you are trying to cd into a deep folder, you might not know the correct folder name some levels deep. You might have to do something like…
$ cd ~/Scripts/Perl $ ls bin SedGUI ToSee Cronjobs Maintenance $ cd Maintenance
There is an easier way – go to the wanted folder
$ cd ~/Scripts/Perl
Now, without pressing enter, double tap the TAB key. You will get a list of files. And the command prompt waiting to be filled…
$ cd ~/Scripts/Perl/[TAB TAB] bin SedGUI ToSee Cronjobs Maintenance $ cd ~/Scripts/Perl/_
You can also use double-TAB to auto-complete commands.
2. Searching the history with Ctrl+R
If you have to use a command you have already used before, press CTRL+R and then type a few characters of the command. The latest command with those characters will be shown – if that is the command you want to execute, press enter and it will be executed. If not, just press CTRL+R again and it will show the next command.
You have no idea how useful this tip is if you haven’t been using it. I use this all the time.
For more details, read this article.
3. Open Terminal using a Shortcut
If you are a GUI user, chances are you prefer using a Terminal emulator(like
konsole) instead of going into the Terminal mode by pressing CTRL+ALT+F1. If so, assign a shortcut to those emulator apps. I prefer using the shortcut ‘Ctrl+Alt+A’ to do this.
If you are in gnome, there is a very easy way to do this…
- Go to System > Preferences > Keyboard Shortcuts
- Find ‘Run a Terminal’ – assign the shortcut ‘Ctrl+Alt+A’
- Right Click on the K-Menu > Menu Editor
- Find your terminal application in the list(usually System > Terminal Applications > Terminal)
- Select the ‘Current Shortcut Key’ option and set it to ‘Ctrl+Alt+A’
You can also do this by opening the KHotKeys application.
4. Bash Keyboard Shortcuts
Learn the bash keyboard shortcuts – these are the ones I use the most…
- Search the history. We already talked about this.
- Clears the screen. Use this instead of the
- Use this instead of the
- Kill whatever is running
- Puts whatever is running into a suspended background process. Use
fgto restore it.
5. Find Command using
Find the command you want using the
apropos command. Just type in a description of the command as the first argument. For example, lets say you want to find the command to list the directory contents. Use the command…
$ apropos "directory contents" dir (1) - list directory contents ls (1) - list directory contents ls (1p) - list directory contents ntfsls (8) - list directory contents on an NTFS filesystem vdir (1) - list directory contents
The only problem is that I can never spell ‘apropos’ – so I keep this in my
6. Learn New Commands
There are a few sites that publish cool commands on a daily/semi-daily basics – subscribe to those and learn new commands…
del.icio.us | Digg it | reddit | StumbleUpon