Skip to content

Instantly share code, notes, and snippets.

@danyalette
Created May 19, 2016 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danyalette/1433d880683b0139c5acc7739fcd71c7 to your computer and use it in GitHub Desktop.
Save danyalette/1433d880683b0139c5acc7739fcd71c7 to your computer and use it in GitHub Desktop.
lsr - bash function to list most recently modified files in dir, takes 1 argument - max number of files to list
function lsr(){
# check if no argument has been supplied
if [ $# -eq 0 ]
then
# if no arg, set file count to 1
count=1
else
# if there is an arg, make sure it's an integer
re='^[0-9]+$'
if ! [[ $1 =~ $re ]] ; then
# if it's not an int, return
echo "error: argument must be an integer" >&2; return
fi
count=$1
fi
ls -1t | head -$count
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment