Skip to content

Instantly share code, notes, and snippets.

@ed-george
Created March 31, 2014 19:05
Show Gist options
  • Save ed-george/9899756 to your computer and use it in GitHub Desktop.
Save ed-george/9899756 to your computer and use it in GitHub Desktop.
Clean folder by moving all files not appended with underscore to Trash (Mac Only)
ls -1 | grep -v '^_' | xargs -I '{}' mv {} ~/.Trash
@apinkney97
Copy link

You should probably use find -print0 and xargs -0 rather than ls, as if you have any filenames with spaces in, it will break the xargs mv

so like

find . -maxdepth 1 -print0 ! -name '_*' | xargs -0 -I '{}' mv {} ~/.Trash

...and maybe use -type f as a form of damage limitation?

@ed-george
Copy link
Author

Seems to work fine with files that have a space.
But I must admit, I am not sure why.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment