Linux Blog

Bash Tips for more efficient terminal usage

Filed under: Linux for Newb's,Linux Software — TheLinuxBlog.com at 5:36 pm on Monday, November 23, 2009

Here are some tips for working in the shell that I use on a daily basis. These may be known to most veterans, please contribute your favorite shortcuts to the comments. But for the most part this is not for the uber leet Linux geek, this is for those new to the terminal.

TAB
– Gives you suggestions / completes stuff for you. Type a, Press it twice, it will make your life a lot easier.

ctrl+w
– Remove word behind cursor.

ctrl+u
– Undo / Erase everything from cursor to beginning of the line

!!
– Type out whatever you typed out last, can be combined with tools like sudo

alt+f
– Go forward to the end of the previous word

alt+b
– Move cursor back to the beginning of the previous word

ctrl+d
– You’re done? Press ctrl+d to logout. If you’re in a virtual terminal, it may also close the window.

ctrl+z
– Stop the current process. Say you run gvim, and then you want to spawn another process. Press ctrl+z, then type bg. Once you’re done with the “other” process, you may type fg to bring it back into the foreground.

Automated scanning with the shell

Filed under: Shell Script Sundays — TheLinuxBlog.com at 9:25 am on Sunday, July 27, 2008

I recently needed to scan a lot of images on my desktop PC. Unfortunately I am not the owner of an automatic document feed printer, and if I were it wouldn’t have helped this time because the documents I needed to scan were not feed able. XSANE is a great way to scan documents visually in Linux. Its not the easiest to use, but it has plenty of options. Part of the SANE package is scanimage, scanimage can be used from the shell.

The first thing that I did was a few test images with scanimage. I quickly found out that scanimage outputs in pnm format, and at a high resolution if the correct options are used. Once I found out the good options for my scanner (scanimage –resolution 400 > file.pnm) I wrote a quick shell script to scan up to 1000 times or until I don’t give the script any input. To do this, I used a combination of snippets that can be found in this blog column.

Here is a direct link to the script, and the shell script source below

#!/bin/bash
for i in `seq 1 1000`; do
 
#get input line
read inputline;
 
if [ $inputline ]; then
 
#Process Scanned Image in BG
echo Scanning Pg$i;
scanimage --resolution 400 > Pg$i.pnm;
echo Next;
else
exit
fi
 
done;

To use it all I do is execute the script, and I get to scan up to 1000 documents providing I type something after it prompts “Next”, and then hit enter. Once I was done scanning, I just hit enter to stop the script execution and then moved on to manipulating the images with the shell.

Hope this shell script scanning script is useful, if it is then drop me a comment, or if you have any suggestions or it was not at all helpful still drop me a comment.