This question is kind of a phase II to the first question I posted at here
I have a directory that contains a bunch of sub-directories, .zip files, and other random files not contained within a sub-directory.
I'd like a command line script to remove all sub-directories from within the parent directory, but keep all zip files and loose files that don't belong to any sub-directories. All of the sub-directories have content, so I believe I'd need to force their deletion with the -f command.
So basically, a command that looks inside the parent directory (or the current directory), deletes all folders from within it, but keeps all other content and files that are not a folder or contained within a folder.
I understand that deleting items from the command line requires special care, but I have already taken all necessary precautions to back up remotely.
-r
,-R
,--recursive
are synonyms meaning "remove directories and their contents recursively". – peterph Mar 22 '13 at 21:39rm
from coreutils. It might vary for other implementations though (always see man/info pages). – peterph Mar 22 '13 at 21:56--
is just to stop hyphen-names to be interpreted as command line options. – frostschutz Mar 23 '13 at 00:06rm -R ./*/
- It also avoids problems with hyphen names. – l0b0 Mar 23 '13 at 09:08rm: cannot remove 'Magento/Framework': Directory not empty
– Black Sep 13 '22 at 10:00