GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   any sysadmins up? shell question: (https://gfy.com/showthread.php?t=669271)

Naja-ram 10-23-2006 12:19 AM

any sysadmins up? shell question:
 
I have a file I want to copy to a few directories at once.
the file is located in /var/www/dir0/myfile.txt and I want to copy it to the following:
/var/www/dir1/
/var/www/dir2/
/var/www/dir3/
/var/www/dir4/

so I tried to use:
Code:

cp /var/www/dir0/myfile.txt  /var/www/dir*/myfile.txt
I got:
Code:

cp: copying multiple files, but last argument `/var/www/dir2/myfile.txt' is not a directory
it is.

I also tried
Code:

cp /var/www/dir0/myfile.txt /var/www/dir*/
and got:
Code:

cp: omitting directory `/var/www/dir0'
ofcourse I tried things like cp /var/www/dir0/myfile.txt /var/www/dir[0-9]/

also tried using the -r parameter.



I am root on the server.

what'chya say?

PussyTeenies 10-23-2006 12:40 AM

use

Code:

for i in $(ls -1d /var/www/|grep -v dir0); do cp /var/www/dir0/myfile.txt /var/www/$i;done
breakdown

you make a listing of all directories except dir0
then you copy the mytext to all directories found ;)

PussyTeenies 10-23-2006 12:41 AM

ah and

Code:

cp: omitting directory `/var/www/dir0'
thats just that you are trying a copy to a allready copying directory ;)

hence the grep -v dir0 part in my anwser

fuzebox 10-23-2006 12:45 AM

I'd do this:

foreach `ls -d /var/www/dir?`;do cp /var/www/dir0/myfile.txt $i;done

It'll throw up an error about /var/www/dir0 that you can ignore.

At least this works in most installations...


All times are GMT -7. The time now is 05:08 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123