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)'
findfor-Eand BSDstatfor-f %z, but then thestat -c %sindicates GNUstat, what system is it? Do you have to usebashor can you use other shells likezsh? – Stéphane Chazelas Oct 26 '18 at 14:48.pdf. So it's different in that we need to sort files found byfind(or other ways to find files by name). – Stéphane Chazelas Oct 26 '18 at 14:53find ... -printf '%s %P\n' | sort -nwork? – pLumo Oct 26 '18 at 15:07syntax error near unexpected token '('is abashmessage, but in any case,$file(DoL)wouldn't make sense inzsheither. That's meant to be a glob qualifier to sort the glob expansion, so doesn't make sense when applied to a single file. – Stéphane Chazelas Oct 26 '18 at 15:08find’s output by size (using-printfon GNUfind). – Stephen Kitt Oct 26 '18 at 15:09printfis GNU specific. The OP is on macOS. – Stéphane Chazelas Oct 26 '18 at 15:09-printfpreficate offindis GNU-specific. Theprintfutility itself is standard. – Stéphane Chazelas Oct 26 '18 at 18:04