copying a file from one dir to another dir


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting copying a file from one dir to another dir
# 1  
Old 10-14-2008
Java copying a file from one dir to another dir

hi
i have a script

Code:
compareFiles()
{
find /tmp/Satya -type f | \
while read filename1
do
echo "----------------------------------------$filename1"
   find /tmp/Satya -type f | \
   while read filename2
   do
      if diff $filename1 $filename2
        then
            echo "Both files are same"
      else
               cp /tmp/Satya/$filename1  /tmp/Satya/CGTPatterns/$filename1
        fi
   done
done

}
compareFiles

i am not able to copy the file i am getting an error
cp: cannot stat `/tmp/Satya//tmp/Satya/11.File': No such file or directory

please help its urgent

Last edited by DukeNuke2; 10-14-2008 at 06:39 PM..
# 2  
Old 10-14-2008
Hammer & Screwdriver Your find is returning the filename WITH the full path

cp: cannot stat `/tmp/Satya//tmp/Satya/11.File': No such file or directory

See the /tmp/Satya/11.File in the above - that is the return from your find command. You will need to
(a) modify your copy command to adjust for the full path
or
(b) strip out for just the filename after you "find" your files
# 3  
Old 10-14-2008
Quote:
Originally Posted by Satyak
hi
i have a script

Code:
compareFiles()
{
find /tmp/Satya -type f | \


There's no need for a slash after the pipe.
Quote:
Code:
while read filename1
do
echo "----------------------------------------$filename1"
   find /tmp/Satya -type f | \
   while read filename2
   do
      if diff $filename1 $filename2


Do you really want the output of diff to show on your screen?

If not, redirect the output of diff to /dev/null.
Quote:
Code:
        then
            echo "Both files are same"
      else
               cp /tmp/Satya/$filename1  /tmp/Satya/CGTPatterns/$filename1


You can just supply the destination directory as you are not changing the filename:
Code:
cp "/tmp/Satya/$filename1"  /tmp/Satya/CGTPatterns/

Quote:
Code:
        fi
   done
done

}
compareFiles

i am not able to copy the file i am getting an error
cp: cannot stat `/tmp/Satya//tmp/Satya/11.File': No such file or directory

Last edited by cfajohnson; 10-14-2008 at 06:50 PM..
# 4  
Old 10-14-2008
Quote:
Originally Posted by cfajohnson

Please put code inside [CODE] tags.
agree. i changed this...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Assign read write permission to the user for specific dir and it's sub dir and files in AIX

I have searched this quite a long time but couldn't find the right method for me to use. I need to assign read write permission to the user for specific directories and it's sub directories and files. I do not want to use ACL. I do not want to assign user the same group of that directories too.... (0 Replies)
Discussion started by: blinkingdan
0 Replies

2. Shell Programming and Scripting

Create file Dir and Sub Dir same time

Hi Guys , I want create files Dire and Sub Dire. as same time using variable. EX: x1="/hk/Pt/put/NC/R1.txt" x2="/hk/pt/Put/Ot/NC/RN.txt" And i want delete all after done with my script. Thanks (2 Replies)
Discussion started by: pareshkp
2 Replies

3. Shell Programming and Scripting

KSH - Find paths of multiple files in CC (dir and sub-dir))

Dear Members, I have a list of xml files like abc.xml.table prq.xml.table ... .. . in a txt file. Now I have to search the file(s) in all directories and sub-directories and print the full path of file in a output txt file. Please help me with the script or command to do so. ... (11 Replies)
Discussion started by: Yoodit
11 Replies

4. UNIX for Dummies Questions & Answers

How to list all files in dir and sub-dir's recursively along with file size?

I am very new to unix as well as shell scripting. I have to write a script for the following requirement. In have to list all the files in directory and its sub directories along with file path and size of the file Please help me in this regard and many thanks in advance. (3 Replies)
Discussion started by: nmakkena
3 Replies

5. UNIX for Dummies Questions & Answers

Copying dir (and sub dir) file names from ftp server to txt file in diff server

Hey all, i want to copy only the file names from an ftp server (directory and all sub directory) to a text file in another server (non ftp), i.e. i want to recursively move through directories and copy only the names to a text file. any help is appreciated...thank you in advance (1 Reply)
Discussion started by: deking
1 Replies

6. Shell Programming and Scripting

A script to find dir, delete files in, and then del dir?

Hello!! I have directories from 2008, with files in them. I want to create a script that will find the directoried from 2008 (example directory: drwxr-xr-x 2 isplan users 1024 Nov 21 2008 FILES_112108), delete the files within those directories and then delete the directories... (3 Replies)
Discussion started by: bigben1220
3 Replies

7. UNIX and Linux Applications

CPIO Problem, copy to the root dir / instead of current dir

HI all, I got a CPIO archive that contains a unix filesystem that I try to extract, but it extract to the root dir / unstead of current dir, and happily it detects my file are newer otherwise it would have overwrited my system's file! I tried all these commands cpio -i --make-directories <... (2 Replies)
Discussion started by: nekkro-kvlt
2 Replies

8. Shell Programming and Scripting

copying files to new dir

Hello, I'm new to shell scripting so I don't really understand what I'm doing wrong. The script I'm trying to do saves all the files (*.c) on the current dir to a list and, one by one, copies them to a new one called Backup. The thing is, if there are already other versions of the files I'm... (6 Replies)
Discussion started by: G3nn
6 Replies

9. Shell Programming and Scripting

Moving file(s) from dir to dir

Hi, I am fairly new to writing scripts. I am trying to write a script that moves either One or All of the files from one directory to another. I know how to make the actual command to do it, but i don't quite know how to add operators to it, ie -i or -a. I want -i to move one file from... (4 Replies)
Discussion started by: SirJoeh
4 Replies

10. Shell Programming and Scripting

a script to clone a dir tree, & overwrite the dir struct elsewhere?

hi all, i'm looking for a bash or tcsh script that will clone an empty dir tree 'over' another tree ... specifically, i'd like to: (1) specify a src directory (2) list the directory tree/hiearchy beneath that src dir, w/o files -- just the dirs (3) clone that same, empty dir hierarchy to... (2 Replies)
Discussion started by: OpenMacNews
2 Replies
Login or Register to Ask a Question