cp && rm command, rm: <file> not removed. No such file or directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting cp && rm command, rm: <file> not removed. No such file or directory
# 1  
Old 01-19-2009
cp && rm command, rm: <file> not removed. No such file or directory

Hi,

I am running this is korn shell

Code:
cp $source/$fname $dest/dir && rm $source/$fname

This was returned:
Code:
rm: /dir/file not removed: No such file or directory

The file could be found in the $dest directory which meant the cp was success.

The above code is used in a for loop to move many files


This script could run properly in another box with the same solaris OS but could not work properly on this box.

Is there something wrong with the command or is there something I missed out? Please help
# 2  
Old 01-19-2009
Code:
Space characters in the filenames?

cp "$source/$fname" "$dest/dir" && rm "$source/$fname"

# 3  
Old 01-19-2009
Quote:
Originally Posted by methyl
Code:
Space characters in the filenames?

cp "$source/$fname" "$dest/dir" && rm "$source/$fname"


no there are no space characters in the filenames...
# 4  
Old 01-19-2009
Code looks ok..

If you don't mind me asking, did you check if the file to be cp'd and rm's really is existing?
# 5  
Old 01-19-2009
Please post the full script.
Do you have any filenames with funny characters e.g. asterisk?
# 6  
Old 01-19-2009
Quote:
Originally Posted by methyl
Please post the full script.
Do you have any filenames with funny characters e.g. asterisk?
The for loop is using

Code:
 cd $source
for fname in `ls`
do
cp $source/$fname $dest/dir && rm $source/$fname
done

There are no funny characters in the filenames..

Last edited by Leion; 01-20-2009 at 01:49 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compressing & removing files in a directory & subdirectory

Hi, I want a simple line of code that will compress files within a directory specified (parameter) and its subdirectories and also i want to remove files which are exactly 365 days old from the sysdate after this compression. Please help. Thanks, JD (8 Replies)
Discussion started by: Jesshelle David
8 Replies

2. Shell Programming and Scripting

File Move & Sort by Name - Kick out Bad File Names & More

I have a dilemma, we have users who are copying files to "directory 1." These images have file names which include the year it was taken. I need to put together a script to do the following: Examine the file naming convention, ensuring it's the proper format (e.g. test-1983_filename-123.tif)... (8 Replies)
Discussion started by: Nvizn
8 Replies

3. Shell Programming and Scripting

Need Script to ZIP/SAVE & then DELETE Log file & send a mail conformation for any error

ENVIROMENT Linux: RHEL 6.4 Log Path: /usr/iplanet/servers/https-company/logs Log Format: user.log.03-15-2015 I have log4j log rotation enabled rotating files on a daily basis. The rotated logs are NOT compressed & are taking up too much space. I need a script that will run daily that... (1 Reply)
Discussion started by: admin_job_admin
1 Replies

4. Shell Programming and Scripting

directory structure & file permisson comparison

Hi - I want to compare permissions of the directory structure and files beneath it with permissions one week back on same directory structure and files beneath it. if any changes to permissions of any file or directory permissions send an email. I am not sure how to list the permissions of all... (1 Reply)
Discussion started by: oraclermanpt
1 Replies

5. Shell Programming and Scripting

Sort a the file & refine data column & row format

cat file1.txt field1 "user1": field2:"data-cde" field3:"data-pqr" field4:"data-mno" field1 "user1": field2:"data-dcb" field3:"data-mxz" field4:"data-zul" field1 "user2": field2:"data-cqz" field3:"data-xoq" field4:"data-pos" Now i need to have the date like below. i have just... (7 Replies)
Discussion started by: ckaramsetty
7 Replies

6. Shell Programming and Scripting

replace & with &amp; xml file

Hello All I have a xml file with many sets of records like this <mytag>mydata</mytag> <tag2>data&</tag2> also same file can be like this <mytag>mydata</mytag> <tag2>data&</tag2> <tag3>data2&amp;data3</tag3> Now i can grep & and replace with &amp; for whole file but it will replace all... (4 Replies)
Discussion started by: lokaish23
4 Replies

7. UNIX for Dummies Questions & Answers

How to compare 2 files & get specific value & replace it in other file.

Hiiii Friends I have 2 files with huge data. I want to compare this 2 files & if they hav same set of vales in specific rows & columns i need to get that value from one file & replace it in other. For example: I have few set data of both files here: a.dat: PDE-W 2009 12 16 5 29 11.11 ... (10 Replies)
Discussion started by: reva
10 Replies

8. UNIX for Dummies Questions & Answers

Search for & edit rows & columns in data file and pipe

Dear unix gurus, I have a data file with header information about a subject and also 3 columns of n rows of data on various items he owns. The data file looks something like this: adam peter blah blah blah blah blah blah car 01 30 200 02 31 400 03 57 121 .. .. .. .. .. .. n y... (8 Replies)
Discussion started by: tintin72
8 Replies

9. Shell Programming and Scripting

How do I search first&second string & copy all content between them to other file?

Hi All, How do I search first string & second string and copy all content between them from one file to another file? Please help me.. Thanks In Advance. Regards, Pankaj (12 Replies)
Discussion started by: pankajp
12 Replies

10. UNIX for Dummies Questions & Answers

how to list a directory & file

Good day every body, Iv've been given a list of files and directory requested by the Auditor's. My problem is how do i list the file with the permission given and also save the file into text.file so that i can passed the result/oucome to them?? Thanks alot guys!! (2 Replies)
Discussion started by: gagasan_makmur
2 Replies
Login or Register to Ask a Question