Recursively delete empty directories with a dotfile / directory exclusion?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












How do I recursively delete all directories which do not contain any files and make an exclusion of hidden directories?



A lot of the directories that I wish to delete contain hidden directories (dot directories) with files inside them, I do not want these directories.



However, any directories with actually visible files in them - I wish to keep.



Any suggestions?



Example (I wish to delete)



v@localhost:~/test$ ls -al
total 20
drwxrwxr-x 3 v v 4096 Oct 28 04:31 .
drwxr-xr-x 255 v v 12288 Oct 28 04:38 ..
drwxrwxr-x 4 v v 4096 Oct 28 04:31 .hidden


Example (I wish to keep)



v@localhost:~/google.com$ ls -al
total 348
drwxrwxr-x 6 v v 4096 Oct 28 04:39 .
drwxr-xr-x 255 v v 12288 Oct 28 04:38 ..
-rw-rw-r-- 1 v v 54 Oct 28 04:39 BCF9360BE20A13B7DA407BF12AF28650.txt
-rw-rw-r-- 1 v v 254 Oct 28 04:39 crossdomain.xml
-rw-rw-r-- 1 v v 1150 Oct 28 04:39 favicon.ico
-rw-rw-r-- 1 v v 234 Oct 28 04:39 .htaccess
-rw-rw-r-- 1 v v 23 Oct 28 04:39 index.html
-rw-rw-r-- 1 v v 418 Oct 28 04:39 index.php
-rw-rw-r-- 1 v v 19935 Oct 28 04:39 license.txt
-rw-rw-r-- 1 v v 110249 Oct 28 04:39 php_errors.log
-rw-rw-r-- 1 v v 7344 Oct 28 04:39 readme.html
-rw-rw-r-- 1 v v 5456 Oct 28 04:39 wp-activate.php
drwxrwxr-x 9 v v 4096 Oct 28 04:39 wp-admin
-rw-rw-r-- 1 v v 364 Oct 28 04:39 wp-blog-header.php
-rw-rw-r-- 1 v v 1477 Oct 28 04:39 wp-comments-post.php
-rw-rw-r-- 1 v v 3376 Oct 28 04:39 wp-config-local.php
-rw-rw-r-- 1 v v 5219 Oct 28 04:39 wp-config.php
-rw-rw-r-- 1 v v 2853 Oct 28 04:39 wp-config-sample.php
drwxrwxr-x 7 v v 4096 Oct 28 04:39 wp-content
-rw-rw-r-- 1 v v 3286 Oct 28 04:39 wp-cron.php
drwxrwxr-x 17 v v 12288 Oct 28 04:39 wp-includes
-rw-rw-r-- 1 v v 2382 Oct 28 04:39 wp-links-opml.php
-rw-rw-r-- 1 v v 3353 Oct 28 04:39 wp-load.php
-rw-rw-r-- 1 v v 34057 Oct 28 04:39 wp-login.php
-rw-rw-r-- 1 v v 7993 Oct 28 04:39 wp-mail.php
-rw-rw-r-- 1 v v 13920 Oct 28 04:39 wp-settings.php
-rw-rw-r-- 1 v v 29890 Oct 28 04:39 wp-signup.php
-rw-rw-r-- 1 v v 4035 Oct 28 04:39 wp-trackback.php
-rw-rw-r-- 1 v v 3064 Oct 28 04:39 xmlrpc.php








share







New contributor




