[conspire] (forw) Re: UNIX beginner asks: what's a good forum for q's about command-line utilities?
rick at linuxmafia.com
Thu Sep 2 16:24:47 PDT 2010
----- Forwarded message from Michael Gray <michaelcgray at gmail.com> -----
Date: Wed, 1 Sep 2010 12:11:58 -0700
From: Michael Gray <michaelcgray at gmail.com>
To: rick at linuxmafia.com
Subject: UNIX beginner asks: what's a good forum for q's about command-line
X-Spam-Status: No, score=0.7 required=4.0 tests=BAYES_50,DKIM_SIGNED,
We met at your house some time last year at one of your installfests. I
don't know whether you remember me; I brought in a circa-1995 desktop system
with a non-standard processor (a copy of a copy, you said), and you
recommended I get a netbook. I did. A man named Christian helped me with the
installation; I have forgotten his last name. He was from northern Europe
somewhere. I now have a netbook running Ubuntu. I have read, and hopefully
internalized, the essay you co-wrote with Eric Raymond entitled "How to ask
good questions" or something quite similar. Probably mine is a trivial,
solved problem, but I have been unable to solve it despite considerable
effort, otherwise I wouldn't be asking you for help. Please correct any
breaches of question protocol, and feel free to forward this to someone who
you think can help, though I'd prefer if you stripped off this introductory
paragraph and just forwarded the technical question that follows.
I want to move multiple files to a directory. I know how to use mv to do
this one file at a time (i.e., mv [file] [directory]), and I figure there
must be a way to do it en masse, without naming each file explicitly. Below
is my conversation with the system. On the off chance that mv supported
perl-like regular expressions, I tried using .* as a wildcard, but mv does
not like that. ("August, 2010" is a directory; anything named "August x,
2010", where x is a numeral, is a file. I have deleted the full pathname for
privacy and inserted a few hard carriage returns for readability.)
>August, 2010 August 29, 2010 August 5, 2010.odt
>August 25, 2010.odt August 30, 2010
>August 26, 2010.odt August 31, 2010
>August 27, 2010.odt August 4, 2010.odt
>$ mv August\ .*,\ 2010 August,\ 2010
>mv: cannot stat `August .*, 2010': No such file or directory
I did a google search of "does mv support regular expressions" and a quick
scan suggested that the answer is no. I googled "passing multiple file names
to mv", and I found this page, entitled "How can I rename multiple files
using wildcards?", which offers a solution (to a related problem) that uses
a shell script:
The page said "If you are using Linux, you should have the "rename" command,
which lets you use wildcards to do some simple renaming. If you are using
some other Unix, you may not have "rename", or even if you do, whatever you
want to do may be too complex for that." Then it offers the following shell
# [A-Z]* matches upper case names
for i in [A-Z]*
j=`echo $i | tr '[A-Z]' '[a-z]'`
mv $i $j
If I knew more about shell scripting, I could probably adapt the logic of
this script to a solution of my problem, but that is so far beyond my
present skill level as to be time-cost prohibitive. I sort of get the gist
of what the script does, but I cannot read/understand every token in it.
I googled "Unix mv faq" and the top few results had plenty of general
information about mv, but none addressed my question.
I also tried reading the man page for mv; a visual grep of "multiple file
names" yielded nothing. The -t option (move all SOURCE arguments into
DIRECTORY) for mv looks like it might be promising, but I don't know how to
use it to solve my problem. I read the info page for mv and found nothing
I have been searching google groups using phrases like "UNIX beginners",
"how to use (name of utility)" as well as the above-named, more specific,
strings. All the groups I have found focus on things like hardware
compatibility, finding drivers, and "which is better, Gnome or KDE". I need
a forum for questions like "how do I pass argument x to utility y" and "grep
gives me x output to command a, but y output to command b. What gives?"
I looked on Ubuntu forums, but could only find discussions that dealt with
installation and hardware, and nothing specifically about "how do I get the
most from a command-line utility". I also looked in the hard-copy manual
"Introduction to UNIX and Linux" by John Muster. It has plenty about the mv
command, but nothing specifically about passing multiple filenames to it.
I have two questions:
In the spirit of "teach a man to fish", what forum can you recommend that
would be an appropriate place for my question(s)?
In the spirit of "give a man a fish", what strategy would you use to solve
this problem? I just need a hint. I will figure out the implementation if
you can point me in the right direction.
----- End forwarded message -----
----- Forwarded message from Rick Moen <rick at linuxmafia.com> -----
Date: Thu, 2 Sep 2010 16:22:28 -0700
From: Rick Moen <rick at linuxmafia.com>
To: Michael Gray <michaelcgray at gmail.com>
Subject: Re: UNIX beginner asks: what's a good forum for q's about
Organization: If you lived here, you'd be $HOME already.
Quoting Michael Gray (michaelcgray at gmail.com):
> I want to move multiple files to a directory.
A classic problem. What's really interesting is why it's a problem,
when primitive OSes like MS-DOS do it easily. It's mostly because the
Unix shell expands globs (wildcards) before passing filespecs to the
commands you specify.
You might consider installing the utility 'mmv' (multiple move), if
Ubuntu doesn't have it already. Here's an HTMLised version of its
manpage: http://ss64.com/bash/mmv.html ("mmv" would not be considered
a 'standard tool' of the Unix toolset, though, for whatever that's
worth. Long story.)
> I did a google search of "does mv support regular expressions" and a quick
> scan suggested that the answer is no.
The standard solution (other than resorting to Perl) would probably be
using grep / egrep to provide the filespec and pipe that to "mv", using
the -print0 stuff to compensate for odd filenames such as ones with
embedded space characters.
> I have two questions:
> In the spirit of "teach a man to fish", what forum can you recommend that
> would be an appropriate place for my question(s)?
The Usenet newsgroup "comp.os.unix.shell". Without a doubt.
It has a newsgroup FAQ: http://www.faqs.org/faqs/unix-faq/shell/intro/
Don't be too surprised to hear crotchety objections to some of the
better suggestions posted, along the lines of 'Hey, you shouldn't rely
on crutches like [useful tool enhancement], beause that's a GNU
extension and you should only do portable scripts."
> In the spirit of "give a man a fish", what strategy would you use to solve
> this problem? I just need a hint. I will figure out the implementation if
> you can point me in the right direction.
I'd love to give you an approximately right example, but am presently on
holiday in Melbourne, Victoria, Australia, and have only interittant
Internet access at the moment. I'll be back on the 7th.
----- End forwarded message -----
More information about the conspire