Skip to content

Instantly share code, notes, and snippets.

@mertenvg
Last active November 11, 2016 10:43
Show Gist options
  • Save mertenvg/1bf5d1a10ad77f53a348d1a390bc8d5f to your computer and use it in GitHub Desktop.
Save mertenvg/1bf5d1a10ad77f53a348d1a390bc8d5f to your computer and use it in GitHub Desktop.
Useful bash snippets
#
# Remove all but last subdirectories from all but last 2 directories in current directory
#
ls | head -n -2 | xargs -r ls | head -n -1 | xargs -r rm -rf
find . -mindepth 1 -maxdepth 1 -type d | \
sort | head -n -1 | xargs -r -I {} find {} -mindepth 1 -maxdepth 1 -type d | \
sort | head -n -1 | xargs -r rm -rf
#
# remove all but last 14 directories
#
ls | head -n -14 | xargs -r rm -rf
find . -mindepth 1 -maxdepth 1 -type d | \
sort | head -n -14 | xargs -r rm -rf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment