One directory, extracting only files to a new directoy


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting One directory, extracting only files to a new directoy
# 8  
Old 09-07-2015
@Don Cragun
This is why I might cut the first 64 digits, because it looks a bit too nasty with the sha256sum, imagine sha512sum.

Code:
f888084c9ee5af98bb46df1c059b8cc2bcc4d9c43691e139f5bce44c64926e3a  ./drum/soundz4/GLASS CAVES – Out Of Control.mp3

as always learning

@Aia for heavens sake, sed coming up......yeah, I will train this....thanks, I will report later.

harsh.....

---------- Post updated 09-07-15 at 06:01 PM ---------- Previous update was 09-06-15 at 10:35 PM ----------

@Aia The quadcore works a lot with the xargs -0 version right now. I just started to read the first chapter of 63 for sed, so sorry, that this is one of the commands I hoped to avoid until now. First try results in one single file, the destination.mp3 in this case. hm....

@Don Cragun
one directory, 252 subdirectories, nearly 5000 tunes, different versions, kbps, length, put them in one folder.
My script from last year, well lets call it a snippet of a script, was hopping from one directory as the outset to move (cp) to destination. Then I took the destination to hop to the third new directory and so on. Surely not a hundred times, but it got a result of 30GB for snippets of tunes, one second of hihat, 3 seconds of openhihat, all together 26k files, or items. Therefore I used this construction

Code:
find /home/origin -type f -exec sha256sum {} \; | sort -k 64 >  /tmp/runner;txt | cp -nr /home/origin /home/destination && cat  -n /tmp/runner.txt | cut -d " " -f1; exit 0;

and guess what, it worked.

And I am aware, that the real 19 inch server rack is not sorted like this, they would put any file listed in alphabetical order, for each letter one drive, may even for different formats (.jpeg or .png) different mirrors. It is just to have it in one directory and later on on a pluggable drive.

@Aia It stopped after 575 songs, unable to call stat for "-" (no underliner), could not find directory. Running now version two, with sed. That goes well as root, I'll try it as well as user. Resulting in 4429 tunes, 22 GB. Orignally it was 22.9 GB. Now I could work with diff or midnight commander.

Last edited by 1in10; 09-07-2015 at 06:45 PM.. Reason: resulting in less
# 9  
Old 09-08-2015
I am very glad that the command line:
Code:
find /home/origin -type f -exec sha256sum {} \; | sort -k 64 >  /tmp/runner;txt | cp -nr /home/origin /home/destination && cat  -n /tmp/runner.txt | cut -d " " -f1; exit 0;

is working for you. Assuming that the /tmp/runner;txt in the above is a typo and that what you really used was /tmp/runner.txt AND assuming that the cp completes successfully; are you aware that the above is equivalent to the three completely independent command lines:
Code:
cp -nr /home/origin /home/destination
find /home/origin -type f -exec sha256sum {} \; | sort -k 64 | tee /tmp/runner.txt | cut -d " " -f1
exit 0

which means, as I said before, that all of the stuff that you're doing with the checksums has absolutely no affect on the set of files copied to your destination directory.

Note also, that unless some of your song titles contain more than 62 "words", the second command line is equivalent to the slightly simpler:
Code:
find /home/origin -type f -exec sha256sum {} \; | sort | tee /tmp/runner.txt | cut -d " " -f1

which sorts with the checksum as the primary sort key and the song title as the secondary sort key. But, if some titles do have more than 62 "words" and you use sort -k 64, your primary sort key is the 63rd "word" in your song titles, the secondary sort key is the checksums, and the tertiary sort key is the rest of the song title. I do not understand why the 63rd word in your song titles should be so significant???

Presumably the reason why the size of the destination directory is smaller than the size of the source file hierarchy is because:
  • the amount of space consumed by the directories in the source file hierarchy is larger than the amount of space consumed by the single destination directory, and
  • for each set of files in the source hierarchy with the same final pathname component name, only one element in each set is included in the destination directory.
This User Gave Thanks to Don Cragun For This Post:
# 10  
Old 09-08-2015
right, thanks for the hint. Solved

