Last active
November 24, 2020 20:16
-
-
Save KebabLord/14c3e9ab66f1d721c29837042c435e5c to your computer and use it in GitHub Desktop.
list recent files from folders. Useful for recent downloaded files and newly taken screenshots
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 | |
# Usage: ./recent.sh <parameters> [FOLDER] | |
SS_FOLDER="$HOME/Pictures/Screenshots/" | |
DL_FOLDER="$HOME/Downloads/" | |
list_amount=1 | |
sorter="tail" | |
while getopts "h?n:rsd" opt; do | |
case "$opt" in | |
r) sorter="head" | |
;; | |
n) list_amount=$OPTARG | |
;; | |
s) custom_path=$SS_FOLDER | |
;; | |
d) custom_path=$DL_FOLDER | |
;; | |
\?) echo "Try './recent -h' for more information." | |
exit 0 | |
;; | |
h) printf "Usage: ./recent.sh <parameters> [FOLDER] | |
List recent or first files of a folder.\n | |
-r Revert sorting and list first files instead | |
-n List last 'n' files | |
-s Set path to screenshot folder | |
-d Set path to your downloads folder\n | |
" | tr -d '\t' | |
exit 0 | |
;; | |
esac | |
done | |
shift $((OPTIND-1)) | |
folder_path="$*" | |
if [ -n "$custom_path" ];then | |
folder_path="$custom_path" | |
elif [ -z "$folder_path" ];then | |
folder_path="./" | |
elif [ "${folder_path: -1}" != "/" ];then | |
folder_path="${folder_path}/" | |
fi | |
ls -Art "$folder_path" | | |
$sorter -n "$list_amount" | | |
xargs -L 1 -I % echo "${folder_path}"% |
Author
KebabLord
commented
Nov 23, 2020
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment