[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: quick shell questions



On Tue, Dec 10, 2002 at 01:00:51PM -0500, Drew Cohan wrote:
> 1.  How do I combine these two (JPG vs jpg):
> 
> for f in /path/to/*.JPG; do mv "$f" `date +%N`.jpg; done
> for f in /path/to/*.jpg; do mv "$f" `date +%N`.jpg; done

that's really simple:

  for f in /path/to/*.[jJ][pP][gG]; do mv "$f" $(date +%N).jpg; done

But, what's the %N format supposed to do? Can't find it in the docs.
Maybe you ment the -uTsec flag instead?  Anyhow, it seems that this
snipped will leave you with a very few files. as most get the same
name:]

> I'm trying to avoid duplicate filenames during my renaming sessions.  

Ah, demanding are we, he:) One way to keep the names uniq is to number
them, this will complicate the script beyond what I like for shell
scripting, so why not switch to the best you can get for (interactive)
scripting and go for Python instead?  But if you insist:

  n=1
  for f in /path/to/*.[jJ][pP][gG]; do
      mv "$f" $(date -uTsec)+$((n++)).jpg
  done


> 2.  What does the "2>/dev/null>&1" mean that I see in a lot of examples
> (eg ls 2>/dev/null/>&1).

I doubt you'll ever find that one, it looks like a contraction of:

  2>/dev/null      this redirects stderr to the bottomless bitbucket.

and

  2>&1             this redirects stderr to stdout, so it merges the two


> I really should take a shell scripting class.  :)

Nah, better go for Python (or Perl if you're into SM:)

-- 
groetjes, carel



Reply to: