Script help

Cameron Simpson cs at zip.com.au
Sat Sep 20 00:36:13 UTC 2008


On 19Sep2008 15:51, NiftyFedora Mitch <niftyfedora at niftyegg.com> wrote:
| On Fri, Sep 19, 2008 at 3:43 PM, Cameron Simpson <cs at zip.com.au> wrote:
| > On 19Sep2008 14:08, Dennis Kaptain <dkaptain at yahoo.com.mx> wrote:
| > | > > Can anyone rattle this off of the top of their head?
| > | > `ls -t myfile*.txt | head -1` might work for you.
[...]
| And if the question was to tinker with a set of files
| that was generated with a script like this?:

| #!/bin/bash
|  cd /tmp
|  mkdir tinker/ tinker/foo/ tinker/foo/bar/ tinker/foo/bletch/
|  for I in tinker/ tinker/foo/ tinker/foo/bar/ tinker/foo/bletch/
|  do
|  touch $I/myfile387465893495643658734.txt
|  touch $I/myfile387465893495643658734.txt
|  touch $I/myfile547647453645635632454.txt
|  touch $I/myfile563546356243546767546.txt
|  touch $I/myfile465565634678567345656.txt
|  touch $I/myfile456674567452345566345.txt
|  touch $I/myfile563546356243546767546.txt
|  done

What's your point here? That the files are in many directories? That
the timestamps may not be far enough apart to discern? That there may
be too many files to fit on a single command line? That the script calls
for bash unnecessarily; the more portable sh is just fine? That "touch"
is a Very Slow way to make files?  That... ???

Something like the find incantation of another post is the easy way:

  find . -type f -name 'myfile\*.txt' | ls -t | sed 1q

That will require significant modification if the file line blows the
command line argument length limit (no, xargs is _not_ your friend for
this particular tasks - exercise for the reader to figure out why).

Cheers,
-- 
Cameron Simpson <cs at zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/

I very strongly suggest that you periodically place ice packs over the abused
areas.  - Steve Garnier




More information about the fedora-list mailing list