LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-01-2022, 01:48 PM   #1
eaberry
LQ Newbie
 
Registered: Jan 2007
Posts: 8

Rep: Reputation: 1
Question does tar cheat when no one is looking (at its output)?


Having burned a dvd (with ext2 filesystem) and wanting some way to check its integrity, I thought tar might be a good option. If I tar the entire disk, tar will have to read every file which will result in errors if there are any. Since I don't care about the output, tar to stdout and redirect that to /dev/null so I can watch stderr:

# tar -c /mnt/cdrom > /dev/null
tar: Removing leading `/' from member names
(finishes immediately, no error)
#
No way it could read the whole disk, much less tar all the files, in a jiffy!
Try this:

# tar -c /mnt/cdrom |tar -tv
tar: Removing leading `/' from member names
(runs for 20 minutes, with several error messages)
tar: Exiting with failure status due to previous errors
#
So it seems like tar looks at the pipe. he knows /dev/null doesn't care what you send him, and skips a lot of work. But if the output is going somewhere real, then he does his job.
Does anyone have a more rational explanation (and what is it)?
# tar --version
tar (GNU tar) 1.26

(But I seem to remember this behavior from around 2000 and before, old red-hat 7.3)

# fsck -n /dev/sr0
fsck from util-linux 2.23.2
e2fsck 1.42.9 (28-Dec-2013)
/dev/sr0 was not cleanly unmounted, check forced.
Pass 1: Checking inodes, blocks, and sizes
Inode 153 has illegal block(s). Clear? no
Illegal indirect block (3948281850) in inode 153. IGNORED.
Error while iterating over blocks in inode 153: Illegal indirect block found
/dev/sr0: ********** WARNING: Filesystem still has errors **********
e2fsck: aborted
 
Old 02-01-2022, 02:31 PM   #2
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,599

Rep: Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546
Quote:
Originally Posted by https://www.gnu.org/software/tar/manual/tar.html
When the archive is being created to ‘/dev/null’, GNU tar tries to minimize input and output operations.
...
 
1 members found this post helpful.
Old 02-01-2022, 06:04 PM   #3
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
Not only tar. Not so long ago, DistroWatch Weekly ran an article in their Tips and Tricks column describing how to find the right words with grep. You know, sort of the task danielbmartin sometimes posts here.

So, I set out to compare how different grep-like (and not-so-like) tools fare against each other doing this task.

First, I tried something like
Code:
time sh -c "grep -P '(?=.*a)(?=.*e)(?=.*i)(?=.*o).*u' /usr/share/dict/words>/dev/null"
But quickly noticed that some tools did it suspiciously fast, and so I ended up piping the output to wc to get reasonable results.
Code:
time sh -c "grep -P '(?=.*a)(?=.*e)(?=.*i)(?=.*o).*u' /usr/share/dict/words|wc -l"
I guess those grep-like tools stop the search after the first successful match when redirected to /dev/null.

I uploaded the full script here if anybody is interested.
 
1 members found this post helpful.
  


Reply

Tags
null, pipe, tar



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Excellent Utilities: cheat.sh - community driven cheat sheet LXer Syndicated Linux News 0 10-21-2019 02:01 PM
LXer: Cheat.sh Shows Cheat Sheets On The Command Line Or In Your Code Editor LXer Syndicated Linux News 0 07-15-2019 08:24 PM
BackUp & Restore with TAR (.tar / .tar.gz / .tar.bz2 / tar.Z) asgarcymed Linux - General 5 12-31-2006 02:53 AM
LXer: Cheat Knoppix 4 to Improve Performance: Part 1. Cheat Code Basics and the ALSA Cheat Code LXer Syndicated Linux News 0 01-10-2006 07:16 AM
How do I un tar a .tar, .tar.z, .tar.gz file vofkid Linux - Newbie 4 03-15-2002 02:54 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration