I have a folder containing a lot of folders and different files with the following structures :
NASA
│
├── a
│ ├── doc1
│ ├── doc2
│ ├── doc3
│ ├── folder1
│ └── folder2
│
├── b
│ ├── doc1
│ ├── doc2
│ ├── doc3
│ ├── folder1
│ └── folder2
│
├── c
│ ├── doc1
│ ├── doc2
│ ├── doc3
│ ├── folder1
│ └── folder2
│
├─ x
├─ y
└─ z
I want to delete the content of the folder (NASA/
) except specified folders and files.
For example I want to keep a
folder, b
folder and x
file.
I tried this solution :
rm !(a/) -r NASA/
And (as explained in the answer here):
find NASA/ -type f ! -iname "x" -delete
But this is not very straight forward and I have to use a bash script.
Am I missing a more easy way ? How can I do this in a single command?
rm -r c y z
– Wayne_Yux Oct 23 '15 at 10:14