1752796 Members
5999 Online
108789 Solutions
New Discussion юеВ

Re: cp command

 
SOLVED
Go to solution
Igor Sovin
Super Advisor

cp command

Hi!
I have a problem that seems to be very easy to solve, at first sight.

How to cp all directories beginning with . from / to some other directory?


Best regards
Igor
8 REPLIES 8
Fabian Brise├▒o
Esteemed Contributor

Re: cp command

Hello Igor.
YOu can use the folliwng command to do what you want

cp -p -R .from* /tmp
where /tmp is the destination address
Knowledge is power.
Igor Sovin
Super Advisor

Re: cp command

sorry :-)

I mean all directories beginnig with .
from - means from root directory /
from is not directory name
Sandman!
Honored Contributor
Solution

Re: cp command

Excerpt from the cpio man page...

# man cpio
...
Duplicate a directory hierarchy:
cd olddir
find . -depth -print | cpio -pd newdir
...
Rajeev  Shukla
Honored Contributor

Re: cp command

i would do something like this to be on the safer side
cd /
for i in `ls -ld .[a-z]*|grep ^d|awk '{print $9}'`
do
cp -rp $i /destinationDIR
done
Rajeev  Shukla
Honored Contributor

Re: cp command

If you have directory with names starting from say .A to .Z or .1 etc.. then change the line to something like this
ls -ld .[aA1-zZ0]*|grep ^d|awk '{print $9}'
Just try running this command from / and you'll see all the directories starting with .
Mridul Shrivastava
Honored Contributor

Re: cp command

The directory "." means the present working dorectory and ".." means the parent directories so these can't be moved...
Time has a wonderful way of weeding out the trivial
Stefan Schulz
Honored Contributor

Re: cp command

Hi,

the most pragmatic way is to use

cp -rp .??*

but with the limitation that it will not copy directories with one character names and also will copy all files beginning with a dot.

Hope this helps

Regards Stefan
No Mouse found. System halted. Press Mousebutton to continue.
Hareesh Kumar
Advisor

Re: cp command

Hi,

Use the command from /
# find . -depth|cpio -pvxdm

Try and revert..

Hareesh