I have been looking for how to do this for *years*. You often have
to change the name of a file in another directory. That's easy
in Windows, but in Unix you have to key in the whole
blasted filespec again (and hope you don't make a typo):
mv /home/d/dannyw/blosxom/data/images/phnompenhtrip/crossing1.jpg...
aaagh, I can't go on.
In a Linux journal article on the *bash* shell, I found this:
www.linuxjournal.com
[http://www.linuxjournal.com/article/7385]
echo {one,two,three}fish
onefish twofish threefish
echo /etc/httpd/conf/httpd.conf{,.bak}
/etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bak
Those are *wiggly* brackets, and they create *multiple* parameters
to your command line, so you can do something like:
mv /etc/httpd/conf/httpd.conf{,.bak}
mv /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bak
I tried it under tcsh, and it still worked.
Perfecto! If only I can remember it!
Link to teach-yourself-sh guide on the web
I feel embarrassed to admit this but when I need to do a shell script I
often realize that I have forgotten some essential trick. Because the
shell tends to use very short and/or common keywords, it's very difficult
to search for terms like "if" or "return" to check syntax/usage. (I get
mixed up between sh, csh and bash, also perl of course; sometimes I try
syntax which *appears* to work but is actually doing something quite
different from what I intended...)
So the most efective thing is probably to check out general
beginner-level guides now and then. Criminy, I've done most of this
stuff n times before, honestly – but I learn something new every time.
steve-parker.org
[http://steve-parker.org/sh/sh.shtml]
Nicely-formatted, and with clear useful examples. I noticed bigwebmaster.com
and librenix.com both linked to it.
Tips on using the Unix command line -- syntax for "locate" utility
The "locate" utility uses a prebuilt database to rapidly find
filenames anywhere on the system. Clearly it depends on a
recent database. Also, the database frequently is generated
without following symbolic links (which might well be circular,
or otherwise result in gigantic numbers of files0; and the many
security issues mean it is often disabled for non-root
users.
Oh well. If you *can* use it, you may run into this syntax issue.
I'd often tried to use commands of the form
locate stuff.*
but they didn't seem to work.
Commands of this form work:
locate stuff
and return stuff.c, stuff/some.txt, /home/danny/stuff.001/some.txt
etc, but don't give much control to reject the stuff you don't
need.
Of course the * needs to be hidden from the shell:
locate "stuff.*"
but that does not work either, because when a wildcard is used the
non-wildcard characters have to match *exactly* – so in this case
it will not even find "stuff.c" in the current directory (because
"locate" stores all its locations in absolute form, and does not
compare relative to the current directory).
Instead what you have to do is:
locate "*stuff.*"
Tips on using the Unix command line -- Fixing a broken shell
Whenever I get an account on a new Unix system it usually
turns out that the action of the
backspace key is messed up. The reason for this is that Emacs has
a default configuration which is both terrible and impossible to
understand, and the original installer spends weeks finding one
issue after another, whether inside Emacs or at the shell level;
when he winds up with a configuration that
works for him, he never wants to mess with it, even if it's screwed
up for everyone else.
The result is that I have to dink around with various shell config
changes till I get it right, and sometimes I wind up with a hosed
shell. This is something that worked for me using bash, when I
found a "magical" snippet of code in the default shell config.
I tried editing .bashrc: I added "stty ek" to run after the
funny code which seemed to cause the problem: it resets erase
and kill key handling to default, and seemed to do what I
want for vi, at least.
Tips on using the Unix command line -- Acting on a list of files
I wanted to listen to a bunch of sound files, all of which were
quite short. Eventually I used "find" to put
a list of NL-separated sound filenames in audio.dat); the trick
for converting filenames into *arguments* is one that took some
head-scratching. It's the "$()" below:
cat $(cat audio.dat) > /dev/audio
This is actually an overcomplex example. I only needed to use
"find" because there were sound files in multiple subdirs, and
I wanted to pick up the full pathnames. Likewise, if you
don't know how the linux /dev/audio device works, just catting
a binary sound file to it will look a little confusing.
Here's a simpler example, though less useful. Suppose you wanted
to concatenate a bunch of files whose filenames were in a file
called orange.txt. You could do:
cat $(cat orange.txt) > compendium.txt
This example, it occurs to me, is probably also a little confusing.
The "cat" program is being used in two different ways: just to
copy orange.txt to standard output; and then to truly concatenate
the files defined in orange.txt. Oh well; I suppose most people
who can see the usefulness of this tip at all already grok cat.
(It also occurs to me I could have done a find -exec, but that's always
so clumsy; this seems better. Also, because it works with a
pre-generated file listing, it avoids long pauses in the
sound output if "find" takes a while to find the next file.)
When I checked, csh did not like the "$()" syntax, but it worked in sh and
bash.
I hope this information was useful. There may be a great deal more
information on this site that is relevant to what you need.
Take
a look at the "site map" display at left; you
can click on a topic to see many recent items on that topic.
Debug: hittotal: 17 startban: 0
dancookie: endbandate:
banned: 0 tempdate:
tert: jse: jsno jsh: 17