Recursively exclude directory with pattern using tar2019 Community Moderator ElectionHow to XZ a directory with TAR using maximum compression?tar --exclude doesn't exclude. Why?Restoring file system using tar causes login loopTar --exclude directory isn't being excludedExclude subdirectory of included directory with tarCreating a tar file using remove-files and excludeDefault Tar DirectoryExclude some files when extracting with tarrsync-like updating of archive filetar directory and exclude multiple subdirectories
What can I do if I am asked to learn different programming languages very frequently?
Make a Bowl of Alphabet Soup
Why does a 97 / 92 key piano exist by Bosendorfer?
Why is participating in the European Parliamentary elections used as a threat?
Has the laser at Magurele, Romania reached a tenth of the Sun's power?
Turning a hard to access nut?
What is the tangent at a sharp point on a curve?
How to get directions in deep space?
Started in 1987 vs. Starting in 1987
PTIJ: Which Dr. Seuss books should one obtain?
Unfrosted light bulb
What is the purpose of using a decision tree?
Is there a POSIX way to shutdown a UNIX machine?
Why do Radio Buttons not fill the entire outer circle?
"Marked down as someone wanting to sell shares." What does that mean?
What should be the ideal length of sentences in a blog post for ease of reading?
Highest stage count that are used one right after the other?
What is it called when someone votes for an option that's not their first choice?
Non-Borel set in arbitrary metric space
Should I warn a new PhD Student?
Do people actually use the word "kaputt" in conversation?
My contractor has questionable methods
Do native speakers use "ultima" and "proxima" frequently in spoken English?
How can a new country break out from a developed country without war?
Recursively exclude directory with pattern using tar
2019 Community Moderator ElectionHow to XZ a directory with TAR using maximum compression?tar --exclude doesn't exclude. Why?Restoring file system using tar causes login loopTar --exclude directory isn't being excludedExclude subdirectory of included directory with tarCreating a tar file using remove-files and excludeDefault Tar DirectoryExclude some files when extracting with tarrsync-like updating of archive filetar directory and exclude multiple subdirectories
I have a directory with various python packages that I'd like to archive using tar. I need to exclude the numerous __pycache__
folders that get left behind by the build/testing process but using --exclude "__pycache__"
will not achieve this. How can I get tar to ignore all subdirectories that match that pattern?
tar -cvf myarchive.tar -C ~/myproject package1/ package2/ --exclude "__pycache__"
To recreate:
me@me-laptop:~/myproject$ pwd
/home/me/myproject
me@me-laptop:~/myproject$ tree
.
├── package1
│ ├── include
│ └── __pycache__
└── package2
├── include
└── __pycache__
6 directories, 0 files
me@me-laptop:~/myproject$ tar -cvf myarchive.tar -C ~/myproject package1/ package2/ --exclude "__pycache__"
package1/
package1/include/
package1/__pycache__/
package2/
package2/include/
package2/__pycache__/
linux directory tar
New contributor
|
show 1 more comment
I have a directory with various python packages that I'd like to archive using tar. I need to exclude the numerous __pycache__
folders that get left behind by the build/testing process but using --exclude "__pycache__"
will not achieve this. How can I get tar to ignore all subdirectories that match that pattern?
tar -cvf myarchive.tar -C ~/myproject package1/ package2/ --exclude "__pycache__"
To recreate:
me@me-laptop:~/myproject$ pwd
/home/me/myproject
me@me-laptop:~/myproject$ tree
.
├── package1
│ ├── include
│ └── __pycache__
└── package2
├── include
└── __pycache__
6 directories, 0 files
me@me-laptop:~/myproject$ tar -cvf myarchive.tar -C ~/myproject package1/ package2/ --exclude "__pycache__"
package1/
package1/include/
package1/__pycache__/
package2/
package2/include/
package2/__pycache__/
linux directory tar
New contributor
I can't seem to reproduce this with a basic directory tree. Can you show us the directory structure you have on your system?
– Haxiel
16 hours ago
added an example
– ptr
15 hours ago
for reference, I'm currently on ubuntu 18.04 but this is also happening on centos7
– ptr
15 hours ago
Thanks for the update, but I still can't reproduce this. I'm on an RHEL 7 system with GNUtar
1.26 (which would be identical to your CentOS system). Copy-pasting the exact same command from your question works for me.
– Haxiel
15 hours ago
my apologies, it does work on centos, i must have used a different flag the time it didn't work. So is it a difference between ubuntu and centos' tar versions?
– ptr
15 hours ago
|
show 1 more comment
I have a directory with various python packages that I'd like to archive using tar. I need to exclude the numerous __pycache__
folders that get left behind by the build/testing process but using --exclude "__pycache__"
will not achieve this. How can I get tar to ignore all subdirectories that match that pattern?
tar -cvf myarchive.tar -C ~/myproject package1/ package2/ --exclude "__pycache__"
To recreate:
me@me-laptop:~/myproject$ pwd
/home/me/myproject
me@me-laptop:~/myproject$ tree
.
├── package1
│ ├── include
│ └── __pycache__
└── package2
├── include
└── __pycache__
6 directories, 0 files
me@me-laptop:~/myproject$ tar -cvf myarchive.tar -C ~/myproject package1/ package2/ --exclude "__pycache__"
package1/
package1/include/
package1/__pycache__/
package2/
package2/include/
package2/__pycache__/
linux directory tar
New contributor
I have a directory with various python packages that I'd like to archive using tar. I need to exclude the numerous __pycache__
folders that get left behind by the build/testing process but using --exclude "__pycache__"
will not achieve this. How can I get tar to ignore all subdirectories that match that pattern?
tar -cvf myarchive.tar -C ~/myproject package1/ package2/ --exclude "__pycache__"
To recreate:
me@me-laptop:~/myproject$ pwd
/home/me/myproject
me@me-laptop:~/myproject$ tree
.
├── package1
│ ├── include
│ └── __pycache__
└── package2
├── include
└── __pycache__
6 directories, 0 files
me@me-laptop:~/myproject$ tar -cvf myarchive.tar -C ~/myproject package1/ package2/ --exclude "__pycache__"
package1/
package1/include/
package1/__pycache__/
package2/
package2/include/
package2/__pycache__/
linux directory tar
linux directory tar
New contributor
New contributor
edited 15 hours ago
Jeff Schaller
43.5k1161140
43.5k1161140
New contributor
asked 16 hours ago
ptrptr
1033
1033
New contributor
New contributor
I can't seem to reproduce this with a basic directory tree. Can you show us the directory structure you have on your system?
– Haxiel
16 hours ago
added an example
– ptr
15 hours ago
for reference, I'm currently on ubuntu 18.04 but this is also happening on centos7
– ptr
15 hours ago
Thanks for the update, but I still can't reproduce this. I'm on an RHEL 7 system with GNUtar
1.26 (which would be identical to your CentOS system). Copy-pasting the exact same command from your question works for me.
– Haxiel
15 hours ago
my apologies, it does work on centos, i must have used a different flag the time it didn't work. So is it a difference between ubuntu and centos' tar versions?
– ptr
15 hours ago
|
show 1 more comment
I can't seem to reproduce this with a basic directory tree. Can you show us the directory structure you have on your system?
– Haxiel
16 hours ago
added an example
– ptr
15 hours ago
for reference, I'm currently on ubuntu 18.04 but this is also happening on centos7
– ptr
15 hours ago
Thanks for the update, but I still can't reproduce this. I'm on an RHEL 7 system with GNUtar
1.26 (which would be identical to your CentOS system). Copy-pasting the exact same command from your question works for me.
– Haxiel
15 hours ago
my apologies, it does work on centos, i must have used a different flag the time it didn't work. So is it a difference between ubuntu and centos' tar versions?
– ptr
15 hours ago
I can't seem to reproduce this with a basic directory tree. Can you show us the directory structure you have on your system?
– Haxiel
16 hours ago
I can't seem to reproduce this with a basic directory tree. Can you show us the directory structure you have on your system?
– Haxiel
16 hours ago
added an example
– ptr
15 hours ago
added an example
– ptr
15 hours ago
for reference, I'm currently on ubuntu 18.04 but this is also happening on centos7
– ptr
15 hours ago
for reference, I'm currently on ubuntu 18.04 but this is also happening on centos7
– ptr
15 hours ago
Thanks for the update, but I still can't reproduce this. I'm on an RHEL 7 system with GNU
tar
1.26 (which would be identical to your CentOS system). Copy-pasting the exact same command from your question works for me.– Haxiel
15 hours ago
Thanks for the update, but I still can't reproduce this. I'm on an RHEL 7 system with GNU
tar
1.26 (which would be identical to your CentOS system). Copy-pasting the exact same command from your question works for me.– Haxiel
15 hours ago
my apologies, it does work on centos, i must have used a different flag the time it didn't work. So is it a difference between ubuntu and centos' tar versions?
– ptr
15 hours ago
my apologies, it does work on centos, i must have used a different flag the time it didn't work. So is it a difference between ubuntu and centos' tar versions?
– ptr
15 hours ago
|
show 1 more comment
1 Answer
1
active
oldest
votes
You need to add the --exclude
switch at the beginning of the command, see this. This solution works on my openSUSE machine, I don't have other distros available right now.
host:/tmp # find test*
test1
test1/file1
test1/__pycache__
test1/__pycache__/file1-py
test1/include
test1/include/file1-incl
test2
test2/__pycache__
test2/__pycache__/file2-py
test2/include
test2/include/file2-incl
test2/file2
host: # tar --exclude='__pycache__' -cv test* -f testtar.tar
test1/
test1/file1
test1/include/
test1/include/file1-incl
test2/
test2/include/
test2/include/file2-incl
test2/file2
This works on both Ubuntu and Centos, odd that the centos version accepts the--exclude
at the end of the line
– ptr
15 hours ago
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
ptr is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f507179%2frecursively-exclude-directory-with-pattern-using-tar%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need to add the --exclude
switch at the beginning of the command, see this. This solution works on my openSUSE machine, I don't have other distros available right now.
host:/tmp # find test*
test1
test1/file1
test1/__pycache__
test1/__pycache__/file1-py
test1/include
test1/include/file1-incl
test2
test2/__pycache__
test2/__pycache__/file2-py
test2/include
test2/include/file2-incl
test2/file2
host: # tar --exclude='__pycache__' -cv test* -f testtar.tar
test1/
test1/file1
test1/include/
test1/include/file1-incl
test2/
test2/include/
test2/include/file2-incl
test2/file2
This works on both Ubuntu and Centos, odd that the centos version accepts the--exclude
at the end of the line
– ptr
15 hours ago
add a comment |
You need to add the --exclude
switch at the beginning of the command, see this. This solution works on my openSUSE machine, I don't have other distros available right now.
host:/tmp # find test*
test1
test1/file1
test1/__pycache__
test1/__pycache__/file1-py
test1/include
test1/include/file1-incl
test2
test2/__pycache__
test2/__pycache__/file2-py
test2/include
test2/include/file2-incl
test2/file2
host: # tar --exclude='__pycache__' -cv test* -f testtar.tar
test1/
test1/file1
test1/include/
test1/include/file1-incl
test2/
test2/include/
test2/include/file2-incl
test2/file2
This works on both Ubuntu and Centos, odd that the centos version accepts the--exclude
at the end of the line
– ptr
15 hours ago
add a comment |
You need to add the --exclude
switch at the beginning of the command, see this. This solution works on my openSUSE machine, I don't have other distros available right now.
host:/tmp # find test*
test1
test1/file1
test1/__pycache__
test1/__pycache__/file1-py
test1/include
test1/include/file1-incl
test2
test2/__pycache__
test2/__pycache__/file2-py
test2/include
test2/include/file2-incl
test2/file2
host: # tar --exclude='__pycache__' -cv test* -f testtar.tar
test1/
test1/file1
test1/include/
test1/include/file1-incl
test2/
test2/include/
test2/include/file2-incl
test2/file2
You need to add the --exclude
switch at the beginning of the command, see this. This solution works on my openSUSE machine, I don't have other distros available right now.
host:/tmp # find test*
test1
test1/file1
test1/__pycache__
test1/__pycache__/file1-py
test1/include
test1/include/file1-incl
test2
test2/__pycache__
test2/__pycache__/file2-py
test2/include
test2/include/file2-incl
test2/file2
host: # tar --exclude='__pycache__' -cv test* -f testtar.tar
test1/
test1/file1
test1/include/
test1/include/file1-incl
test2/
test2/include/
test2/include/file2-incl
test2/file2
answered 15 hours ago
eblockeblock
1667
1667
This works on both Ubuntu and Centos, odd that the centos version accepts the--exclude
at the end of the line
– ptr
15 hours ago
add a comment |
This works on both Ubuntu and Centos, odd that the centos version accepts the--exclude
at the end of the line
– ptr
15 hours ago
This works on both Ubuntu and Centos, odd that the centos version accepts the
--exclude
at the end of the line– ptr
15 hours ago
This works on both Ubuntu and Centos, odd that the centos version accepts the
--exclude
at the end of the line– ptr
15 hours ago
add a comment |
ptr is a new contributor. Be nice, and check out our Code of Conduct.
ptr is a new contributor. Be nice, and check out our Code of Conduct.
ptr is a new contributor. Be nice, and check out our Code of Conduct.
ptr is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f507179%2frecursively-exclude-directory-with-pattern-using-tar%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I can't seem to reproduce this with a basic directory tree. Can you show us the directory structure you have on your system?
– Haxiel
16 hours ago
added an example
– ptr
15 hours ago
for reference, I'm currently on ubuntu 18.04 but this is also happening on centos7
– ptr
15 hours ago
Thanks for the update, but I still can't reproduce this. I'm on an RHEL 7 system with GNU
tar
1.26 (which would be identical to your CentOS system). Copy-pasting the exact same command from your question works for me.– Haxiel
15 hours ago
my apologies, it does work on centos, i must have used a different flag the time it didn't work. So is it a difference between ubuntu and centos' tar versions?
– ptr
15 hours ago