Created
September 29, 2022 12:28
-
-
Save horaciod/8a43e4621aec7499f6733aa4b31acdd4 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
num=10 | |
short=0 | |
timestyle='--time-style=locale' | |
#"+%d-%b-%Y%H:%M:%S "' | |
## number of files to print | |
## set to 1 for short listing | |
## GNU-specific time format | |
opts=Aadn:os | |
while getopts $opts opt | |
do | |
case $opt in | |
a|A|d) ls_opts="$ls_opts -$opt" ;; | |
n) num=$OPTARG ;; | |
o) ls_opts="$ls_opts -r" ;; | |
s) short=$(( $short + 1 )) ;; | |
esac | |
done | |
shift $(( $OPTIND - 1 )) | |
case $short in | |
0) ls_opts="$ls_opts -l -t" ;; | |
*) ls_opts="$ls_opts -t" ;; | |
esac | |
## options passed to ls | |
## number of files to display | |
## show oldest files, not newest | |
## long listing, use -l | |
## short listing, do not use -l | |
ls $ls_opts $timestyle "$@" | { | |
read | |
## In bash, the same as: IFS= read -r REPLY | |
case $line in | |
total*) ;; | |
## do not display the 'total' line | |
*) printf "%s\n" "$REPLY" ;; | |
esac | |
cat | |
} | head -n$num |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment