In comp.os.linux.advocacy, Bill Turner
<
[email protected]>
wrote
The said:
[3] If one doesn't have file extensions, with Windows one is kinda
stuck. However, in Linux, one can do things like
$ find . -type f -mtime +7 | xargs file | \
grep '^.*: PNG image data, ' | \
awk -F: '{print $1;}' | cpio -oc > archive.cpio
which will take any file older than 7 days, open it, check
to see if it looks like a PNG file, and, if it is, take
it and throw it into a CPIO archive.
The naive user will probably think this is gobbledygook but it's
actually fairly simple, and can be tested easily by
omitting the tail end of the pipeline. Admittedly, tarballs
are more common, and tar's a little harder to feed.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If you think that is "actually fairly simple", I give up. We come from
different planets.
Mr Bill
You do have a point. Of course, it's fairly simple *to me*.
But, here's a few thoughts *for you*.
[1] The command, of course, is a pipeline. With a pipeline,
the output of one subcommand is fed to another, making
for rather handy if crude debugging. For example, the
above pipeline can be deconstructed and debugged using
something like the following.
$ find . -type f -mtime +7
to ensure the initial filelist is right. If one
sees strange messages such as "file not found",
one can interject the -print0 option after some
manpage searching. (The corresponding xargs option is
'xargs -0'.)
Command history can then be used, to reenter the
command after editing it a bit:
$ find . -type f -mtime +7 | xargs file
Now one sees the output of the second stage of the pipeline.
It's not quite right, of course, which is where the
grep comes in:
$ find . -type f -mtime +7 | xargs file | \
grep '^.*: PNG image data, '
and then I don't need all of the goo following the colon,
so there are various ways; one can use awk or sed here.
$ find . -type f -mtime +7 | xargs file | \
grep '^.*: PNG image data, ' | \
awk -F: '{print $1;}'
and now one has a list of files again -- and this list,
furthermore, is blessed by the file command and in more or
less the proper format.
(There are still issues with spaces therein, admittedly.)
[2] The 'tee' command is occasionally useful if one wants to
get at the intermediates of a pipeline. This command
is generally used e.g.
$ find . -type f -mtime +7 | xargs file | tee rawfilelist \
grep '^.*: PNG image data, ' | \
awk -F: '{print $1;}'
and tee simply spits out what it sees on standard input
into the file, as well as onto standard output.
[3] Shell plumbing can get interesting, especially with
f, m>&n, >>f, and m>>&n, where m and n are number (usually,
one merges errout and stdout: prog 2>&1 | otherprog).
At some point I'm hoping that Nautilus or Konqueror will allow
for the specification of criteria such as what one would find on the
'find' command, and present a list of the results, ready for
selection. Dragging and dropping the list would then do what
is necessary.
However, that's still more cumbersome than a simple pipeline.