+ Reply to Thread
Posts 1 to 4 of 4
  1. #1

    TykeLike

    SimonMac's Avatar
    Join Date
    Aug 2010
    Location
    God's Own Republic Of Yorkshire
    Posts
    21,690
    Thanks (Given)
    206
    Thanks (Received)
    964
    Likes (Given)
    768
    Likes (Received)
    2695

    Default OSX Terminal Help

    Dear Lazyweb, I have a folder on OSX with about 150 other folders within, most of the other folders have a folder in it call XYZ, how would I go about deleting all XYZ folders and anything in that folder without removing anything else.
    “Live a good life. If there are gods and they are just, then they will not care how devout you have been, but will welcome you based on the virtues you have lived by. If there are gods, but unjust, then you should not want to worship them. If there are no gods, then you will be gone, but will have lived a noble life that will live on in the memories of your loved ones.”

    ― Marcus Aurelius

  2. #2

    Nice But Dim

    DaveB's Avatar
    Join Date
    Oct 2005
    Posts
    18,270
    Thanks (Given)
    29
    Thanks (Received)
    659
    Likes (Given)
    289
    Likes (Received)
    2018

    Default

    Quote Originally Posted by SimonMac View Post
    Dear Lazyweb, I have a folder on OSX with about 150 other folders within, most of the other folders have a folder in it call XYZ, how would I go about deleting all XYZ folders and anything in that folder without removing anything else.
    Should be able to do it using Spotlight to search for folders named XYZ within the root folder. Then just highlight and drag and drop to the trash.

    Type XYZ into the search window in Finder, then click the little + button underneath it and modify the search terms to "Kind" "Folder".

    If you are feeling brave you could use the command line via Find and RM, strongly suggest making it interactive with the -i flag on RM!

    cd <folder>
    Find . -name "xyz" -exec rm -ri "{}" \;

    That should find all files with the name "xyz" recursively within the top level folder and delete them asking you to confirm each deletion in turn.
    Last edited by DaveB; 2nd February 2017 at 09:47.
    "Being nice costs nothing and sometimes gets you extra bacon" - Pondlife.

  3. #3

    Ducklike

    Platypus's Avatar
    Join Date
    Dec 2007
    Location
    In the pub
    Posts
    8,250
    Thanks (Given)
    25
    Thanks (Received)
    80
    Likes (Given)
    720
    Likes (Received)
    315

    Default

    Quote Originally Posted by DaveB View Post
    Should be able to do it using Spotlight to search for folders named XYZ within the root folder. Then just highlight and drag and drop to the trash.

    Type XYZ into the search window in Finder, then click the little + button underneath it and modify the search terms to "Kind" "Folder".

    If you are feeling brave you could use the command line via Find and RM, strongly suggest making it interactive with the -i flag on RM!

    cd <folder>
    Find . -name "xyz" -exec rm -ri "{}" \;

    That should find all files with the name "xyz" recursively within the top level folder and delete them asking you to confirm each deletion in turn.
    I think it's

    find . -name "xyz" -exec rm -rf {} \;

    But then I've only been working with Unix for 30 years

    The above command will generate lots of errors as the xyz directories disappear under find's feet, but not to worry

  4. #4

    Nervous Newbie


    Join Date
    Feb 2017
    Location
    London
    Posts
    8
    Thanks (Given)
    1
    Thanks (Received)
    0
    Likes (Given)
    0
    Likes (Received)
    0

    Default

    I do this quiet regularly in order to remove all node_modules or .git folders:

    find . -type d -name "XYZ" -exec rm -rf {} \;

    You can drop this statement while being in the parent directory. I put this terminal statement into a *.sh file which allows me to execute it easily.

Posting Permissions

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

Content Relevant URLs by vBSEO 3.6.0 ©2011, Crawlability, Inc.