LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-08-2012, 02:29 AM   #1
pradeepdee6
Member
 
Registered: Jul 2012
Posts: 30

Rep: Reputation: Disabled
Move file names with space to other directory with different file name with space


Hi,

I want to move the files from one directory to another directory.

Condition i have is: file names are with spaces. Ex: "my file" , "your file".

I used the below command.
mv $current_dir/my\ file $remote_dir/their\ file
this moves "my file" to $remote_dir/ "their file"

But the problem im facing is i ll not beknowint the name of the file. File name will be stored in a variable.

So when i used variable, the space in the file name is creating problem.


Please help me how to achieve this move.

Thanks in advance
 
Old 08-08-2012, 02:33 AM   #2
pradeepdee6
Member
 
Registered: Jul 2012
Posts: 30

Original Poster
Rep: Reputation: Disabled
Hi,

I want to move the files from one directory to another directory.

Condition i have is: file names are with spaces. Ex: "my file" , "your file".

I used the below command.
Quote:
Originally Posted by pradeepdee6 View Post
mv $current_dir/my\ file $remote_dir/their\ file
this moves "my file" to $remote_dir/ "their file"

But the problem im facing is i will not be knowing the name of the file. File name will be stored in a variable.

So when i used variable, the space in the file name is creating problem.

mv $current_dir/$varaible $remote_dir/ ## it ll be interpretted as mv $current_dir/my file $remote_dir/

Please help me how to achieve this move.

Thanks in advance
 
Old 08-08-2012, 02:50 AM   #3
segmentation_fault
Member
 
Registered: Sep 2008
Location: Ioannina, Greece
Distribution: Gentoo
Posts: 332

Rep: Reputation: 55
I'm not good at bash but have you tried double-quoting the var? Eg
Code:
mv $currentdir/"$variable" $remotedir/
 
Old 08-08-2012, 02:59 AM   #4
pradeepdee6
Member
 
Registered: Jul 2012
Posts: 30

Original Poster
Rep: Reputation: Disabled
Thanku so much.

I have used it. But I dont want the same file name in destination.
I want to rename it with a file name having space again.

Quote:
Ex: file name in source : 123abcd.xxx xy
I want to rename in destination as : abc123d.xxx xy ( means the destination file name should have space )
To achive this i ll have to enter the destination file name manually.
But im running a script and it involves many files. so it wont be fesible.

Please help me with ideas to achieve this.

Thanks
 
Old 08-08-2012, 03:09 AM   #5
segmentation_fault
Member
 
Registered: Sep 2008
Location: Ioannina, Greece
Distribution: Gentoo
Posts: 332

Rep: Reputation: 55
Then you need to do
Code:
mv $currentdir/"$filename" $newdir/"$newfilename"
and find a way to update newfilename for every file. Spaces have nothinfg to do with this.
 
1 members found this post helpful.
Old 08-08-2012, 03:33 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,011

Rep: Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194
Also, no need to quote just a single variable, if quoting, quote the whole piece of text, like:
Code:
mv "$currentdir/$filename" "$newdir/$newfilename"
 
2 members found this post helpful.
Old 08-08-2012, 06:52 AM   #7
pradeepdee6
Member
 
Registered: Jul 2012
Posts: 30

Original Poster
Rep: Reputation: Disabled
Thank u so much all the answers.

This really works correctly.

But im trying to work it out in XML and the out put of XML is being feeded to unix box.

Quote:
Ex: Out put of XML shuld generate -> mv "$currentdir/$filename" "$newdir/$newfilename"
In XML format initializing a variable is starting with a ", so when i use " in move command, it is interpretted as the ending brace.
Quote:
<assign to "variable"> from="mv "$currentdir/$filename" "$newdir/$newfilename" " </>
So im facing problem in generating the mv "$currentdir/$filename" "$newdir/$newfilename". (used &quot; but didnt serve the purpose)

So is their any other way to interpret the the file name with space??

I want to try from Unix end. If i can get a way in unix then can generate XML out put in that format and input to unix box
XML Code
Thanks,
 
Old 08-08-2012, 07:02 AM   #8
segmentation_fault
Member
 
Registered: Sep 2008
Location: Ioannina, Greece
Distribution: Gentoo
Posts: 332

Rep: Reputation: 55
Please explain what you are EXACTLY trying to do. The original problem (as I understand it) was resolved. Now you need to escape the " in an xml tag. But then again, maybe another problem will rise. Start a new thread giving as much information as possible about your initial goal. Then describe what have you tried, what worked and what didn't.
 
Old 08-08-2012, 07:27 AM   #9
pradeepdee6
Member
 
Registered: Jul 2012
Posts: 30

Original Poster
Rep: Reputation: Disabled
Hi,

I was trying it out manualy and mv "$currentdir/$filename" "$newdir/$newfilename" works fine.

But what im acctually supposed to do is i have to generate the mv "$currentdir/$filename" "$newdir/$newfilename" command through a XML code.
Quote:
<assign to "variable"> from="mv "$currentdir/$filename" "$newdir/$newfilename" " <\>
The variable is given as input to Unix box. Problem is XML code is interpreting the quote(<assign to "variable"> from="mv ") as start and immediate next quote as end.

Im not able to use quotes efficiently.

So Im trying out to change the format of move command.

Can we use mv command to move files with name having spaces(with out using quotes ).
Is ther any way in Unix.

Please help me.

Thanks,
 
Old 08-08-2012, 09:19 AM   #10
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,753

Rep: Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983
Quote:
Originally Posted by pradeepdee6 View Post
Hi,
I was trying it out manualy and mv "$currentdir/$filename" "$newdir/$newfilename" works fine. But what im acctually supposed to do is i have to generate the mv "$currentdir/$filename" "$newdir/$newfilename" command through a XML code.

The variable is given as input to Unix box. Problem is XML code is interpreting the quote(<assign to "variable"> from="mv ") as start and immediate next quote as end.

Im not able to use quotes efficiently. So Im trying out to change the format of move command. Can we use mv command to move files with name having spaces(with out using quotes ).
Pradeepdee6, you don't ever seem to post any of what you've done/tried, despite folks asking you to. You only seem to want us to do your homework/work for you:
https://www.linuxquestions.org/quest...ch-4175417736/
https://www.linuxquestions.org/quest...in-4175417783/

Post ALL the code you've written to do your specified task, and where you're stuck. There are many solutions to this...Perl has a pretty robust XML parsing library that's fairly easy to use. This has also been addressed on this site, and a Google search for "linux bash parse xml" pulls up answers too:
https://www.linuxquestions.org/quest...se-xml-798863/
http://stackoverflow.com/questions/1...se-xml-snippet

Have you done/tried ANYTHING? We are always happy to help, but you are going to have to show what effort you've put in to solving your problems, too.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get file info of a directory in linux kernel space? bitzsk Linux - Kernel 0 06-03-2009 12:20 AM
how to handle file names with space characters in a shell script? Sammy_G Programming 14 04-27-2009 10:40 AM
space in file names man_linux Linux - General 3 09-20-2006 06:32 PM
script #!/bin/bash, problem with space in file names existent Linux - General 3 06-17-2004 08:13 AM
When I try to move a file to a dir it says No Space Left on Device. Help KrazyKid Linux - Software 1 06-16-2002 09:06 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration