Quote:
Originally Posted by Cerephim
Okay, I think I understand what you're doing...
However, the output of the find command needs to be edited via grep for hidden files that shouldn't be removed like:
.bashrc
.bash_profile
etc.
How can I feed the output of the grep command into the tar command? Everytime I try, it fails.
|
Hey, I said it was simplistic
But I think what you want is to go more complex...
Allright, lets try this: you can chain rules in find, and inside each rule, you can run execs!
Lets start with this:
(Note, this only works if you give it the full path, because I'm too tired to craft a more clever first-expression here)
find /home/ \( -type d -name ".*" -prune \) -o \( -type f ! -name ".*" \)
find /home
#List things in home
\( -type d -name ".*" -prune \)
#Prune (don't look in) directories that start with "."
-o
#or
\( -type f ! -name ".*" \)
#look only at files that don't start with "."
Now, if that made sense... we add two execs
find /home/ \( -type d -name ".*" -prune \) -o \( -type f ! -name ".*" -exec tar -rvf /path/to/my/archive.tar {} \; rm -f {} \; \)
To break that last expression down:
-type f
#Look at files
! -name ".*"
#not starting with "."
-exec tar -rvf /path/to/my/archive.tar {} \;
#append the files to the tar file /path/to/my/archive.tar
rm -f {} \;
#remove the file
The exec _only_ works on the files, not the directories since it's enclosed in the parenthesis \(\), so there may be empty directories laying around afterwards.
Does that help at all?
PS: Thanks for asking the question, it forced me to remember some find kung-foo I hadn't done in years!