Skip to main content
added 6 characters in body
Source Link
Graeme
  • 34.7k
  • 9
  • 90
  • 110

I am a little confused by wording of the question. If what you want to do is delete everything in the ./Library/Caches directory apart from a single folder called Snapshots, there is no need to use find. In bash, shell globs are the simplest way:

shopt -s extglob # probably already enabled echo Library/Caches/!(Snapshots) 

If this prints all the files/directories that you want to delete, then replace echo by rm -f --.

If there are multiple Snapshots directories at different levels of the directory tree below ./Library/Caches that you want to preserve, then with GNU find you can do:

find Library/Caches ! -path '*Snapshots*' 

This should print all files/directories excluding those that have Snapshots in their path. It will include directories that contain (or whose children contain) Snapshots directories, however find ... -delete will not delete those and instead print an error that they are not empty. Once you are happy, add -delete to the end.

One caveat is that this will leave any files named Snapshots intact. If this is a problem, instead do:

find Library/Caches \( ! -path '*Snapshots*' -o -type f -name Snapshots \) 

Again add -delete when happy.

I am a little confused by wording of the question. If what you want to do is delete everything in the ./Library/Caches directory apart from a single folder called Snapshots, there is no need to use find. In bash, shell globs are the simplest way:

shopt -s extglob # probably already enabled echo Library/Caches/!(Snapshots) 

If this prints all the files/directories that you want to delete, then replace echo by rm -f --.

If there are multiple Snapshots directories at different levels of the directory tree below ./Library/Caches that you want to preserve, then with GNU find you can do:

find Library/Caches ! -path '*Snapshots*' 

This should print all files/directories excluding those that have Snapshots in their path. It will include directories that contain (or whose children contain) Snapshots directories, however find ... -delete will not delete those and instead print an error that they are not empty. Once you are happy, add -delete to the end.

One caveat is that this will leave any files named Snapshots intact. If this is a problem, instead do:

find Library/Caches ! -path '*Snapshots*' -o -type f -name Snapshots 

Again add -delete when happy.

I am a little confused by wording of the question. If what you want to do is delete everything in the ./Library/Caches directory apart from a single folder called Snapshots, there is no need to use find. In bash, shell globs are the simplest way:

shopt -s extglob # probably already enabled echo Library/Caches/!(Snapshots) 

If this prints all the files/directories that you want to delete, then replace echo by rm -f --.

If there are multiple Snapshots directories at different levels of the directory tree below ./Library/Caches that you want to preserve, then with GNU find you can do:

find Library/Caches ! -path '*Snapshots*' 

This should print all files/directories excluding those that have Snapshots in their path. It will include directories that contain (or whose children contain) Snapshots directories, however find ... -delete will not delete those and instead print an error that they are not empty. Once you are happy, add -delete to the end.

One caveat is that this will leave any files named Snapshots intact. If this is a problem, instead do:

find Library/Caches \( ! -path '*Snapshots*' -o -type f -name Snapshots \) 

Again add -delete when happy.

deleted 1 character in body
Source Link
Graeme
  • 34.7k
  • 9
  • 90
  • 110

I am a little confused by wording of the question. If what you want to do is delete everything in the ./Library/Caches directory apart from a single folder called Snapshots, there is no need to use find. In bash, shell globs are the simplest way:

shopt -s extglob # probably already enabled echo Library/Caches/!(Snapshots) 

If this prints all the files/directories that you want to delete, then replace echo by rm -f --.

If there are multiple Snapshots directories at different levels of the directory tree below ./Library/Caches that you want to preserve, then with GNU find you can do:

find ./Library/CacheCaches ! -path '*Snapshots*' 

This should print all files/directories excluding those that have Snapshots in their path. It will include directories that contain (or whose children contain) Snapshots directories, however find ... -delete will not delete those and instead print an error that they are not empty. Once you are happy, add -delete to the end.

One caveat is that this will leave any files named Snapshots intact. If this is a problem, instead do:

find .Library/CacheCaches ! -path '*Snapshots*' -o -type f -name Snapshots 

Again add -delete when happy.

I am a little confused by wording of the question. If what you want to do is delete everything in the ./Library/Caches directory apart from a single folder called Snapshots, there is no need to use find. In bash, shell globs are the simplest way:

shopt -s extglob # probably already enabled echo Library/Caches/!(Snapshots) 

If this prints all the files/directories that you want to delete, then replace echo by rm -f.

If there are multiple Snapshots directories at different levels of the directory tree below ./Library/Caches that you want to preserve, then with GNU find you can do:

find ./Library/Cache ! -path '*Snapshots*' 

