Re: create directories based on directory contents
- From: ibuprofin@xxxxxxxxxxxxxxxxxxxxxx (Moe Trin)
- Date: Tue, 30 Jan 2007 10:04:39 -0600
On 29 Jan 2007, in the Usenet newsgroup comp.os.linux.misc, in article
<1170129250.226737.308410@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
gmail@xxxxxxxxxxxxxxxx wrote:
Suppose I have the following directory structure:
[...]
is it possible to issue some commands that will automatically create 3
subdirectories, AAA, XXXXX, ZZ and subsequently move all the files
into these folders?
Yes, but you'd spend more time creating a script to do so than just
doing
ls *jpg | sed 's/_[0-9]*.jpg//' | column
to get a list of the letter prefixes, then manually creating the
directories, and finally doing
mv AAA*jpg AAA
and so on. A UNIX guru will often spend six hours to create a tool that
will do a two hour job in ten minutes - but only if it looks as if the
tool will be used several times. If it's a one-time job, doing things
manually is actually more efficient.
Now, if this is a homework assignment, there are several ways to create
a script to do this job. I'd probably use a shell glob through a 'sed' to
get the prefix, through a 'sort -u' to get a variable, and use that in a
simple loop to create the directory, and do the move. Something on the
idea of
for VAR in `ls *jpg | sed 's/_[0-9]*.jpg//' | sort -u`
do
mkdir $VAR
mv $VAR_* $VAR
done
although that probably has at least one error (hey - I haven't finished
my first cup of coffee), and may blow up violently. As a matter of fact,
I even see one error already - but this is just displaying the concept.
Old guy
.
- References:
- create directories based on directory contents
- From: gmail
- create directories based on directory contents
- Prev by Date: Re: free command what does buffers/cache mean ?
- Next by Date: Re: Whats a good way to write GUI apps
- Previous by thread: Re: create directories based on directory contents
- Next by thread: Re: create directories based on directory contents
- Index(es):
Relevant Pages
|