+ 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,952
    Thanks (Given)
    224
    Thanks (Received)
    1057
    Likes (Given)
    798
    Likes (Received)
    2882

    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,645
    Thanks (Given)
    35
    Thanks (Received)
    754
    Likes (Given)
    345
    Likes (Received)
    2307

    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 08: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,374
    Thanks (Given)
    25
    Thanks (Received)
    95
    Likes (Given)
    811
    Likes (Received)
    359

    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
    14
    Thanks (Given)
    1
    Thanks (Received)
    1
    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.