Created
May 19, 2016 17:30
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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