Looking all over for a solution, but can't find it. Somehow I am always trying unique scenarios that no one ever thinks of. Weird. Anyway here is the scenario...
foldertop (keep)
-foldersub (keep)
--foldersubsub (keep)
----foldersubsubsub (keep)
------files (exclude)
----files (exclude)
--files (keep)
-files (keep)
I want to tar all directories and subdirectories. I want the entire folder structure, but I don't want all files. I want to keep some files from some folders and leave out other files from other directories.
The only thing i know to do is to exclude the folders of the files i don't want like so:
tar -cvf bak_1-28-15.tar --exclude=foldertop/foldersub/foldersubsub foldertop
Maybe i can add a star to keep the foldersubsub directory and exclude all the files within it like this:
tar -cvf bak_1-28-15.tar --exclude=foldertop/foldersub/foldersubsub/* foldertop
But that will exclude the foldersubsubsub directory as well. i want to exclude all the files in foldersubsubsub but keep the foldersubsubsub directory.
How can i do this scenario?
tried this without find method. doesn't work:
tar -cvf bak_1-28-15.tar --exclude=foldertop/foldersub/foldersubsub/* --include=foldertop/foldersub/foldersubsub/foldersubsubsub --exclude=foldertop/foldersub/foldersubsub/foldersubsubsub/* foldertop
the error i get is:
tar: unrecognized option '--include=foldertop/foldersub/foldersubsub/foldersubsubsub'
putting include at the end didn't work either, it's still an unrecognized option.
tar -cvf bak_1-28-15.tar --exclude=foldertop/foldersub/foldersubsub/* --exclude=foldertop/foldersub/foldersubsub/foldersubsubsub/* --include=foldertop/foldersub/foldersubsub/foldersubsubsub foldertop
putting folder at the end without an include in the middle doesn't work either. doesn't give and error, but the foldersubsubsub directory is not included.
tar -cvf bak_1-28-15.tar --exclude=foldertop/foldersub/foldersubsub/* --exclude=foldertop/foldersub/foldersubsub/foldersubsubsub/* foldertop foldertop/foldersub/foldersubsub/foldersubsubsub
next going to try star*.star* so i only target files and not folders. like this:
tar -cvf bak_1-28-15.tar --exclude=foldertop/foldersub/foldersubsub/*.* --exclude=foldertop/foldersub/foldersubsub/foldersubsubsub/*.* foldertop
that seems to have done the trick. this works for me since there will be no files without dots, and there will also be no files that begin with a dot.
find foldertop | grep -v "foldersubsubsub/files" | xargs tar -cvf tarFileName.tar
应该这样做。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.