@Don Cragun: You are right, not only the typing error of " ; " but the length of the field for the checksum. Browsing the result there are no hidden files like
Code:
 ./mediaartlocal

, that tiny thumbnails, and probably some links. So thanks a lot to
@Aia and you,
even pushing me into the streamline editor. I will probe it some more times with diferent values. Really thanks a lot for your attention.

Last edited by 1in10; 09-08-2015 at 09:26 AM.. Reason: spelling and quoting
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Extracting directory portion.

Dear Experts, I have some directory structure something like follows. I would like to cut portion of it. Would you please help me? I have to run this on several sql's. The directory path is dynamic. I have cut what comes after first "sql" string. Input:... (3 Replies)
Discussion started by: srikanth38
3 Replies

2. UNIX for Beginners Questions & Answers

Extracting to another directory using cygwin

I have a file, in Windows, called php_0.27.tar.gz and want to extract it to C:\Program Files\PHP\script through Cygwin using this command: tar -xf php_0.27.tar.gz -C /Program Files/PHP/script But I got an error saying: tar: Files: Not found in archive I tried this command too: ... (8 Replies)
Discussion started by: steve120
8 Replies

3. Shell Programming and Scripting

How can we automaitcally sync/copy files from one directoy to another ?

Hi, I would like to achieve below requirement, I have a directory "/mydir" and I want to automatically sync/copy all the content of /mydir directory to "/yourdir" directory all the time. meaning, if some application creates a file in /mydir, it supposed to be copied/available in "/yourdir"... (4 Replies)
Discussion started by: aaron8667
4 Replies

4. Shell Programming and Scripting

Directoy Size - avoid cannot read directory

Hello, I need to write a script to check directory size on a linux server. I do not have access to some directories Inside the directory tree so I've got some warning in the output that say : du : cannot read directory .... Could you please help me. I did try Inside of my script to... (2 Replies)
Discussion started by: Aswex
2 Replies

5. Shell Programming and Scripting

Extracting into a remote directory

I need to fit in a module in my Korn Shell script which would extract file_archive.tar.gz residing in the folder /apps/Test of my local machine into a folder /global/ in a remote machine server1. Please help me on this regard. Thanks Kumarjit. (2 Replies)
Discussion started by: kumarjt
2 Replies

6. Shell Programming and Scripting

Zipping a directory and extracting to another server.

Hello everyone, I am trying to make a script in KSH that will zip an entire directory but leave out one file in that directory. I then need to send that zipped directory to another UNIX box. I am new to UNIX and would appreciate a good template to study from. (3 Replies)
Discussion started by: BrutalBryan
3 Replies

7. Shell Programming and Scripting

Extracting Directory From Path

Hi guys. I'm doing some bash scripting and have run into a snag. Say I have the path: /home/one/two/three/ All I need is the 'three' while making a filename. Is there an easy way to do this? I've tried using grep (because I'm that smart.) cut (as I'm unable to tell how many fields there... (3 Replies)
Discussion started by: Drayol
3 Replies

8. UNIX for Advanced & Expert Users

Extracting the different files from directory & its sub directories

Hi Everyone, It would be helpful if someone helps me on this. Requirement: I have a directory which includes different types of files(for example *.java,*.class),but not restricted for only these types. I need to find the same types of file extensions from its directories and subdirectories... (3 Replies)
Discussion started by: rcvasu
3 Replies

9. Shell Programming and Scripting

extracting a field from directory path ??????

Hi I'll be getting a directory path as the input to the script. E.g. 1 abc/fsg/sdfhgsa/fasgfsd/adfghad/XXX/fhsad e.g. 2 sadfg/sadgjhgds/sd/dtuc/cghcx/dtyue/dfghsdd/XXX/qytq This input will be stored in a variable. My query is how to extract the field in a variable VAR which occurs... (15 Replies)
Discussion started by: skyineyes
15 Replies

10. UNIX for Dummies Questions & Answers

Searching a directoy

Hi, How to search a directory and know it's path. Please Help. Thanks (3 Replies)
Discussion started by: gumsun
3 Replies
Login or Register to Ask a Question