I want to run wc -l
and use the result in an arithmetic expansion. In other words, I want to do something like this:
wc -l (now somehow pipe/pass the result of this to) $((2 + result of wc command))
How can I do this?
Context
In my ~/Pictures
directory, I have multiple files named "Screenshot from YYYY-MM-DD hh-mm-ss.png
", as well as other files.
I want to keep all files that are not Screenshots, and only a specified number of Screenshot pictures, based on how recent they were. I want to basically only keep the last 3 most recent Screenshots I have, and delete all the rest.
So here is what I have so far:
ls | grep "Screenshot *" | sort -r | wc -l
What I then wanted to do was to subtract 3 from wc -l
, which would then allow me to use tail
to list all the files that are not the first 3, and then just delete them.