SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2013-11-03 17:14:01

Malice
#! Member
From: Poland
Registered: 2013-10-15
Posts: 50

How to copy folders without their content

Hello,
I have 50 folders in ~/x. I want to copy these folders to ~/y, but without their content(so ls would show the same list in both ~/x and ~/y, but files in ~/y are empty).
I looked in man and --help, but I can't find the answer.
Thanks in advance!

Offline

Help fund CrunchBang, donate to the project!

#2 2013-11-03 17:18:05

lcafiero
The #! Guy
From: Felton, California, USA
Registered: 2011-07-21
Posts: 2,225
Website

Re: How to copy folders without their content


Res publica non dominetur | Larry the CrunchBang Guy speaks of the pompetous of CrunchBang

CrunchBang Forum moderator

Offline

#3 2013-11-03 17:34:01

Malice
#! Member
From: Poland
Registered: 2013-10-15
Posts: 50

Re: How to copy folders without their content

Not sure. Figured out how IRC works, so case is solved.

I first made cp -r ~/a/* ~/b
Then, I used rm ~/b/*/*

So effectively, I first copied all folder from one directory to other, and then deleted it's content.  I don't know I could have done it easier, but this solution worked. Anyway, thanks for help!:)

Offline

#4 2013-11-03 20:55:06

moetunes
#! Member
Registered: 2012-10-06
Posts: 75

Re: How to copy folders without their content

Something like

for f in $(ls ~/a); do mkdir ~/b/$f; done

would do what you want.

Offline

#5 2013-11-06 12:09:10

johnraff
nullglob
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 4,148
Website

Re: How to copy folders without their content

rsync (In the thread Lcafiero linked) seems the neatest way.

rsync --dirs ~/x/ ~/y

@moetunes:

for ... ls ...

will likely break if any folders have spaces in the names.

Last edited by johnraff (2013-11-06 12:11:35)


John
--------------------
( a boring Japan blog , Japan Links, idle twitterings  and GitStuff )
#! forum moderator    BunsenLabs

Offline

#6 2013-11-06 19:10:54

iann
#! Die Hard
Registered: 2010-09-10
Posts: 720

Re: How to copy folders without their content

Could also use find . -type d -exec ...

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.
Server: acrobat

Debian Logo