OT: Bash script help needed

Craig Puchta craig at craigpuchta.net
Thu Dec 20 13:30:44 UTC 2007


This is off topic, but I'm not sure where to look for answers.

I am looking for some help in making a script to make directories and
move files to those directories. I am doing it manually and since I have
tens of thousands of these files to move, I figure there must be an
easier way to do it.
Here is what I have and want to do.

In one directory I have tens of thousands of .txt files named as such:

rdb-001-001.txt
rdb-001-002.txt
rdg-002-001.txt
rdg-002-002.txt 
and so on.

What I want to do (and not manually, as I haven't even put a dent in it
yet) is:

mkdir rdb-001
mv rdb-001-* rdb-001
mkdir rbg-002
mv rbg-002-* rbg-002

I want to make a script that can grab a file name, make the directory
and move all corresponding files to that directory. The problem is I
don't know what command could grab a file name and make a directory from
it.
Any help would be appreciated. 





More information about the ubuntu-users mailing list