How can I exclude a directory in find and rsync but include specific files?

0
1
Asked By TechWhiz42 On

I'm trying to figure out how to use find and rsync to manage my dotfiles. Specifically, I want to exclude the .mozilla folder and a few other directories, but I still need to keep certain files related to Firefox, like login data. Right now, I've been using a command like:

find -path '*/.*' -not -path '*/.cache/*' -not -path '*/.mozilla/*' -path '*/.mozilla/firefox/*.default-release/{autofill-profiles,signedInUser,prefs}.js*' > dotfiles

However, this command gives me an empty output. I need some guidance on how to exclude most things in a directory while still including specific files. I also want to know how to apply this for rsync (and possibly tar) later on.

2 Answers

Answered By ShellSavant99 On

The way -path works is more like shell globbing and it doesn't handle brace expansions. Consider breaking your task into two parts—it simplifies things. For example, you could use commands like:

find . ( -path ./.cache -o -path ./.mozilla ) -prune -o -type f -name '.*' -print

And separately target .mozilla/firefox/*.default to find the specific files like prefs.js or autofill-profiles.js. It makes it cleaner and more manageable.

AutomateAce33 -

Exactly! Splitting your approach is much clearer, and it really helps in the long run.

Answered By CodeNinja88 On

For rsync, if you have a set of file names that you know won't change, you can list them in a text file and use the --files-from=foo.txt option. Just keep in mind that using this method won't maintain recursion, so you might need to run another rsync call for additional depth if that's important.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.