Processing multiple files in a directory and moving them.
Hi! I am trying to rename a large number of files in a particular directory and move them into a new directory.
Ex: /var/named file1.db, file2.db file3.db - rename to file (strip off .db) and move to new directory /var/named/new/file, file2, file3 Here is my attempt to complete this but its not functioning: cd /var/named echo *.db | sed -e 's/.db//' |xargs `mv /var/named/new` What am I doing wrong? Thanks. |
im no expert but you might wanna try commands such as "dd" or "cp"
edit: my book says use "mv" |
Ok I tried the following command with no luck as either?
find *.db | sed -e 's/.db//' |xargs cp -R /var/named/new/ |
Code:
for original in ./*.db; do |
You could use variable substitution:
Code:
for file in *.db; do |
if i wanted to take say "file" and copy it multiple times to a directory like file0,file1,file2,file3,file4 etc. how would i do it?
|
Code:
for suffix in {0..100}; do |
that did a whole lot of nothing anything else that might make say 50 copies of one file
|
My two cents. :)
Code:
for file in *.db; do mv $file new/${file%.db}; done |
Quote:
Quote:
Code:
for suffix in {0..100}; do 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 |
What prevents you from running this as a command? Just type this in a terminal
for original in ./*.db; do cp $original /var/named/new/$(basename $original .db); done and voila! :) |
Thanks Uncle_Theodore, I just gave that a shot. I didn't know you could run for loops at the terminal.
|
pwc101 yours worked after i figured out how to use it.... thank you
|
Quote:
|
All times are GMT -5. The time now is 08:45 AM. |