Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a directly called /cache which has about a million files.

I restructured my caching system to put cache files into different folders, inside the /cache dir. new cache files are already being written to those sub-folders. So I want to remove all the files inside the /cache dir that are not in any subfolder.

How would I do this in SSH?

share|improve this question

2 Answers 2

up vote 6 down vote accepted

You can do so with the find command.

find /cache -maxdepth 1 -type f -exec rm -rf {} \;

I suggest to take a look to the list of files which would be deleted before executing find in combination with -exec rm:

find /cache -maxdepth 1 -type f

This will give you the list of files without deleting them. Again; use find in combination with -exec rm with caution, I can't be clear enough :).

share|improve this answer

You want to remove all files in cache folder without removing files in directory in cache folder ? If it is, you can use find : find /cache -maxdepth 1 -type f -delete -maxdepth limits the depth and don't remove files in folders

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.