lslt Bash Function
by admin on Jan.26, 2013, under Linux
I’m always typing: ls -lhatr | tail
I decided this was getting old. ‘Alias’ was not going to really do what I wanted, so I made a little bash function instead, which can be put in your .bashrc, etc. Simple – but handy. And (of course) maintains colors.
The full script version :
#!/bin/bash
# List the last N items in specified directory in
# reverse time order (newest on bottom).
#
# Note however, the 'alias' commanad alone will not correctly handle args.
if [ $# -lt 1 ]
then
echo "Usage: $0 /foo N (optional)"
echo "Will perform ls -lhatr | tail -N"
exit 1
fi
dir=$1
echo "Listing $dir . . . "
ls -lhatr --color=always $dir | tail -$2
But you can achieve the same thing with a bash function, perhaps in your ~/.bashrc e.g.:
# lslt () { command ls -lhatr --color=always "$1" | tail -"$2"; }
#
# Or even fancier . . .
lslt () {
if [ $# -lt 1 ]
then
#type lslt //Works, but a nicer way is . . .
echo "Usage: lslt /foo N (optional)"
echo "Will perform ls -lhatr | tail -N"
else
command ls -lhatr --color=always "$1" | tail -"$2";
fi
}
No comments for this entry yet...
Leave a Reply
You must be logged in to post a comment.