Tuesday, November 27, 2012

.bashrc Tweaks

If you're anything like the average *nix user you most likely find yourself in a terminal quite often. Myself being no different love extending my .bashrc file to add some time and headache saving aliases and functions; here's some of my favs.

ls Aliases


These are especially handy when used in conjunction with other bash tools like sed and awk

[sourcecode language="bash"]
alias ll="ls -l --group-directories-first"
alias ls='ls -hF --color'
alias la='ls -Al'
alias lx='ls -lXB'
alias lk='ls -lSr'
alias lc='ls -ltcr'
alias lu='ls -ltur'
alias lt='ls -ltr'
alias lm='ls -al |more'
alias lr='ls -lR'
[/sourcecode]

The Shred Bomb


This is extremely handy if you're either anal retentive about trash files or paranoid o_0 The first alias passes some flags to shred that cause it to annihilate a single file. The function I wrote below it recursively does the same with a whole directory, very fun to watch in a terminal.

[sourcecode language="bash"]
alias shred="sudo shred -vxuz -n33"

function shredd() {
if [ -z "$1" ]
then
for file in ./*
do
if [ -d $file ]
then
prevdir=$file
cd $file
shredd
cd "../"
rmdir $prevdir
else
shred $file
fi
done
else
initdir=$1
paramflag="true"
for file in $1
do
if [ -d $file ]
then
prevdir=$file
cd $file
shredd
cd "../"
rmdir $prevdir
else
shred $file
fi
done
fi
rmdir $initdir
}
[/sourcecode]

Miscellaneous


The unzip alias is for all those people tired of remembering which flags tar needs for a tar.gz or bz2 archives, yes I'm lazy. cleanpics wipes all exif meta data from jpg files, great for pics off your phone you want to sanitize.

[sourcecode language="bash"]
alias unzip='atool -x'
alias cleanpics='exiftool -all= *.jpg; rm *.jpg_original;'
[/sourcecode]

Some of these may not work until you install the proper packages but that's as easy as a sudo apt-get install shred. Have fun.

No comments:

Post a Comment