Some very useful bash shell tips.

The bash shell has some very useful features when using the command line. This can make using the command line much faster. For example, if you forget to type sudo before a command, this can be fixed this way.

jason$ fdisk -l /dev/sda
fdisk: cannot open /dev/sda: Permission denied

Type sudo !! at the command line.

jason$ sudo !!
sudo fdisk -l /dev/sda
[sudo] password for jason: 
Disk /dev/sda: 1.8 TiB, 2000398934016 bytes, 3907029168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x000658b4
 
Device     Boot  Start        End    Sectors  Size Id Type
/dev/sda1  *      2048     206847     204800  100M  7 HPFS/NTFS/exFAT
/dev/sda2       206848 3907026943 3906820096  1.8T  7 HPFS/NTFS/exFAT

And the command will be redone with the sudo command prepended to it.

Press ^p to retype the last command at the bash shell prompt. If you have already typed something at the prompt, it will be replaced.

^l will clear the terminal window.

^a will take the cursor back to the start of the command line.

Press ^w to erase back one word on the command line. Use this multiple times to erase a whole sentence.

Print information about your tty terminal interface like this.

Printing information about the terminal.
Printing information about the terminal.

To erase an entire line, run this command.

jason$ stty kill ^a

Now ^a will erase an entire line at the bash prompt. Put this into the .bashrc and this will be available whenever you need it.

More bash shortcuts information here.

Have fun!

50,000 dollar hard disk drive being loaded onto a truck.
50,000 dollar hard disk drive being loaded onto a truck.

No comments have been made. Use this form to start the conversation :)

Leave a Reply