Hot answers tagged

2

Assuming your files have sane names (i.e. they don't have embedded newlines), something like this should work: find . -mtime +60 | fgrep -v -x -f exceptions.txt | xargs -d '\n' rm -f Replace rm -f with ls -1 for a dry run first. Put paths exactly as they are printed by find in exceptions.txt.


1

Because when you use just *net* (without any quoting or escaping), it will be expanded by the shell as the (existing) net file/directory in the current directory before the find command run. So the command becomes: find . -name net As you can see it is just matching net, so usbnet.ko will not be matched. So you need to avoid the shell globbing first, to ...


1

I don't think find has an option like this, you could build a command using printf and your exclude list: find . -name "*.txt" $(printf "! -name %s " $(cat file.txt)) -mtime +60 -exec rm -f {} + file.txt will have list of files to exclude in find command.


1

Unorthodox approach: zsh -c 'echo $PWD/**/*.gz(.om[1])' where () after *.gz means to use so called glob qualifiers, i.e.: . consider only plain files om sort by modification time [1] take only first element Obviusly if you are already using zsh you don't need to call it with zsh -c.



Only top voted, non community-wiki answers of a minimum length are eligible