Hi I have 1 directory in my server i will delete everything except 2 files (index.html and .htaccess) with cronjob how can do it?
From SSH: rm -R *.* !(index.html*) !(.htaccess*) Code (markup): From FTP: Just select and delete the files Code (markup):
[root@test~]# mkdir z ; cd z ; touch 1 2 3 4 5 6 [root@test z]# ls 1 2 3 4 5 6 [root@test~]# find z/ -type f \( ! -iname '2' -and ! -iname '3' \) -print z/1 z/4 z/5 z/6 [root@test~]# Code (markup): You could use find with -delete instead of -print to remove the files.
i have a different angle on it: how about not keeping your auto generated files (logs, cache, tmp) in the same directory as your static files?