Sponsored Content
Top Forums Shell Programming and Scripting Recursively move directories along with files/specific files Post 302520203 by frintocf on Friday 6th of May 2011 05:47:32 AM
Old 05-06-2011
Recursively move directories along with files/specific files

I would like to transfer all files ending with .log from /tmp and to /tmp/archive (using find )
The directory structure looks like :-
Code:
/tmp
    a.log
    b.log
    c.log
         /abcd
             d.log
             e.log

When I tried the following command , it movies all the log files to /tmp/archive (does not maintain the directory structure )
Code:

find /tmp -name "*.log" -type f -exec mv {} /tmp/archive \; 

The output is

Code:
/tmp/archive
     a.log
     b.log
     c.log
     d.log
     e.log

whereas the output should be

Code:
/tmp/archive
     a.log
     b.log
     c.log
          /abcd
             d.log
             e.log

For copying (cp) ,this can be done using -R but does not work with move (mv) .Is there any simple command to achieve this .

I had gone through forums and come across few commands rsync ,tar ......

Code:
find /tmp -name "*.log" -type f -exec rsync {} /tmp/archive \;   /* gives the same output */

Also , could anyone explain the difference between cp and rsync
What is the usage of the command tar?

Last edited by Franklin52; 05-24-2011 at 12:52 PM.. Reason: Please use code tags
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Recursively copy only specific files from a directory tree

Hi I am a shell-script newbie and am looking to synchronize certain files in two directory structures. Both these directory-trees are in CVS and so I dont want the CVS directory to be copied over. I want only .sh and .pl files in each subdirectory under these directory trees to be... (3 Replies)
Discussion started by: sharpsharkrocks
3 Replies

2. Shell Programming and Scripting

grep'ing for specific directories, and using the output to move files

Hello, this is probably another really simple tasks for most of you gurus, however I am trying to make a script which takes an input, greps a specific file for that input, prints back to screen the results (which are directory names) and then be able to use the directory names to move files.... (1 Reply)
Discussion started by: JayC89
1 Replies

3. Shell Programming and Scripting

Loop to move files in different directories

Hi, I have various log files in different paths. e.g. a/b/c/d/e/server.log a/b/c/d/f/server.log a/b/c/d/g/server.log a/b/c/h/e/server.log a/b/c/h/f/server.log a/b/c/h/g/server.log a/b/c/i/e/server.log a/b/c/i/e/server.log a/b/c/i/e/server.log and above these have an archive folder... (6 Replies)
Discussion started by: acc01
6 Replies

4. UNIX for Dummies Questions & Answers

List directories and sub directories recursively excluding files

Hi, Please help me, how to get all the direcotries, its sub directories and its sub directories recursively, need to exclude all the files in the process. I wanted to disply using a unix command all the directories recursively excluding files. I tried 'ls -FR' but that display files as... (3 Replies)
Discussion started by: pointers
3 Replies

5. Shell Programming and Scripting

Deleting all files recursively from directories while ignoring one file type

Hi, Seems like I need help again with a problem: I want to delete all files from my lets say "Music" Directory inkluding all of the subfolders except for .mp3 and .MP3 files. I tried it with globalignoring mp3 files, finding and deleting all other files, which resulted in all files... (3 Replies)
Discussion started by: pasc
3 Replies

6. UNIX for Dummies Questions & Answers

Move multipe files to corresponding directories

Hi, In a parent directory there are several files in the form IDENTIFIER1x IDENTIFIER1.yyy IDENTIFIER1_Z, etc IDENTIFIER2x IDENTIFIER2.yyy IDENTIFIER2_Z, etc IDENTIFIER3x IDENTIFIER3.yyy, IDENTIFIER3_Z, etcIn the same parent directory there are corresponding directories named... (7 Replies)
Discussion started by: spirospap
7 Replies

7. Shell Programming and Scripting

Find Large Files Recursively From Specific Directory

Hi. I found many scripts in the web of achieving this. But I like to use this one find /EDWH-DMT03 -xdev -size +10000 -exec ls -la {} \;|sort -n -k 5 > LARGE.rst But the problem is, why it still list out files with 89 bytes as the output? Is there anything wrong with the command? My... (7 Replies)
Discussion started by: aimy
7 Replies

8. Shell Programming and Scripting

Copy Specific Files Recursively

Is it possible to only copy selected files+its directories when you are copying recursively? find /OriginalFolder/* -type -d \{ -mtime 1 -o -mtime 2 \ } -exec cp -R {} /CopyTo/'hostname'__CopyTo/ \; -print From the above line, I want to only copy *txt and *ini files from /OriginalFolder/* ... (4 Replies)
Discussion started by: apacheLinux
4 Replies

9. UNIX for Beginners Questions & Answers

Move several files into specific directories with a loop

Hello, I'm a first time poster looking for help in scripting a task in my daily routine. I am new in unix but i am attracted to its use as a mac user. Bear with me... I have several files (20) that I manually drag via the mouse into several named directories over a network. I've used rsync... (14 Replies)
Discussion started by: SonnyClark
14 Replies
PMFETCHARCHIVE(3)					     Library Functions Manual						 PMFETCHARCHIVE(3)

NAME
pmFetchArchive - get performance metrics directly from an archive log C SYNOPSIS
#include <pcp/pmapi.h> int pmFetchArchive(pmResult **result); cc ... -lpcp DESCRIPTION
pmFetchArchive is a variant of pmFetch(3) that may only be used when the current Performance Metrics Application Programming Interface (PMAPI) context is associated with an archive log. The result is instantiated with all of the metrics (and instances) from the next archive record, consequently there is no notion of a list of desired metrics, and the instance profile of the PMAPI context is ignored. It is expected that pmFetchArchive would be used to create utilities that scan archive logs, while the more common access to the archives would be via the pmFetch(3) interface. To skip records within the archive log, use pmSetMode(3) to change the collection time within the current PMAPI context, then call pmFetchArchive. Note that the result returned by pmFetchArchive is dynamically allocated, and must be released using pmFreeResult(3), not free(3C). See pmFetch(3) and pmFreeResult(3) for further details. pmFetchArchive returns zero on success. SEE ALSO
PMAPI(3), pmFetch(3), pmFreeResult(3), pmNewContext(3), pmSetMode(3) and pmTrimNameSpace(3). DIAGNOSTICS
PM_ERR_NOTARCHIVE the current PMAPI context is not associated with an archive log Performance Co-Pilot PCP PMFETCHARCHIVE(3)
All times are GMT -4. The time now is 07:07 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy