LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 05-19-2012, 12:52 AM   #1
dchurch315
LQ Newbie
 
Registered: May 2012
Location: Florida, US
Distribution: Debian
Posts: 4

Rep: Reputation: Disabled
How to copy directory and file structure with zero length files


I've been trying to solve a problem in Linux that is beyond my skill set. Basically I need to copy an entire folder and file structure but have all the files reduced to zero length and keeping the same filename. Rsync and cp seem to be missing the feature, but I'm thinking a Bash script could do the the trick if I can get the recursion right.

Anybody tackled this before? For reference, the equivalent command in Windows is ROBOCOPY (source) (dest) /E /CREATE
 
Old 05-19-2012, 01:20 AM   #2
cbtshare
Member
 
Registered: Jul 2009
Posts: 645

Rep: Reputation: 42
just use the exclude command with rsync.


Quote:
rsync will copy files from one directory to another directory on the same machine like robocopy. Here is the rsync command that is equivalent to your robocopy command:

rsync -auv --exclude 'file' --exclude '*.file extension' source destination
or try this script:

http://www.cis.upenn.edu/~bcpierce/unison/

Last edited by cbtshare; 05-19-2012 at 01:23 AM.
 
Old 05-19-2012, 01:34 AM   #3
dchurch315
LQ Newbie
 
Registered: May 2012
Location: Florida, US
Distribution: Debian
Posts: 4

Original Poster
Rep: Reputation: Disabled
Just to clarify - I need to copy all the folders AND files, but have the files reduced to zero length to save space. The files may have hundreds of different extensions, so a command specifying each extension isn't practical.
 
Old 05-19-2012, 02:26 AM   #4
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,108

Rep: Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598
Have you tried 'cp -r --attributes-only <source directory> <destination directory>' ?
 
Old 05-19-2012, 01:38 PM   #5
dchurch315
LQ Newbie
 
Registered: May 2012
Location: Florida, US
Distribution: Debian
Posts: 4

Original Poster
Rep: Reputation: Disabled
The Ubuntu/Debian CP command doesn't support the --attributes-only parameter - is that only in newer versions past 11.04?
 
Old 05-19-2012, 02:02 PM   #6
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,108

Rep: Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598
The --attributes-only option was added in coreutils-8.6
From http://lists.gnu.org/archive/html/co.../msg00079.html
Quote:
** New features

cp now accepts the --attributes-only option to not copy file data,
which is useful for efficiently modifying files.
 
Old 05-19-2012, 02:11 PM   #7
dchurch315
LQ Newbie
 
Registered: May 2012
Location: Florida, US
Distribution: Debian
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thanks - upgrading the package now.
 
Old 07-25-2016, 08:41 PM   #8
itsdezman
LQ Newbie
 
Registered: Jul 2016
Posts: 1

Rep: Reputation: Disabled
Zero Length Files

I'm in over my head here. I'm trying to replicate the Windows Robocopy feature of /CREATE that copies an entire directory with zero length files. I tried updating CP to 8.6 but no success on my Mac. Any help would be appreciated...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy Directory Structure Only ronin1 Linux - Newbie 10 06-08-2013 06:23 AM
How to copy an entire directory structure except certain files? thanhvn Programming 9 01-27-2012 11:41 AM
Convert directory structure from long file names in Linux to DOS 8.3 structure? manorina Linux - Software 5 09-12-2009 09:18 AM
bash - copy with a directory structure mkiler Linux - General 6 06-03-2008 08:45 AM
Copy directory structure? tpe Programming 2 06-02-2005 04:59 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:26 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration