|
Answer» We have numerous directories that each contain 2 files, one of which is a hidden file. We want to remove all those directories and their contents that contain ONLY files that have a modification date older than 180 days. So, for example, if we have the following:
Dir1 Jan 1 2000 File1A Jan 1 2000 File1B Jan 1 2000 Dir2 Jan 1 2000 File2A Jan 1 2014 File2B Jan 1 2014 Dir3 Jan 1 2000 File3A Jan 1 2014 File3B Jan 1 2000
I need a command that will remove only Dir1 and all of its contents including the hidden file. Dir2 and Dir 3 would remain untouched because each contain at least one file that is NEWER than 180 days ago.
I've played around with listing those directories that contain a newer file but I couldn't find an "inverse" command that would then remove all the "other" directories.
Thanks in advance for your help! OK. First, some basic questions. Why? -Is it to save space on your hard drive? - Is it to reduce visual clutter? - Does it affect the logic of a process? Also, you have enough drive space to allow temporary storage? Are you sure a bash command is the best method for you? - Some users would use visual INTERFACE, but you can do it in the terminal mode swith a few commands We assume you have a backup plan already in place. As for me, I am lazy and do not like to make bad mistakes. So I would make the computer do the work. So this is what I do in case I want to zap just old files.
Make a sibling directory named 'temp'. (A sibling is a directory alongside the working you use.) COPY all new files and directories to the 'teemp' directory. (In Windows you would use Xcopy. In Linux you might use 'cp' or another utility.
Next, if all goes well, delete all in the working directory. Last step is move contents of the temp dir working dir. This can be don E one step at a time and you can view the progress.
Others here can find a more elegant solution.
|