bash

sudo !!

A time-saver for those that forget to sudo, bash substitutes !! for the last command entered, for example

<br />
charles@lucifer$ make sandwich<br />
Permission Denied!<br />
charles@lucifer$ sudo !!<br />
sudo make sandwich<br />
echo "You seriously think I would write a sandwich recipe just to demonstrate bash shortcut?"<br />
You seriously think I would write a sandwich recipe just to demonstrate a bash shortcut?<br />

Subject: 

Walking a directory tree with bash

I'm doing the hard-drive shuffle thing. I have a lot of data and I'm paranoid about losing it. I've been let down once or twice by bad copies so I thought I should take checksums before copying. I had a lot of fun arguing with wildcards and string escaping so I thought I'd share my adventure, as I've already worked out how to do this and forgotten at least once.

My first attempt. It dies when fed directories.

[code lang=bash]md5sum * | md5sums.txt
[/code]

I try again, and it occours to me to use tee in append mode so I get output to the screen as well

Subject: 

Do the same thing to many files when wildcards break

This is a gem I use a lot, and forget a lot, so it's write it down time.

Suppose I have a folder with a number of tarballs in it and I want to extract all of them, tar -xf *.tar won't work as tar will try and extract all but the first file that matches the wild card from the first item. We break out the trusty for loop.


for foo in `ls *.tar`
do
tar -xf $foo
done

Subject: 

Subscribe to RSS - bash

My Band

LinuxCounter.net

Creative Commons License
Except where otherwise noted, work is licensed under a Creative Commons Licence and is the work and opinion of the credited author(s).

Powered by Drupal

My Facebook


Charles Elwood's Facebook profile