Page 3 of 3 FirstFirst 123
Results 21 to 23 of 23

Thread: Finding and deleting directories and files with similar names

  1. #21
    Join Date
    Nov 2008
    Beans
    36

    Re: Finding and deleting directories and files with similar names

    For me the best solution was

    Code:
    while read -r dir; do rm "${dir%_files}".html && rm -rf "$dir"; done < folders.txt
    So with this piece of code I was able to purge 900+ folders & files on the basis of folders
    listed in the folders.txt. Steeldriver, thank you very much!

    I especially liked the opportunity to use the folders.txt list, as it provided feedback on how I was
    doing.

    I am intrigued by the expression "${dir%_files}".html - if you have time, please explain how it works.
    Or where can I find more information on this structure.

    Sudodus also, thanks very much for your prompt and helpful action!

  2. #22
    Join Date
    Apr 2012
    Beans
    6,635

    Re: Finding and deleting directories and files with similar names

    Glad that worked for you

    Code:
    ${dir%_files}
    is a bash parameter substitution - it says "remove any trailing portion of dir that matches _files" - so that gives you the basename, then you can add .html to get the html filename corresponding to the dir. The quotes are just good practice to prevent the filename getting split at spaces.

    You can read about it all here --> http://tldp.org/LDP/abs/html/paramet...stitution.html

    It's basically a way of doing variable substitutions natively in the shell - instead of using an external program like 'sed' as another poster suggested

  3. #23
    Join Date
    Nov 2008
    Beans
    36

    Re: Finding and deleting directories and files with similar names

    Thank you - it is so clear
    (when somebody explains it).

Page 3 of 3 FirstFirst 123

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •