2

Say I did a

ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/* /usr/local/include/

Now I regret it. How can I delete all these links? The good news is I created them today, so can I filter on the creation date of these symlinks?

1

If you want to make sure you only remove the symlinks created you can run

cd /usr/local/include
rm $(cd /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/; echo *)

This does not work if the filenames contain spaces etc., but for this specific case this isn't an issue.

1

Inspired by How to delete files from a specific date?:

# Create a marker
touch -t 201910190000.00 /tmp/PID$$.marker1

# View the files you would like to delete
find /usr/local/include/ -type l -newer /tmp/PID56680.marker1 -ls | less

# Delete them
find /usr/local/include/ -type l -newer /tmp/PID56680.marker1 | xargs rm -f
  • 2
    It might be important to know which symlinks couldn‘t be removed so you probably are better off without the -f option. – nohillside Oct 19 at 6:19
  • Doesn't find have a -delete operator instead of using xargs and rm? – Bakuriu Oct 19 at 13:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .