D&C GLug - Home Page

[ Date Index ] [ Thread Index ] [ <= Previous by date / thread ] [ Next by date / thread => ]

Re: [LUG] Deleting Empty Folders

 

Hi Rich,

Yep: rmdir *

I just created a bunch of folders, and added a file to one of them, listed everything recursively, and then removed all the empty folders:

Creating the folders:
$ mkdir a b c d

Adding a file:
$ touch b/file

Listing it all recursively:
$ ls -lR
total 0
drwxr-xr-x  2 gsewell  staff  64  3 Jan 14:55 a
drwxr-xr-x  3 gsewell  staff  96  3 Jan 14:55 b
drwxr-xr-x  2 gsewell  staff  64  3 Jan 14:55 c
drwxr-xr-x  2 gsewell  staff  64  3 Jan 14:55 d

./a:

./b:
total 0
-rw-r--r--  1 gsewell  staff  0  3 Jan 14:55 file

./c:

./d:


Removing all the empty folders:
$ rmdir *
rmdir: b: Directory not empty

Listing recursively again to show what's been removed:
$ ls -lR
total 0
drwxr-xr-x  3 gsewell  staff  96  3 Jan 14:55 b

./b:
total 0
-rw-r--r--  1 gsewell  staff  0  3 Jan 14:55 file


As you can see, the folders a, c, and d have gone, but the folder b and the file within it remain.

Grant. :)

On Fri, 3 Jan 2020 at 14:51, Rich <rich@xxxxxxxxxxx> wrote:
Hi Grant

Yes that is correct. Can I double check the command though please? Is it

rmdir *

---
This is the very day God acted—
let’s celebrate and be festive!
Rich
07546 804439
https://gucu.org.uk/


January 3, 2020 2:37 PM, "Grant Phillips-Sewell" <dcglug@xxxxxxxxxxxxxxxxxxxxx> wrote:
On Fri, 3 Jan 2020, 14:33 Rich, <rich@xxxxxxxxxxx> wrote:
Hi

Happy new year to all.

Is there a command I can use via command line that will delete all empty folders from a folder please?
---
This is the very day God acted—
let’s celebrate and be festive!
Rich
07546 804439
https://gucu.org.uk/
--
The Mailing List for the Devon & Cornwall LUG
https://mailman.dclug.org.uk/listinfo/list
FAQ: http://www.dcglug.org.uk/listfaq
Hi Rich,
It's it just 1 folder with a bunch of other folders (some of which are empty), but you're not looking to do anything recursive (like find and remove all empty folders everywhere)?
If so, just do "rmdir *" - anything that isn't a folder won't be removed, and any folder that isn't empty can't be removed.
Grant.
--
The Mailing List for the Devon & Cornwall LUG
https://mailman.dclug.org.uk/listinfo/list
FAQ: http://www.dcglug.org.uk/listfaq
-- 
The Mailing List for the Devon & Cornwall LUG
https://mailman.dclug.org.uk/listinfo/list
FAQ: http://www.dcglug.org.uk/listfaq