[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
> I'm trying to avoid duplicate filenames during my renaming sessions.  

If it's bash:

  for f in /path/to/*.{JPG,jpg}; do mv "$f" `date +%N`.jpg; done

Otherwise you have to resort to:

  for f in /path/to/*.JPG /path/to/*.jpg; do mv "$f" `date +%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).

'>&1' is nonsensical, so I guess you mean:

  ls 2>/dev/null >&2

... or the equivalent but more usual:

  ls >/dev/null 2>&1

'>/dev/null' redirects standard output (file descriptor 1) to /dev/null,
and standard error (fd 2) to what standard output is after the first
redirection, in other words /dev/null again. The effect of this is to
bin all output from ls.

Or you might mean this instead:

  ls 2>&1 >/dev/null

This redirects standard error from ls to the current standard output
(say, your terminal) and standard output from ls to /dev/null. The
effect of this is to discard the normal output and treat any error
output as if it had come out as normal output, for example so that you
can pipe it into a pager.

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

The man pages are pretty good: look at the REDIRECTION section in

Colin Watson                                  [cjwatson@flatline.org.uk]

Reply to: