I retrieved all the pdfs in $HOME directory
$ find -E ~ -regex ".*/[^/].*.pdf"
It print more than 1000 files;
I intent to sort them by size and searched
$ stat -f '%z' draft.sh
184
I drafts the script:
#! /usr/local/bin/bash
OLD_IFS=IFS
IFS=$'\n'
touch sorted_pdf.md
for file in $(find -E ~ -regex ".*/[^/].*.pdf")
do
file_size=$(stat -c "%s" $file)
....
done > sorted_pdf.md
IFS=OLD_IFS
It's hard to work them together and get my result. Could you please provide any hint?
I refactored the code
#! /bin/zsh
OLD_IFS=IFS
IFS=$'\n'
touch sorted_pdf.md
for file in $(find -E ~ -regex ".*/[^/].*.pdf")
do
# file_size=$(stat -c "%s" $file)
printf '%s\n' $file(DoL)
done > sorted_pdf.md
IFS=OLD_IFS
but get error report
$ ./sort_files.sh
./sort_files.sh: line 12: syntax error near unexpected token `('
./sort_files.sh: line 12: ` printf '%s\n' $file(DoL)'