find size, cp breaks directory structure


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting find size, cp breaks directory structure
# 8  
Old 02-25-2010
Debian Squeeze & bash, and thanks a lot for your help so far methyl Smilie
# 9  
Old 02-26-2010
Quote:
Originally Posted by unclecameron
Code:
find /sourcefiles -type f -size -7M -print | while read file
do
        dir=$(dirname $file)
        echo "mkdir -p /home/some/path/testdir"$dir
        echo "cp -uv "$file "/home/some/path/testdir"$dir
done

but I get the error:
[code]
dirname: extra operand `blah/blahblah/somefile.txt'
Try `dirname --help' for more information.
Got spaces in your path, because that message seems like this might be the issue. Change it to
Code:
find /sourcefiles -type f -size -7M -print | while read file
do
        dir=$(dirname "$file")
        echo "mkdir -p /home/some/path/testdir/$dir"
        echo "cp -uv $file /home/some/path/testdir/$dir"
done

and it should run. Mind tho, as soon as you remove the echo, make sure you have double quotes around the $file and $dir variable in order to remove the special meaning from any whitespace character (so it won't act as an argument separator)
# 10  
Old 02-27-2010
wooohoooo! That worked (just had to delete the trailing slash after testdir), thanks so much for the help Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find a particular directory in multiple file systems and calculate total size

Hello : I need some help in writing a ksh script which will find a particular directory in all the file systems in a server and finally report the total size of the direcotry in all the file systems. Some thing like this.. find /u*/app/oracle -type d -name "product" -prune and then... (1 Reply)
Discussion started by: Sam1974
1 Replies

2. UNIX for Dummies Questions & Answers

find mv and create directory structure

Hi there, I'm trying to pull all my flacs out of my Music collection. I can do it with following command find b/ -name *.flac -exec mv {} flac/ \; which works great except it moves all the flac files to the flac folder. I want it to recreate the original folder the flacs were found in and mv... (8 Replies)
Discussion started by: fistikuffs
8 Replies

3. Shell Programming and Scripting

Find which dir is big size in a directory

Hi all, Could you please tellme the commadn which sorts the list of directories in a parent dir by their size. Thanks. (2 Replies)
Discussion started by: firestar
2 Replies

4. Shell Programming and Scripting

How to traverse directory structure and sum size of files?

How do I write a bash or ruby or perl or groovy script to print all the files in my directory tree that are one-to-two years old, the size of each file, and the sum of file sizes and then delete them? I was using find . -atime +365 -exec rm '{}' \; but the problem was that I could not... (5 Replies)
Discussion started by: siegfried
5 Replies

5. Shell Programming and Scripting

how to find the size of a directory alone

hi, i am using korn shell............... Any one please help me in solving the below question: question: i need to find the size of the directory alone... let us assume /root/kamal/hash1 is the directory, now i want to find the hash1 size .. ... (7 Replies)
Discussion started by: G.K.K
7 Replies

6. Shell Programming and Scripting

stop unix find on a directory structure after finding 1st occurrence

Hi, Has anyone tried to restrict Solaris 10 unix find on a large directory structure based on time to stop running after finding the first occurrence of a matching query. Basically I'm trying to build up a usage map of user workspaces based on file modification (week/month/3 months/year etc) and... (3 Replies)
Discussion started by: jm0221
3 Replies

7. Shell Programming and Scripting

Find the size of a directory

Hi, I would really appreciate if you could help me with this. I have a directory structure like this :- /data Under data i have directories /data1 , /input_files , /output_files etc . Under these directories I have other subdirectories. What i am looking for is to find out the size of all... (5 Replies)
Discussion started by: divz
5 Replies

8. UNIX for Advanced & Expert Users

MV files from one directory structure(multiple level) to other directory structure

Hi, I am trying to write a script that will move all the files from source directory structure(multiple levels might exist) to destination directory structure. If a sub folder is source doesnot exist in destination then I have to skip and goto next level. I also need to delete the files in... (4 Replies)
Discussion started by: srmadab
4 Replies

9. HP-UX

How find size of directory

Hi, How can find the size of the directory. If the directory has 1000 files. I want the total size of directory including all the files. the bdf command is just able to give only the volume size. It is not heling my cause. (2 Replies)
Discussion started by: truth
2 Replies

10. UNIX for Dummies Questions & Answers

Copying a Directory Structure to a new structure

Hi all Is it possible to copy a structure of a directory only. e.g. I have a file with the following entries that is a result of a find :- /dir1/dir2/file.dbf /dir1/dir2/dir3/file1.dbf /dir1/file.dbf I want to copy these to a directory and keep the structure however starting at a new dir... (8 Replies)
Discussion started by: jhansrod
8 Replies
Login or Register to Ask a Question