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










0















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__/









share|improve this question









New contributor




ptr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • 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















0















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__/









share|improve this question









New contributor




ptr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • 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













0












0








0








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__/









share|improve this question









New contributor




ptr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












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






share|improve this question









New contributor




ptr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




ptr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 15 hours ago









Jeff Schaller

43.5k1161140




43.5k1161140






New contributor




ptr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 16 hours ago









ptrptr

1033




1033




New contributor




ptr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





ptr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






ptr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • 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

















  • 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
















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










1 Answer
1






active

oldest

votes


















2














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





share|improve this answer























  • 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










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.









draft saved

draft discarded


















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









2














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





share|improve this answer























  • 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















2














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





share|improve this answer























  • 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













2












2








2







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





share|improve this answer













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






share|improve this answer












share|improve this answer



share|improve this answer










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

















  • 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










ptr is a new contributor. Be nice, and check out our Code of Conduct.









draft saved

draft discarded


















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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

getting Checkpoint VPN SSL Network Extender working in the command lineHow to connect to CheckPoint VPN on Ubuntu 18.04LTS?Will the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayVPN SSL Network Extender in FirefoxLinux Checkpoint SNX tool configuration issuesCheck Point - Connect under Linux - snx + OTPSNX VPN Ububuntu 18.XXUsing Checkpoint VPN SSL Network Extender CLI with certificateVPN with network manager (nm-applet) is not workingWill the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayImport VPN config files to NetworkManager from command lineTrouble connecting to VPN using network-manager, while command line worksStart a VPN connection with PPTP protocol on command linestarting a docker service daemon breaks the vpn networkCan't connect to vpn with Network-managerVPN SSL Network Extender in FirefoxUsing Checkpoint VPN SSL Network Extender CLI with certificate

Cannot Extend partition with GParted The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election ResultsCan't increase partition size with GParted?GParted doesn't recognize the unallocated space after my current partitionWhat is the best way to add unallocated space located before to Ubuntu 12.04 partition with GParted live?I can't figure out how to extend my Arch home partition into free spaceGparted Linux Mint 18.1 issueTrying to extend but swap partition is showing as Unknown in Gparted, shows proper from fdiskRearrange partitions in gparted to extend a partitionUnable to extend partition even though unallocated space is next to it using GPartedAllocate free space to root partitiongparted: how to merge unallocated space with a partition

Marilyn Monroe Ny fiainany manokana | Jereo koa | Meny fitetezanafanitarana azy.