Processing multiple files in a directory and moving them.
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
that did a whole lot of nothing anything else that might make say 50 copies of one file
Your original request was:
Quote:
Originally Posted by tommytomthms5
take say "file" and copy it multiple times to a directory
which I took to mean copy a file (called "file" in the example I gave) multiple times.
Code:
for suffix in {0..100}; do
input_file=/some/file/you/want/to/copy
cp $input_file /some/destination/directory/$(basename $input_file)"$suffix"; done
done
That will take a file as defined in the variable input_file and output it to /some/destination/directory named whatever $input_file was called, but with a number added as a suffix.
Please clarify if that's not what you meant.
Some pleases and thankyous (plus some commas) wouldn't go amiss either.
Guys using the script below works perfectly, but can't we run this as a command in conjunction with xargs? Just curious if not I'll just use the script. I would ideally like to run this as a command for a quick job rather than scripting out a file. I never new %.db was even possible. Need to do some reading on variable substitution.
for original in ./*.db; do
cp $original /var/named/new/$(basename $original .db)
done
Thanks for the help once again guys.
Edit Sorry I did not try at the CLI that did the job without a script. Sweet!!!!
for file in *.db; do mv $file new/${file%.db}; done
Last edited by keysorsoze; 12-25-2007 at 03:55 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.