confused in australia


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting confused in australia
# 1  
Old 01-18-2006
confused in australia

hi!

i have a lot of files (800+) (in windows format - i.e. they have spaces in the filename) that i need to copy to disk... if i write a for loop to ls the files and copy it fails as the file it trys to read is just the 1st part of the file (which of course doesnt exist)...

i dont want to add a '\ ' and do each one individually - can anyone suggest a quick workaround??

thanks a lot !!
Richard
# 2  
Old 01-18-2006
Use double quotes around the file name.

Something like this...

ls -l "a b c"
# 3  
Old 01-18-2006
Quote:
Originally Posted by vino
Use double quotes around the file name.

Something like this...

ls -l "a b c"

Thanks Vino... i was hoping for something i could script, rather than copy them individually...
cheers anyway
# 4  
Old 01-18-2006
Many ways of doing this, here's one

Code:
cd /where/my/files/are
ls | while IFS=; read file; do
   cp ${file} /some/destination
done

That'll keep the spaces in the filenames. If you don't want the spaces, use tr or sed to change the spaces to underscores.

Code:
cd /where/my/files/are
ls | while read file; do
   cp "${file}" /some/destination/`echo "${file}" | tr ' ' '_'`
done

Edit: Added alternate method to rename files.

Cheers
ZB

Last edited by zazzybob; 01-18-2006 at 10:59 PM..
# 5  
Old 01-19-2006
Quote:
Originally Posted by zazzybob
Many ways of doing this, here's one

Code:
cd /where/my/files/are
ls | while IFS=; read file; do
   cp ${file} /some/destination
done

That'll keep the spaces in the filenames. If you don't want the spaces, use tr or sed to change the spaces to underscores.

Code:
cd /where/my/files/are
ls | while read file; do
   cp "${file}" /some/destination/`echo "${file}" | tr ' ' '_'`
done

Edit: Added alternate method to rename files.

Cheers
ZB

top man !!
Login or Register to Ask a Question

Previous Thread | Next Thread

3 More Discussions You Might Find Interesting

1. Ubuntu

New and Confused

Hello, I am having a problem with Dual Booting Windows XP Pro and Linux Mint. I have Three Hard Drives, One Hard Drive has Linux Mint Loaded on it. When it is hooked up to the computer by itself it works great. This is an IDE Drive. The Second Hard Drive has Window XP Pro loaded on it.... (3 Replies)
Discussion started by: Forextrading
3 Replies

2. AIX

Australia NSW DST

Hello. Our application is running on AIX box located in NSW , Australia. As DST starts on Oct 28th - Do you know IF AIX boxes have auto updates of day light saving times? IF not , how to do it? IF yes, where can I verify it? Thank you! (3 Replies)
Discussion started by: panchpan
3 Replies

3. Shell Programming and Scripting

DST Change For Australia

Hello , We are investigating an issue from a customer from Western Australia related to DST change on 25 th March. The customer in Australia has the below settings for Time Zone. The System is Solaris 9. TZ=Australia/NSW CMASK=022 We are trying to reproduce the problem in our local... (1 Reply)
Discussion started by: Mohammed
1 Replies
Login or Register to Ask a Question