0

I am trying to index some LTO tapes (and some hard disks as well) and would like a simple output, stored in a text file. Something like the example below:

...
/home/norg/Desktop/empty\ dir/
/home/norg/Documents/file.txt
...

The "empty dir" folder is, of course, an empty folder. Notice how folders like "Desktop" and "Documents" are only printed because they have contents inside them. In other words, /home/norg/Desktop/ would never be printed, unless it were empty.

I've tried things like ls -RFad /home/norg/ and some find syntaxes to varying success. The trickiest part is having the empty directories printed, but not the full ones. I hope this makes sense. Thanks.

Another thing to mention, I would really prefer this to work in one go, as I will be using this with tape and want to have as little reads as necessary to reduce wear.

1 Answers1

0
find /home/norg \( -type d -empty \) -o -type f

This will list empty directories and regular files which are below /home/norg.

Although the question title mentions "directories containing files", those are not printed as an item, per the ¡question text.

Also note that it only prints regular files. If you have e.g. fifos or devices, those would not appear (and if you had a folder only containing a device, it would not be printed, either). In case you wanted to also include them, you may use

find  \( -type d -empty \) -o -not -type d
Ángel
  • 3,589