Compress and remove original directory with limited storage
On my 3 TB external hard drive, I have a 2.7 TB directory containing relatively small files. I would like to compress this 2.7 TB directory and remove it to keep only the compressed version. The issue is that I do not have enough storage to first zip and then rm the non-zipped directory.
Is there a way around this problem or do I necessarily have to acquire more storage for the manipulation?
rm zip compression storage
add a comment |
On my 3 TB external hard drive, I have a 2.7 TB directory containing relatively small files. I would like to compress this 2.7 TB directory and remove it to keep only the compressed version. The issue is that I do not have enough storage to first zip and then rm the non-zipped directory.
Is there a way around this problem or do I necessarily have to acquire more storage for the manipulation?
rm zip compression storage
That may help: superuser.com/questions/656111/…
– alpert
Apr 25 '16 at 21:18
Your title is misleading. Why do you want to compress if you want to remove it anyway? Or do you want to move+compress it to another drive?
– ott--
Apr 25 '16 at 21:26
@ott Given directoryd, I would like to compress it intod.zipand thenrm -r dbut I don't have enough storage for that. Does it make sense? Sorry if the title is misleading. I welcome suggestions to improve it. Thanks
– Remi.b
Apr 25 '16 at 21:35
add a comment |
On my 3 TB external hard drive, I have a 2.7 TB directory containing relatively small files. I would like to compress this 2.7 TB directory and remove it to keep only the compressed version. The issue is that I do not have enough storage to first zip and then rm the non-zipped directory.
Is there a way around this problem or do I necessarily have to acquire more storage for the manipulation?
rm zip compression storage
On my 3 TB external hard drive, I have a 2.7 TB directory containing relatively small files. I would like to compress this 2.7 TB directory and remove it to keep only the compressed version. The issue is that I do not have enough storage to first zip and then rm the non-zipped directory.
Is there a way around this problem or do I necessarily have to acquire more storage for the manipulation?
rm zip compression storage
rm zip compression storage
edited Sep 2 '17 at 1:39
Jeff Schaller
41.5k1056132
41.5k1056132
asked Apr 25 '16 at 21:09
Remi.bRemi.b
3351515
3351515
That may help: superuser.com/questions/656111/…
– alpert
Apr 25 '16 at 21:18
Your title is misleading. Why do you want to compress if you want to remove it anyway? Or do you want to move+compress it to another drive?
– ott--
Apr 25 '16 at 21:26
@ott Given directoryd, I would like to compress it intod.zipand thenrm -r dbut I don't have enough storage for that. Does it make sense? Sorry if the title is misleading. I welcome suggestions to improve it. Thanks
– Remi.b
Apr 25 '16 at 21:35
add a comment |
That may help: superuser.com/questions/656111/…
– alpert
Apr 25 '16 at 21:18
Your title is misleading. Why do you want to compress if you want to remove it anyway? Or do you want to move+compress it to another drive?
– ott--
Apr 25 '16 at 21:26
@ott Given directoryd, I would like to compress it intod.zipand thenrm -r dbut I don't have enough storage for that. Does it make sense? Sorry if the title is misleading. I welcome suggestions to improve it. Thanks
– Remi.b
Apr 25 '16 at 21:35
That may help: superuser.com/questions/656111/…
– alpert
Apr 25 '16 at 21:18
That may help: superuser.com/questions/656111/…
– alpert
Apr 25 '16 at 21:18
Your title is misleading. Why do you want to compress if you want to remove it anyway? Or do you want to move+compress it to another drive?
– ott--
Apr 25 '16 at 21:26
Your title is misleading. Why do you want to compress if you want to remove it anyway? Or do you want to move+compress it to another drive?
– ott--
Apr 25 '16 at 21:26
@ott Given directory
d, I would like to compress it into d.zip and then rm -r d but I don't have enough storage for that. Does it make sense? Sorry if the title is misleading. I welcome suggestions to improve it. Thanks– Remi.b
Apr 25 '16 at 21:35
@ott Given directory
d, I would like to compress it into d.zip and then rm -r d but I don't have enough storage for that. Does it make sense? Sorry if the title is misleading. I welcome suggestions to improve it. Thanks– Remi.b
Apr 25 '16 at 21:35
add a comment |
4 Answers
4
active
oldest
votes
You can try the --remove-files argument to tar. Say you want to compress everything on directory FOO, you would:
tar -czf FooCompressed.tar.gz --remove-files FOO
Arguments explained:
- c: create TAR
- z: compress using GZIP, you can switch to
-jfor BZIP2 or-Jfor LZMA(xz) - f: output to file instead of of STDOUT
- remove-files: self explanatory
** I said try because I don't know if the released space will be available on the fly.
– Dalvenjia
Apr 25 '16 at 23:59
add a comment |
If the largest file in the directory is less than 300GB (the amount of free space), the easiest option is to compress files individually rather than creating an archive; something like
find directory -type f ! -name '*.xz' -print 0 | xargs -0 xz -9
will compress all non-compressed files in directory using xz at compression level 9. This will replaces files one at a time with the corresponding compressed version, adding a .xz extension (so foo.txt becomes foo.txt.xz).
In fact this can work even if the largest file is larger than the available free space, as long as you have enough files smaller than the available free space: start by compressing the smaller files, which will progressively free more and more space up, until (hopefully) you have enough free space to handle the largest file.
add a comment |
I normally never make zip files, so I'm no expert, but it looks like zip by default just adds files to an archive, so something like (untested - contains an rm command = potentially dangerous - Test yourself before risking your data):
for f in $(ls --sort=size --reverse); do zip -9 archive.zip $f; rm $f; done
in the directory, could probably do it.
One safety valve I'd add would be to changezip...; rm...to `zip... && rm
– Jeff Schaller
Apr 25 '16 at 23:17
3
@JeffSchaller - and never dofor f in $(ls whatever)...
– don_crissti
Apr 25 '16 at 23:19
2
@Henrik If I remember correctly, when adding files to an existing archive,zipcreates a new archive alongside the old one — so when space is short this doesn't work.
– Stephen Kitt
Apr 26 '16 at 18:07
add a comment |
- c: create TAR
- z: compress using GZIP, you can switch to -j for BZIP2 or -J for LZMA(xz)
- f: output to file instead of of STDOUT
- remove-files: self explanatory
something happens on stage 1-3 and you lose all your original files on step 4
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
});
}
});
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%2f279011%2fcompress-and-remove-original-directory-with-limited-storage%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can try the --remove-files argument to tar. Say you want to compress everything on directory FOO, you would:
tar -czf FooCompressed.tar.gz --remove-files FOO
Arguments explained:
- c: create TAR
- z: compress using GZIP, you can switch to
-jfor BZIP2 or-Jfor LZMA(xz) - f: output to file instead of of STDOUT
- remove-files: self explanatory
** I said try because I don't know if the released space will be available on the fly.
– Dalvenjia
Apr 25 '16 at 23:59
add a comment |
You can try the --remove-files argument to tar. Say you want to compress everything on directory FOO, you would:
tar -czf FooCompressed.tar.gz --remove-files FOO
Arguments explained:
- c: create TAR
- z: compress using GZIP, you can switch to
-jfor BZIP2 or-Jfor LZMA(xz) - f: output to file instead of of STDOUT
- remove-files: self explanatory
** I said try because I don't know if the released space will be available on the fly.
– Dalvenjia
Apr 25 '16 at 23:59
add a comment |
You can try the --remove-files argument to tar. Say you want to compress everything on directory FOO, you would:
tar -czf FooCompressed.tar.gz --remove-files FOO
Arguments explained:
- c: create TAR
- z: compress using GZIP, you can switch to
-jfor BZIP2 or-Jfor LZMA(xz) - f: output to file instead of of STDOUT
- remove-files: self explanatory
You can try the --remove-files argument to tar. Say you want to compress everything on directory FOO, you would:
tar -czf FooCompressed.tar.gz --remove-files FOO
Arguments explained:
- c: create TAR
- z: compress using GZIP, you can switch to
-jfor BZIP2 or-Jfor LZMA(xz) - f: output to file instead of of STDOUT
- remove-files: self explanatory
answered Apr 25 '16 at 23:58
DalvenjiaDalvenjia
1,20648
1,20648
** I said try because I don't know if the released space will be available on the fly.
– Dalvenjia
Apr 25 '16 at 23:59
add a comment |
** I said try because I don't know if the released space will be available on the fly.
– Dalvenjia
Apr 25 '16 at 23:59
** I said try because I don't know if the released space will be available on the fly.
– Dalvenjia
Apr 25 '16 at 23:59
** I said try because I don't know if the released space will be available on the fly.
– Dalvenjia
Apr 25 '16 at 23:59
add a comment |
If the largest file in the directory is less than 300GB (the amount of free space), the easiest option is to compress files individually rather than creating an archive; something like
find directory -type f ! -name '*.xz' -print 0 | xargs -0 xz -9
will compress all non-compressed files in directory using xz at compression level 9. This will replaces files one at a time with the corresponding compressed version, adding a .xz extension (so foo.txt becomes foo.txt.xz).
In fact this can work even if the largest file is larger than the available free space, as long as you have enough files smaller than the available free space: start by compressing the smaller files, which will progressively free more and more space up, until (hopefully) you have enough free space to handle the largest file.
add a comment |
If the largest file in the directory is less than 300GB (the amount of free space), the easiest option is to compress files individually rather than creating an archive; something like
find directory -type f ! -name '*.xz' -print 0 | xargs -0 xz -9
will compress all non-compressed files in directory using xz at compression level 9. This will replaces files one at a time with the corresponding compressed version, adding a .xz extension (so foo.txt becomes foo.txt.xz).
In fact this can work even if the largest file is larger than the available free space, as long as you have enough files smaller than the available free space: start by compressing the smaller files, which will progressively free more and more space up, until (hopefully) you have enough free space to handle the largest file.
add a comment |
If the largest file in the directory is less than 300GB (the amount of free space), the easiest option is to compress files individually rather than creating an archive; something like
find directory -type f ! -name '*.xz' -print 0 | xargs -0 xz -9
will compress all non-compressed files in directory using xz at compression level 9. This will replaces files one at a time with the corresponding compressed version, adding a .xz extension (so foo.txt becomes foo.txt.xz).
In fact this can work even if the largest file is larger than the available free space, as long as you have enough files smaller than the available free space: start by compressing the smaller files, which will progressively free more and more space up, until (hopefully) you have enough free space to handle the largest file.
If the largest file in the directory is less than 300GB (the amount of free space), the easiest option is to compress files individually rather than creating an archive; something like
find directory -type f ! -name '*.xz' -print 0 | xargs -0 xz -9
will compress all non-compressed files in directory using xz at compression level 9. This will replaces files one at a time with the corresponding compressed version, adding a .xz extension (so foo.txt becomes foo.txt.xz).
In fact this can work even if the largest file is larger than the available free space, as long as you have enough files smaller than the available free space: start by compressing the smaller files, which will progressively free more and more space up, until (hopefully) you have enough free space to handle the largest file.
edited Feb 8 '18 at 12:33
answered Apr 25 '16 at 21:17
Stephen KittStephen Kitt
172k24386465
172k24386465
add a comment |
add a comment |
I normally never make zip files, so I'm no expert, but it looks like zip by default just adds files to an archive, so something like (untested - contains an rm command = potentially dangerous - Test yourself before risking your data):
for f in $(ls --sort=size --reverse); do zip -9 archive.zip $f; rm $f; done
in the directory, could probably do it.
One safety valve I'd add would be to changezip...; rm...to `zip... && rm
– Jeff Schaller
Apr 25 '16 at 23:17
3
@JeffSchaller - and never dofor f in $(ls whatever)...
– don_crissti
Apr 25 '16 at 23:19
2
@Henrik If I remember correctly, when adding files to an existing archive,zipcreates a new archive alongside the old one — so when space is short this doesn't work.
– Stephen Kitt
Apr 26 '16 at 18:07
add a comment |
I normally never make zip files, so I'm no expert, but it looks like zip by default just adds files to an archive, so something like (untested - contains an rm command = potentially dangerous - Test yourself before risking your data):
for f in $(ls --sort=size --reverse); do zip -9 archive.zip $f; rm $f; done
in the directory, could probably do it.
One safety valve I'd add would be to changezip...; rm...to `zip... && rm
– Jeff Schaller
Apr 25 '16 at 23:17
3
@JeffSchaller - and never dofor f in $(ls whatever)...
– don_crissti
Apr 25 '16 at 23:19
2
@Henrik If I remember correctly, when adding files to an existing archive,zipcreates a new archive alongside the old one — so when space is short this doesn't work.
– Stephen Kitt
Apr 26 '16 at 18:07
add a comment |
I normally never make zip files, so I'm no expert, but it looks like zip by default just adds files to an archive, so something like (untested - contains an rm command = potentially dangerous - Test yourself before risking your data):
for f in $(ls --sort=size --reverse); do zip -9 archive.zip $f; rm $f; done
in the directory, could probably do it.
I normally never make zip files, so I'm no expert, but it looks like zip by default just adds files to an archive, so something like (untested - contains an rm command = potentially dangerous - Test yourself before risking your data):
for f in $(ls --sort=size --reverse); do zip -9 archive.zip $f; rm $f; done
in the directory, could probably do it.
answered Apr 25 '16 at 22:49
HenrikHenrik
3,6511419
3,6511419
One safety valve I'd add would be to changezip...; rm...to `zip... && rm
– Jeff Schaller
Apr 25 '16 at 23:17
3
@JeffSchaller - and never dofor f in $(ls whatever)...
– don_crissti
Apr 25 '16 at 23:19
2
@Henrik If I remember correctly, when adding files to an existing archive,zipcreates a new archive alongside the old one — so when space is short this doesn't work.
– Stephen Kitt
Apr 26 '16 at 18:07
add a comment |
One safety valve I'd add would be to changezip...; rm...to `zip... && rm
– Jeff Schaller
Apr 25 '16 at 23:17
3
@JeffSchaller - and never dofor f in $(ls whatever)...
– don_crissti
Apr 25 '16 at 23:19
2
@Henrik If I remember correctly, when adding files to an existing archive,zipcreates a new archive alongside the old one — so when space is short this doesn't work.
– Stephen Kitt
Apr 26 '16 at 18:07
One safety valve I'd add would be to change
zip...; rm... to `zip... && rm– Jeff Schaller
Apr 25 '16 at 23:17
One safety valve I'd add would be to change
zip...; rm... to `zip... && rm– Jeff Schaller
Apr 25 '16 at 23:17
3
3
@JeffSchaller - and never do
for f in $(ls whatever) ...– don_crissti
Apr 25 '16 at 23:19
@JeffSchaller - and never do
for f in $(ls whatever) ...– don_crissti
Apr 25 '16 at 23:19
2
2
@Henrik If I remember correctly, when adding files to an existing archive,
zip creates a new archive alongside the old one — so when space is short this doesn't work.– Stephen Kitt
Apr 26 '16 at 18:07
@Henrik If I remember correctly, when adding files to an existing archive,
zip creates a new archive alongside the old one — so when space is short this doesn't work.– Stephen Kitt
Apr 26 '16 at 18:07
add a comment |
- c: create TAR
- z: compress using GZIP, you can switch to -j for BZIP2 or -J for LZMA(xz)
- f: output to file instead of of STDOUT
- remove-files: self explanatory
something happens on stage 1-3 and you lose all your original files on step 4
add a comment |
- c: create TAR
- z: compress using GZIP, you can switch to -j for BZIP2 or -J for LZMA(xz)
- f: output to file instead of of STDOUT
- remove-files: self explanatory
something happens on stage 1-3 and you lose all your original files on step 4
add a comment |
- c: create TAR
- z: compress using GZIP, you can switch to -j for BZIP2 or -J for LZMA(xz)
- f: output to file instead of of STDOUT
- remove-files: self explanatory
something happens on stage 1-3 and you lose all your original files on step 4
- c: create TAR
- z: compress using GZIP, you can switch to -j for BZIP2 or -J for LZMA(xz)
- f: output to file instead of of STDOUT
- remove-files: self explanatory
something happens on stage 1-3 and you lose all your original files on step 4
edited Feb 6 at 1:35
Jeff Schaller
41.5k1056132
41.5k1056132
answered Feb 6 at 0:56
DmitryDmitry
1
1
add a comment |
add a comment |
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%2f279011%2fcompress-and-remove-original-directory-with-limited-storage%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
That may help: superuser.com/questions/656111/…
– alpert
Apr 25 '16 at 21:18
Your title is misleading. Why do you want to compress if you want to remove it anyway? Or do you want to move+compress it to another drive?
– ott--
Apr 25 '16 at 21:26
@ott Given directory
d, I would like to compress it intod.zipand thenrm -r dbut I don't have enough storage for that. Does it make sense? Sorry if the title is misleading. I welcome suggestions to improve it. Thanks– Remi.b
Apr 25 '16 at 21:35