# less the youngest file in the dir that is not a dot file.
function lless () {
less `ls -Art1|tail -1`
}
Aug 01
Jan 07
I always seem to need a tmp file, I used to do ‘vi /tmp/foo’ but it usually had something in it from last time. This function opens a new file and stores the file name in $f.
I use it like:
vt
<paste some stuff, clean it up>
perl -pe ’s/foo/bar/’ $f
####
function vt () {
for i in `seq 0 255`;
do
FILE=/tmp/$USER-foo-$i;
if [ -f "$FILE" ]; then
echo -n '.';
else
f=$FILE;
vi $FILE;
echo $FILE;
return;
fi;
done
}
###### Cleanup
function cleanvt () {
for i in `seq 0 255`
do
FILE=/tmp/$USER-foo-$i
if [ -f "$FILE" ]
then
echo -n '.'
rm $FILE
else
echo
return
fi
done
echo
}
Sep 28
No matter how good an admin you are, you’ll eventually delete something by accident. I don’t like ‘rm -i’, it’s too much. I use the trick of typing ‘#’ before the rm command. Tab competion still works but if I mess up and hit tab-enter (like I do a lot) the ‘#’ saves me. When I’ve got the line looking like I want I ‘ctrl-a’ to beginning and delete the ‘#’ and execute the line.
# rm -rf /etc/sysconfig/network-hold
Once I got used to it, it became reflexive. It adds a couple of extra characters, but it doesn’t break my admin flow.
Sep 06
I love writing shell commands and functions. Everyone does something with ‘ll’ mine is:
alias ll=’ls -lart’ # because I want to see the newest file last.
Lots of times I also want the full path of a file. I could just type
it, but I make a lot of errors when I type long things. A long time
ago I decided cut-and-paste are a dyslexsics best friend. Here are a
couple of helper tools:
’lll’ gets me a full path
’llll’ gets me a path suitable for use in scp.
I do this a lot:
tony-ws:log> llll setup.log
tony-ws:/var/log/setup.log
On another box:
betlong:log> scp tony-ws:/var/log/setup.log .
#quick demo
for i in lll llll
do echo “this is what $i does: “
$i hacked-footertracking.html foo.*
echo
done
this is what lll does:
/home/tony/tmp/hacked-footertracking.html
/home/tony/tmp/foo.idx
/home/tony/tmp/foo.pl
/home/tony/tmp/foo.pl~
/home/tony/tmp/foo.sh
/home/tony/tmp/foo.sh~
this is what llll does:
tony-ws:/home/tony/tmp/hacked-footertracking.html
tony-ws:/home/tony/tmp/foo.idx
tony-ws:/home/tony/tmp/foo.pl
tony-ws:/home/tony/tmp/foo.pl~
tony-ws:/home/tony/tmp/foo.sh
tony-ws:/home/tony/tmp/foo.sh~
############
# often want full path to file(s), this gets it for me
# Tony Hansmann (t o n y replacewith-at-sign open source consulting com)
lll ()
{
if [ ! -z "$*" ]
then
for i in $*;
do
if (echo $i |egrep -q “^/|\.\./”)
then
ls $i
else
\ls `pwd`/$i;
fi
done
else
pwd;
fi
}
##########
# often need to have a file or dir name in scp format
# box:/full/path/to/file, this gets it for me
# Tony Hansmann (t o n y replacewith-at-sign open source consulting com)
llll () {
if [ ! -z "$*" ]
then
if [ ! -z "$*" ]
then
for i in $*
do
if (echo $i |egrep -q “^/|\.\./”)
then
echo $(hostname):$(\ls $i);
else
echo $(hostname):$(\ls `pwd`/$i);
fi
done
fi
else
echo $(hostname):`pwd`;
fi
}