vazovop is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.























    up vote
    0
    down vote

    favorite












    How do I recursively delete all directories which do not contain any files and make an exclusion of hidden directories?



    A lot of the directories that I wish to delete contain hidden directories (dot directories) with files inside them, I do not want these directories.



    However, any directories with actually visible files in them - I wish to keep.



    Any suggestions?



    Example (I wish to delete)



    v@localhost:~/test$ ls -al
    total 20
    drwxrwxr-x 3 v v 4096 Oct 28 04:31 .
    drwxr-xr-x 255 v v 12288 Oct 28 04:38 ..
    drwxrwxr-x 4 v v 4096 Oct 28 04:31 .hidden


    Example (I wish to keep)



    v@localhost:~/google.com$ ls -al
    total 348
    drwxrwxr-x 6 v v 4096 Oct 28 04:39 .
    drwxr-xr-x 255 v v 12288 Oct 28 04:38 ..
    -rw-rw-r-- 1 v v 54 Oct 28 04:39 BCF9360BE20A13B7DA407BF12AF28650.txt
    -rw-rw-r-- 1 v v 254 Oct 28 04:39 crossdomain.xml
    -rw-rw-r-- 1 v v 1150 Oct 28 04:39 favicon.ico
    -rw-rw-r-- 1 v v 234 Oct 28 04:39 .htaccess
    -rw-rw-r-- 1 v v 23 Oct 28 04:39 index.html
    -rw-rw-r-- 1 v v 418 Oct 28 04:39 index.php
    -rw-rw-r-- 1 v v 19935 Oct 28 04:39 license.txt
    -rw-rw-r-- 1 v v 110249 Oct 28 04:39 php_errors.log
    -rw-rw-r-- 1 v v 7344 Oct 28 04:39 readme.html
    -rw-rw-r-- 1 v v 5456 Oct 28 04:39 wp-activate.php
    drwxrwxr-x 9 v v 4096 Oct 28 04:39 wp-admin
    -rw-rw-r-- 1 v v 364 Oct 28 04:39 wp-blog-header.php
    -rw-rw-r-- 1 v v 1477 Oct 28 04:39 wp-comments-post.php
    -rw-rw-r-- 1 v v 3376 Oct 28 04:39 wp-config-local.php
    -rw-rw-r-- 1 v v 5219 Oct 28 04:39 wp-config.php
    -rw-rw-r-- 1 v v 2853 Oct 28 04:39 wp-config-sample.php
    drwxrwxr-x 7 v v 4096 Oct 28 04:39 wp-content
    -rw-rw-r-- 1 v v 3286 Oct 28 04:39 wp-cron.php
    drwxrwxr-x 17 v v 12288 Oct 28 04:39 wp-includes
    -rw-rw-r-- 1 v v 2382 Oct 28 04:39 wp-links-opml.php
    -rw-rw-r-- 1 v v 3353 Oct 28 04:39 wp-load.php
    -rw-rw-r-- 1 v v 34057 Oct 28 04:39 wp-login.php
    -rw-rw-r-- 1 v v 7993 Oct 28 04:39 wp-mail.php
    -rw-rw-r-- 1 v v 13920 Oct 28 04:39 wp-settings.php
    -rw-rw-r-- 1 v v 29890 Oct 28 04:39 wp-signup.php
    -rw-rw-r-- 1 v v 4035 Oct 28 04:39 wp-trackback.php
    -rw-rw-r-- 1 v v 3064 Oct 28 04:39 xmlrpc.php








    share







    New contributor




    vazovop is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      How do I recursively delete all directories which do not contain any files and make an exclusion of hidden directories?



      A lot of the directories that I wish to delete contain hidden directories (dot directories) with files inside them, I do not want these directories.



      However, any directories with actually visible files in them - I wish to keep.



      Any suggestions?



      Example (I wish to delete)



      v@localhost:~/test$ ls -al
      total 20
      drwxrwxr-x 3 v v 4096 Oct 28 04:31 .
      drwxr-xr-x 255 v v 12288 Oct 28 04:38 ..
      drwxrwxr-x 4 v v 4096 Oct 28 04:31 .hidden


      Example (I wish to keep)



      v@localhost:~/google.com$ ls -al
      total 348
      drwxrwxr-x 6 v v 4096 Oct 28 04:39 .
      drwxr-xr-x 255 v v 12288 Oct 28 04:38 ..
      -rw-rw-r-- 1 v v 54 Oct 28 04:39 BCF9360BE20A13B7DA407BF12AF28650.txt
      -rw-rw-r-- 1 v v 254 Oct 28 04:39 crossdomain.xml
      -rw-rw-r-- 1 v v 1150 Oct 28 04:39 favicon.ico
      -rw-rw-r-- 1 v v 234 Oct 28 04:39 .htaccess
      -rw-rw-r-- 1 v v 23 Oct 28 04:39 index.html
      -rw-rw-r-- 1 v v 418 Oct 28 04:39 index.php
      -rw-rw-r-- 1 v v 19935 Oct 28 04:39 license.txt
      -rw-rw-r-- 1 v v 110249 Oct 28 04:39 php_errors.log
      -rw-rw-r-- 1 v v 7344 Oct 28 04:39 readme.html
      -rw-rw-r-- 1 v v 5456 Oct 28 04:39 wp-activate.php
      drwxrwxr-x 9 v v 4096 Oct 28 04:39 wp-admin
      -rw-rw-r-- 1 v v 364 Oct 28 04:39 wp-blog-header.php
      -rw-rw-r-- 1 v v 1477 Oct 28 04:39 wp-comments-post.php
      -rw-rw-r-- 1 v v 3376 Oct 28 04:39 wp-config-local.php
      -rw-rw-r-- 1 v v 5219 Oct 28 04:39 wp-config.php
      -rw-rw-r-- 1 v v 2853 Oct 28 04:39 wp-config-sample.php
      drwxrwxr-x 7 v v 4096 Oct 28 04:39 wp-content
      -rw-rw-r-- 1 v v 3286 Oct 28 04:39 wp-cron.php
      drwxrwxr-x 17 v v 12288 Oct 28 04:39 wp-includes
      -rw-rw-r-- 1 v v 2382 Oct 28 04:39 wp-links-opml.php
      -rw-rw-r-- 1 v v 3353 Oct 28 04:39 wp-load.php
      -rw-rw-r-- 1 v v 34057 Oct 28 04:39 wp-login.php
      -rw-rw-r-- 1 v v 7993 Oct 28 04:39 wp-mail.php
      -rw-rw-r-- 1 v v 13920 Oct 28 04:39 wp-settings.php
      -rw-rw-r-- 1 v v 29890 Oct 28 04:39 wp-signup.php
      -rw-rw-r-- 1 v v 4035 Oct 28 04:39 wp-trackback.php
      -rw-rw-r-- 1 v v 3064 Oct 28 04:39 xmlrpc.php








      share







      New contributor




      vazovop is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      How do I recursively delete all directories which do not contain any files and make an exclusion of hidden directories?



      A lot of the directories that I wish to delete contain hidden directories (dot directories) with files inside them, I do not want these directories.



      However, any directories with actually visible files in them - I wish to keep.



      Any suggestions?



      Example (I wish to delete)



      v@localhost:~/test$ ls -al
      total 20
      drwxrwxr-x 3 v v 4096 Oct 28 04:31 .
      drwxr-xr-x 255 v v 12288 Oct 28 04:38 ..
      drwxrwxr-x 4 v v 4096 Oct 28 04:31 .hidden


      Example (I wish to keep)



      v@localhost:~/google.com$ ls -al
      total 348
      drwxrwxr-x 6 v v 4096 Oct 28 04:39 .
      drwxr-xr-x 255 v v 12288 Oct 28 04:38 ..
      -rw-rw-r-- 1 v v 54 Oct 28 04:39 BCF9360BE20A13B7DA407BF12AF28650.txt
      -rw-rw-r-- 1 v v 254 Oct 28 04:39 crossdomain.xml
      -rw-rw-r-- 1 v v 1150 Oct 28 04:39 favicon.ico
      -rw-rw-r-- 1 v v 234 Oct 28 04:39 .htaccess
      -rw-rw-r-- 1 v v 23 Oct 28 04:39 index.html
      -rw-rw-r-- 1 v v 418 Oct 28 04:39 index.php
      -rw-rw-r-- 1 v v 19935 Oct 28 04:39 license.txt
      -rw-rw-r-- 1 v v 110249 Oct 28 04:39 php_errors.log
      -rw-rw-r-- 1 v v 7344 Oct 28 04:39 readme.html
      -rw-rw-r-- 1 v v 5456 Oct 28 04:39 wp-activate.php
      drwxrwxr-x 9 v v 4096 Oct 28 04:39 wp-admin
      -rw-rw-r-- 1 v v 364 Oct 28 04:39 wp-blog-header.php
      -rw-rw-r-- 1 v v 1477 Oct 28 04:39 wp-comments-post.php
      -rw-rw-r-- 1 v v 3376 Oct 28 04:39 wp-config-local.php
      -rw-rw-r-- 1 v v 5219 Oct 28 04:39 wp-config.php
      -rw-rw-r-- 1 v v 2853 Oct 28 04:39 wp-config-sample.php
      drwxrwxr-x 7 v v 4096 Oct 28 04:39 wp-content
      -rw-rw-r-- 1 v v 3286 Oct 28 04:39 wp-cron.php
      drwxrwxr-x 17 v v 12288 Oct 28 04:39 wp-includes
      -rw-rw-r-- 1 v v 2382 Oct 28 04:39 wp-links-opml.php
      -rw-rw-r-- 1 v v 3353 Oct 28 04:39 wp-load.php
      -rw-rw-r-- 1 v v 34057 Oct 28 04:39 wp-login.php
      -rw-rw-r-- 1 v v 7993 Oct 28 04:39 wp-mail.php
      -rw-rw-r-- 1 v v 13920 Oct 28 04:39 wp-settings.php
      -rw-rw-r-- 1 v v 29890 Oct 28 04:39 wp-signup.php
      -rw-rw-r-- 1 v v 4035 Oct 28 04:39 wp-trackback.php
      -rw-rw-r-- 1 v v 3064 Oct 28 04:39 xmlrpc.php






      linux find





      share







      New contributor




      vazovop is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share







      New contributor




      vazovop is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share



      share






      New contributor




      vazovop is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 4 mins ago









      vazovop

      1




      1




      New contributor




      vazovop is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      vazovop is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      vazovop is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.

























          active

          oldest

          votes











          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );






          vazovop is a new contributor. Be nice, and check out our Code of Conduct.









           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f478201%2frecursively-delete-empty-directories-with-a-dotfile-directory-exclusion%23new-answer', 'question_page');

          );

          Post as a guest



































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          vazovop is a new contributor. Be nice, and check out our Code of Conduct.









           

          draft saved


          draft discarded


















          vazovop is a new contributor. Be nice, and check out our Code of Conduct.












          vazovop is a new contributor. Be nice, and check out our Code of Conduct.











          vazovop is a new contributor. Be nice, and check out our Code of Conduct.













           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f478201%2frecursively-delete-empty-directories-with-a-dotfile-directory-exclusion%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Christian Cage

          How to properly install USB display driver for Fresco Logic FL2000DX on Ubuntu?