The ramblings of Chad Humphries

Posts Tagged ‘bash

bashing around the old shell prompt

Digging about the interwebs I discovered many a interesting thing about bash. (Note: Bash junkies and long time users will wince as these are probably nigh ancient widely known bits of knowledge).

Flip the Last Two Characters (from bashhelp)

If you type like me your fingers spit characters out in the wrong order on occasion. ctrl-t swaps the order that the last two character appear in.

Searching Bash History (from bashhelp)

As you enter commands at the CLI they are saved in a file ~./.bash_history. From the bash prompt you can browse the most recently used commands through the least recently used commands by pressing the up arrow. Pressing the down arrow does the opposite.

If you have entered a command a long time ago and need to execute it again you can search for it. Type the command ‘ctrl-r’ and enter the text you want to search for.

Lists Using { and } (from bashhelp)

The characters { and } allow for list creation. In other words you can have a command be executed on each item in the list. This is perhaps best explained with examples:

# This will create/modify the files temp1, temp2, temp3, and temp4 and as 
# in the example below when the files share common parts of the name you can do:
$ touch {temp1,temp2,temp3,temp4} 
# This will move all four of the files into a directory foobar.
$ mv temp{1,2,3,4} ./foobar/ 

Aliases (from bashhelp)

To see what aliases are currently active, simply type alias at the command prompt and all active aliases will be listed. To “disable” an alias type unalias followed by the alias name.

Bash Completion (from bashhelp) Basic completion will work in any bash shell. It allows for completion of:

  1. File Names
  2. Directory Names
  3. Executable Names
  4. User Names (when they are prefixed with a ~)
  5. Host Names (when they are prefixed with a @)
  6. Variable Names (when they are prefixed with a $)

A rather hodge-podge extraction of bash tidbits but I found them very, very useful.

Written by spicycode

January 27, 2008 at 6:23 pm

Posted in programming

Tagged with