Moving files that contain spaces...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Moving files that contain spaces...
# 1  
Old 02-15-2011
Moving files that contain spaces...

I have a script that I've written and it's been running fine until someone dropped a file in the source directory that had spaces in it. The script breaks the file name into separate mv commands. I've tried putting " around the $FILE but that didn't help. Anyone who can help me would be greatly appreciated.

Code:
#!/usr/bin/ksh
DATEFOLDER=`date +%m%d%y`
SOURCE=/opt/Lotus/restores/
DESTINATION=/tpcdcatap01h/app1/restores/$DATEFOLDER
mkdir $DESTINATION
chmod 7777 $DESTINATION
for FILE in `ls $SOURCE|grep -i .nsf$`;do
mv $SOURCE$FILE $DESTINATION
done
for FILE in `ls $DESTINATION/|grep -i .nsf$`;do
chown tpcdap1h $DESTINATION/$FILE
done

# 2  
Old 02-15-2011
Code:
mv "$SOURCE$FILE" "$DESTINATION"

chown tpcdap1h "$DESTINATION/$FILE"

# 3  
Old 02-15-2011
It's still not working that way.

Code:
mv: cannot rename /opt/Lotus/restores/test to /tpcdcatap01h/app1/restores/021511/test: 
No such file or directory
+ mv /opt/Lotus/restores/file /tpcdcatap01h/app1/restores/021511
mv: cannot rename /opt/Lotus/restores/file to /tpcdcatap01h/app1/restores/021511/file: 
No such file or directory
+ mv /opt/Lotus/restores/1.nsf /tpcdcatap01h/app1/restores/021511
mv: cannot rename /opt/Lotus/restores/1.nsf to /tpcdcatap01h/app1/restores/021511/1.nsf: 
No such file or directory

# 4  
Old 02-15-2011
I don't see where the embedded space in the file name is....
Looks like either the source or the destination paths are not correct....

Last edited by vgersh99; 02-15-2011 at 03:43 PM..
# 5  
Old 02-15-2011
the filename is "test file 1.nsf"
# 6  
Old 02-15-2011
Try:
Code:
mkdir "$DESTINATION"
chmod 7777 "$DESTINATION" # do you need to do this? this is very insecure..
for FILE in "$SOURCE"*.nsf ;do
  mv "$FILE" "$DESTINATION"
  chown tpcdap1h "$DESTINATION/${FILE##*/}"
done

This User Gave Thanks to Scrutinizer For This Post:
# 7  
Old 02-15-2011
Quote:
Originally Posted by Scrutinizer
Try:
Code:
mkdir "$DESTINATION"
chmod 7777 "$DESTINATION" # do you need to do this? this is very insecure..
for FILE in "$SOURCE"*.nsf ;do
  mv "$FILE" "$DESTINATION"
  chown tpcdap1h "$DESTINATION/${FILE##*/}"
done

Thanks so much. That fixed the problem. The destination directory needs to be open to everyone as all users need to go there to retrieve their restored file. Each file is password protected.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Help with replacing characters without moving the spaces.

Could you please advise what is the best way to edit a file without disrupting the spaces? For example: I have within my file the value below, wherein I wanted to change VALUE2 to VALUETEST. The total characters on the field of VALUE2 is 15 characters. VALUE1|VALUE2<9 spaces>|VALUE3 but... (3 Replies)
Discussion started by: asdfghjkl
3 Replies

2. AIX

Moving Hidden files to normal files

I have a bunch of hidden files in a directory in AIX. I would like to move these hidden files as regular files to another directory. Say i have the following files in directory /x .test~1234~567 .report~5678~123 .find~9876~576 i would like to move them to directory /y as test~1234~567... (10 Replies)
Discussion started by: umesh.narain
10 Replies

3. UNIX for Dummies Questions & Answers

Moving Files to VM

Hi guys, i need to test a script on my RedHat which it's mounted on a VirtualBox (oracle VM). So i need to copy a directory with subdirectories, from a remote host to my VM. I'd like to do that within cmd not with program like Filezilla or something like that. Any idea please? (4 Replies)
Discussion started by: Newer
4 Replies

4. Shell Programming and Scripting

Finding files with wc -l results = 1 then moving the files to another folder

Hi guys can you please help me with a script to find files with one row/1 line of content then move the file to another directory my script below runs but nothing happens to the files....Alternatively Ca I get a script to find the *.csv files with "wc -1" results = 1 then create a list of those... (5 Replies)
Discussion started by: Dj Moi
5 Replies

5. UNIX for Dummies Questions & Answers

Moving Multiple files to destination files

I am running a code like this foreach list ($tmp) mv *_${list}.txt ${chart}_${list}.txt #mv: when moving multiple files, last argument must be a directory mv *_${list}.doc ${chart}_${list}.doc #mv: when moving multiple files, last argument must be a... (3 Replies)
Discussion started by: animesharma
3 Replies

6. Shell Programming and Scripting

moving the files in a.txt files to a different directory

HI All, I am coding a shell script which will pick all the .csv files in a particular directoryand write it in to a .txt file, this .txt file i will use as a source in datastage for processing. now after the processing is done I have to move and archive all the files in the .txt file to a... (5 Replies)
Discussion started by: subhasri_2020
5 Replies

7. Shell Programming and Scripting

moving files with spaces in filename from one directory to another

Hello, When I run following script #!/bin/bash cd ~/directory1 mv `ls -trF | grep -v / | tail -10 ` ~/directory2 works fine with filenames not having any space but runs into issues with filenames that have spaces tried with $file variable still doesnot work. Can someone help me (4 Replies)
Discussion started by: asakhare
4 Replies

8. Shell Programming and Scripting

Moving filenames containing spaces

I want to ftp all the sh files in the directory. Also if any of the file name contains spaces in them, it should be converted to underscores before it is ftped. I wrote the following code below: FILESSH=$(ls /mysh/*.sh) --- FILESH being used here for some other task --- echo "$FILESSH" |... (3 Replies)
Discussion started by: amicon007
3 Replies

9. UNIX for Dummies Questions & Answers

moving files ??

I am using AIX Version 5.1 If I moved a file say using this command but the directory rpt did not exist would this dump the file? I went back to the directory I was moving it from and the file was gone and when I looked in the directory I moved it to of course that directory was not found.... (9 Replies)
Discussion started by: rocker40
9 Replies

10. UNIX for Dummies Questions & Answers

moving only files...

hi.. I want to move a set of files that contain a particular string. I wished to do that with find but i am unable to do that. can anybody give me a good method? :) (12 Replies)
Discussion started by: sskb
12 Replies
Login or Register to Ask a Question