find -size -7M finds files, but won't cp them all


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers find -size -7M finds files, but won't cp them all
# 1  
Old 12-23-2010
find -size -7M finds files, but won't cp them all

If I run:
Code:
find /somefolder -type f -size -7M | wc -l

I get 73594 files

But when I run
Code:
find /somefolder -type f -size -7M -exec /bin/cp -v {} /someotherfolder/ \;

it only copies 38891 of the files to the folder, why? There's a mix of all types of files in /somefolder. Is there some other way I should be doing this?
# 2  
Old 12-23-2010
Is it giving any error? Did you check the exit status of command after it is completed (echo $?)
# 3  
Old 12-23-2010
there are no errors, I tried it with rsync using:
Code:
rsync -ruv --max-size=7M --progress /somefolder/* /someotherfolder

and that works, but I don't want to preserve the file structure in the destination folder.
# 4  
Old 12-24-2010
I'd guess the 'cp' command may only accept up to a certain number of arguments, and the full list of files exceeds that number ... if I recall correctly (no guarantee) the -exec option causes the full list to be presented to the command it invokes ... though I'd expect it would provide an error message about too many arguments ... what OS & 'cp' version are you working with?
# 5  
Old 12-24-2010
You may try following then:
Code:
cnt=1
find /somefolder -type f -size -7M | while read file; do
   echo "Copying $cnt: $file"
   cp $file /someotherfolder/
   cnt=$(expr $cnt + 1)
done


Last edited by anurag.singh; 12-24-2010 at 07:49 AM..
# 6  
Old 12-24-2010
Maybe you have files in different subdirectories but with the same filename.
Try counting your unique names to test this theory.
Code:
find /somefolder -type f -size -7M -exec basename {} \; | sort | uniq | wc -l


I do hope that /someotherfolder is not a subdirectory of /somefolder .
This User Gave Thanks to methyl For This Post:
# 7  
Old 12-28-2010
NoWizz -> Debian Squeeze 64bit, cp (GNU coreutils) 8.5

anurag.singh -> doesn't copy filenames with spaces in filename, trying to figure out a workaround

methyl -> this outputted 38,xxx files, which is the reduced number it cp'ed previously, looking into duplicate filenames, not sure how to test this to confirm it's the problem. I ran it without piping to uniq and it returned 73,xxx files, so maybe that's my answer?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finds all duplicate files

Hi, How would you write bash script that given a directory as an argument and finds all duplicate files (with same contents - by using bytewise comparison) there and prints their names? (6 Replies)
Discussion started by: elior
6 Replies

2. Solaris

Find the total size of multiple files

If I have a number of files in a directory, for example, test.1 test.2 test.3 abc.1 abc.2 abc.3 and I need to find the total file size of all of the test.* files, I can use du -bc test.* in Linux. However, in Solaris, du does not have the -c option. What can I do in Solaris to get... (11 Replies)
Discussion started by: learnix
11 Replies

3. Shell Programming and Scripting

Find duplicate files by file size

Hi! I want to find duplicate files (criteria: file size) in my download folder. I try it like this: find /Users/frodo/Downloads \! -type d -exec du {} \; | sort > /Users/frodo/Desktop/duplicates_1.txt; cut -f 1 /Users/frodo/Desktop/duplicates_1.txt | uniq -d | grep -hif -... (9 Replies)
Discussion started by: Dirk Einecke
9 Replies

4. Shell Programming and Scripting

Find file size difference in two files using awk

Hi, Could anyone help me to solve this problem? I have two files "f1" and "f2" having 2 fields in each, a) file size and b) file name. The data are almost same in both the files except for few and new additional lines. Now, I have to find out and print the output as, the difference in the... (3 Replies)
Discussion started by: royalibrahim
3 Replies

5. HP-UX

How can I find the size of files added to a folder after a particular date

Hi, I want to find the size of the files added to a folder after a certain date(say 1st of october), I know we can list the files which were created after a certain date , but is there anyway to find the total size of those files ? (3 Replies)
Discussion started by: alookachaloo
3 Replies

6. Shell Programming and Scripting

How to find size 0-4 bytes files?

Hi I need to find and delete 0-4 bytes size files in a folder. How can I achieve that? (1 Reply)
Discussion started by: kapilk
1 Replies

7. UNIX for Dummies Questions & Answers

very urgent..need of a script which finds a file without the use of find command..hlp

im a beginner in shell scripting and i need a script which will find a file in a given path without the use of find or grep command.......i need some kind of code.....plzzz plzzzz help me......ive tried n searched every where but i couldn't find the solution for my particular problem..... (4 Replies)
Discussion started by: mishi
4 Replies

8. UNIX for Dummies Questions & Answers

find command returns files with spaces, mv won't work...

Hi guys. I am trying, to move files found with the find command... Script runs fine, until it reaches a file that contains spaces... Here is what i wrote up quickly. ROOTDIR=/apps/data SEARCH=$(find /data/HDTMPRestore/home/tmq/ -type f -print | grep Mods/Input/bck | cut -c19-) for i... (1 Reply)
Discussion started by: Stephan
1 Replies

9. UNIX for Dummies Questions & Answers

Find total size for some files?

Hi, I'm newbie to Unix. I'd like to count the total size of those files in my directory by date. For example, files on this period 05/01/08 - 05/31/08. If possible can we count by byte instead of kb. if I use $ du - ks , it will add up all files in the dir. thanks, Helen (5 Replies)
Discussion started by: helen008
5 Replies

10. UNIX for Dummies Questions & Answers

How can I find files by date or size from stout?

Hello all I wander if I make for example " ls -l " And it gives me all the files in the directory with the additional info like data size and privileges But what if I like to filter the stout result for example by date When I try to do: echo "`ls -l`" | grep "Jan 12" it gives me the... (2 Replies)
Discussion started by: umen
2 Replies
Login or Register to Ask a Question