Why does tar appear to skip file contents when output file is /dev/null?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
I have a directory with over 400 GiB of data in it. I wanted to check that all the files can be read without errors, so a simple way I thought of was to tar
it into /dev/null
. But instead I see the following behavior:
$ time tar cf /dev/null .
real 0m4.387s
user 0m3.462s
sys 0m0.185s
$ time tar cf - . > /dev/null
real 0m3.130s
user 0m3.091s
sys 0m0.035s
$ time tar cf - . | cat > /dev/null
^C
real 10m32.985s
user 0m1.942s
sys 0m33.764s
The third command above was forcibly stopped by Ctrl+C after having run for quite long already. Moreover, while the first two commands were working, activity indicator of the storage device containing .
was nearly always idle. With the third command the indicator is constantly lit up, meaning extreme busyness.
So it seems that, when tar
is able to find out that its output file is /dev/null
, i.e. when /dev/null
is directly opened to have the file handle which tar
writes to, file body appears skipped. (Adding v
option to tar
does print all the files in the directory being tar
'red.)
So I wonder, why is this so? Is it some kind of optimization? If yes, then why would tar
even want to do such a dubious optimization for such a special case?
I'm using GNU tar 1.26 with glibc 2.27 on Linux 4.14.105 amd64.
tar null
add a comment |
I have a directory with over 400 GiB of data in it. I wanted to check that all the files can be read without errors, so a simple way I thought of was to tar
it into /dev/null
. But instead I see the following behavior:
$ time tar cf /dev/null .
real 0m4.387s
user 0m3.462s
sys 0m0.185s
$ time tar cf - . > /dev/null
real 0m3.130s
user 0m3.091s
sys 0m0.035s
$ time tar cf - . | cat > /dev/null
^C
real 10m32.985s
user 0m1.942s
sys 0m33.764s
The third command above was forcibly stopped by Ctrl+C after having run for quite long already. Moreover, while the first two commands were working, activity indicator of the storage device containing .
was nearly always idle. With the third command the indicator is constantly lit up, meaning extreme busyness.
So it seems that, when tar
is able to find out that its output file is /dev/null
, i.e. when /dev/null
is directly opened to have the file handle which tar
writes to, file body appears skipped. (Adding v
option to tar
does print all the files in the directory being tar
'red.)
So I wonder, why is this so? Is it some kind of optimization? If yes, then why would tar
even want to do such a dubious optimization for such a special case?
I'm using GNU tar 1.26 with glibc 2.27 on Linux 4.14.105 amd64.
tar null
add a comment |
I have a directory with over 400 GiB of data in it. I wanted to check that all the files can be read without errors, so a simple way I thought of was to tar
it into /dev/null
. But instead I see the following behavior:
$ time tar cf /dev/null .
real 0m4.387s
user 0m3.462s
sys 0m0.185s
$ time tar cf - . > /dev/null
real 0m3.130s
user 0m3.091s
sys 0m0.035s
$ time tar cf - . | cat > /dev/null
^C
real 10m32.985s
user 0m1.942s
sys 0m33.764s
The third command above was forcibly stopped by Ctrl+C after having run for quite long already. Moreover, while the first two commands were working, activity indicator of the storage device containing .
was nearly always idle. With the third command the indicator is constantly lit up, meaning extreme busyness.
So it seems that, when tar
is able to find out that its output file is /dev/null
, i.e. when /dev/null
is directly opened to have the file handle which tar
writes to, file body appears skipped. (Adding v
option to tar
does print all the files in the directory being tar
'red.)
So I wonder, why is this so? Is it some kind of optimization? If yes, then why would tar
even want to do such a dubious optimization for such a special case?
I'm using GNU tar 1.26 with glibc 2.27 on Linux 4.14.105 amd64.
tar null
I have a directory with over 400 GiB of data in it. I wanted to check that all the files can be read without errors, so a simple way I thought of was to tar
it into /dev/null
. But instead I see the following behavior:
$ time tar cf /dev/null .
real 0m4.387s
user 0m3.462s
sys 0m0.185s
$ time tar cf - . > /dev/null
real 0m3.130s
user 0m3.091s
sys 0m0.035s
$ time tar cf - . | cat > /dev/null
^C
real 10m32.985s
user 0m1.942s
sys 0m33.764s
The third command above was forcibly stopped by Ctrl+C after having run for quite long already. Moreover, while the first two commands were working, activity indicator of the storage device containing .
was nearly always idle. With the third command the indicator is constantly lit up, meaning extreme busyness.
So it seems that, when tar
is able to find out that its output file is /dev/null
, i.e. when /dev/null
is directly opened to have the file handle which tar
writes to, file body appears skipped. (Adding v
option to tar
does print all the files in the directory being tar
'red.)
So I wonder, why is this so? Is it some kind of optimization? If yes, then why would tar
even want to do such a dubious optimization for such a special case?
I'm using GNU tar 1.26 with glibc 2.27 on Linux 4.14.105 amd64.
tar null
tar null
asked 32 mins ago
RuslanRuslan
1,3961427
1,3961427
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
It is a documented optimization:
When the archive is being created to
/dev/null
, GNU tar tries to
minimize input and output operations. The Amanda backup system, when
used with GNU tar, has an initial sizing pass which uses this feature.
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%2f512362%2fwhy-does-tar-appear-to-skip-file-contents-when-output-file-is-dev-null%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
It is a documented optimization:
When the archive is being created to
/dev/null
, GNU tar tries to
minimize input and output operations. The Amanda backup system, when
used with GNU tar, has an initial sizing pass which uses this feature.
add a comment |
It is a documented optimization:
When the archive is being created to
/dev/null
, GNU tar tries to
minimize input and output operations. The Amanda backup system, when
used with GNU tar, has an initial sizing pass which uses this feature.
add a comment |
It is a documented optimization:
When the archive is being created to
/dev/null
, GNU tar tries to
minimize input and output operations. The Amanda backup system, when
used with GNU tar, has an initial sizing pass which uses this feature.
It is a documented optimization:
When the archive is being created to
/dev/null
, GNU tar tries to
minimize input and output operations. The Amanda backup system, when
used with GNU tar, has an initial sizing pass which uses this feature.
answered 14 mins ago
murumuru
37.7k589165
37.7k589165
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%2f512362%2fwhy-does-tar-appear-to-skip-file-contents-when-output-file-is-dev-null%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