B
B
b4rret2016-06-20 18:47:31
linux
b4rret, 2016-06-20 18:47:31

How to find and delete all files older than X days except certain ones?

Now the line for searching and deleting files looks like this:
find /dir -type f -mtime +2 -exec rm -rf {} \;
But it took to exclude certain files. How to do it?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
strelmax, 2016-06-20
@b4rret

to exclude certain files use ! -name file_name_to_exclude

V
Vi, 2016-06-21
@redsabien

Like this find ./ -name * .sh
-prune -o -name *.test -prune -o
-print

V
Vlad Zhivotnev, 2016-06-21
@inkvizitor68sl

find /dir -not -iname "*bla" -not -iname "*bla2" -type f -mtime +2 -exec rm -rf {} \;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question