This should print all files/directories excluding those that have Snapshots in their path. It will include directories that contain (or whose children contain) Snapshots directories, however find ... -delete will not delete those and instead print an error that they are not empty. Once you are happy, add -delete to the end.

One caveat is that this will leave any files named Snapshots intact. If this is a problem, instead do:

find .Library/Cache ! -path '*Snapshots*' -o -type f -name Snapshots 

Again add -delete when happy.

I am a little confused by wording of the question. If what you want to do is delete everything in the ./Library/Caches directory apart from a single folder called Snapshots, there is no need to use find. In bash, shell globs are the simplest way:

shopt -s extglob # probably already enabled echo Library/Caches/!(Snapshots) 

If this prints all the files/directories that you want to delete, then replace echo by rm -f --.

If there are multiple Snapshots directories at different levels of the directory tree below ./Library/Caches that you want to preserve, then with GNU find you can do:

find Library/Caches ! -path '*Snapshots*' 

This should print all files/directories excluding those that have Snapshots in their path. It will include directories that contain (or whose children contain) Snapshots directories, however find ... -delete will not delete those and instead print an error that they are not empty. Once you are happy, add -delete to the end.

One caveat is that this will leave any files named Snapshots intact. If this is a problem, instead do:

find Library/Caches ! -path '*Snapshots*' -o -type f -name Snapshots 

Again add -delete when happy.

deleted 5 characters in body
Source Link
Graeme
  • 34.7k
  • 9
  • 90
  • 110

I am a little confused by wording of the question. If what you want to do is delete everything in the ./Library/Caches directory apart from a single folder called Snapshots, there is no need to use find. In bash, shell globs are the simplest way:

shopt -s extglob # probably already enabled echo Library/Caches/!(Snapshots) 

If this prints all the files/directories that you want to delete, thethen replace echo by rm -f.

If there are multiple Snapshots directories at different levels of the directory tree below ./Library/Caches that you want to preserve, then with GNU find you can do:

find ./Library/Cache ! -path '*Snapshots*' 

This should print all files/directories excluding those that have Snapshots in their path. It will include directories that contain (or whose children contain) Snapshots directories, however find ... -delete will not delete those since and instead print an error that they are not empty. Once you are happy, add -delete to the end.

One caveat is that this will leave any files named Snapshots intact. If this is a problem, instead do:

find .Library/Cache ! -path '*Snapshots*' -o -type f -name Snapshots 

Again add -delete when happy.

I am a little confused by wording of the question. If what you want to do is delete everything in the ./Library/Caches directory apart from a single folder called Snapshots, there is no need to use find. In bash, shell globs are the simplest way:

shopt -s extglob # probably already enabled echo Library/Caches/!(Snapshots) 

If this prints all the files/directories that you want to delete, the replace echo by rm -f.

If there are multiple Snapshots directories at different levels of the directory tree below ./Library/Caches that you want to preserve, then with GNU find you can do:

find ./Library/Cache ! -path '*Snapshots*' 

This should print all files/directories excluding those that have Snapshots in their path. It will include directories that contain (or whose children contain) Snapshots directories, however find ... -delete will not delete those since and instead print an error that they are not empty. Once you are happy, add -delete to the end.

One caveat is that this will leave any files named Snapshots intact. If this is a problem, instead do:

find .Library/Cache ! -path '*Snapshots*' -o -type f -name Snapshots 

Again add -delete when happy.

I am a little confused by wording of the question. If what you want to do is delete everything in the ./Library/Caches directory apart from a single folder called Snapshots, there is no need to use find. In bash, shell globs are the simplest way:

shopt -s extglob # probably already enabled echo Library/Caches/!(Snapshots) 

If this prints all the files/directories that you want to delete, then replace echo by rm -f.

If there are multiple Snapshots directories at different levels of the directory tree below ./Library/Caches that you want to preserve, then with GNU find you can do:

find ./Library/Cache ! -path '*Snapshots*' 

This should print all files/directories excluding those that have Snapshots in their path. It will include directories that contain (or whose children contain) Snapshots directories, however find ... -delete will not delete those and instead print an error that they are not empty. Once you are happy, add -delete to the end.

One caveat is that this will leave any files named Snapshots intact. If this is a problem, instead do:

find .Library/Cache ! -path '*Snapshots*' -o -type f -name Snapshots 

Again add -delete when happy.

added 54 characters in body
Source Link
Graeme
  • 34.7k
  • 9
  • 90
  • 110
Loading
Source Link
Graeme
  • 34.7k
  • 9
  • 90
  • 110
Loading