Skip to content

Instantly share code, notes, and snippets.

@raphaelchaib
Last active December 20, 2015 04:39
Show Gist options
  • Select an option

  • Save raphaelchaib/6072977 to your computer and use it in GitHub Desktop.

Select an option

Save raphaelchaib/6072977 to your computer and use it in GitHub Desktop.
Exclude files and directories via Linux's shell, except some of them.
find . ! -name one ! -name two -maxdepth 1 -type f -delete
! negates the next expresso
-name specifies a filename
-maxdepth 1 will make find process the specified directory only (find per default traverses directories)
-type f will process only files (and not for example directories)
-delete will delete the files
You can then tune the conditions looking at the man page of find
keep in mind that the order of the elements of the expressions is significant (see the documentation)
test your command first by using -print instead of -delete
> find . ! -name u ! -name p -maxdepth 1 -type f -print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment