Unix/Linux Go Back    


UNIX for Dummies Questions & Answers This forum is closed for new posts. Please post beginner questions to learn unix and learn linux in this forum UNIX for Beginners Questions & Answers

ignoring a dash in file name

UNIX for Dummies Questions & Answers


 
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 08-04-2008
LumpSum LumpSum is offline
Registered User
 
Join Date: Aug 2008
Last Activity: 5 August 2008, 6:14 AM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
ignoring a dash in file name

so i have a simple file called -x and i need it renamed to x

now i dont understand why when using the most basic methods, only the code
Code:
mv ./-x x

changes the file name while using any other type of escape characters around the dash, such as single/double quotations or backslash, doesnt.

anyone? im completely new to unix and this seems out of the ordinary. im sure there is a very obvious answer to this

shouldnt things like mv /-/x x or mv "-"x x work?
Sponsored Links
    #2  
Old Unix and Linux 08-04-2008
Yogesh Sawant's Unix or Linux Image
Yogesh Sawant Yogesh Sawant is offline Forum Advisor  
Full Time Dad
 
Join Date: Sep 2006
Last Activity: 12 June 2017, 2:21 AM EDT
Location: Rossem, Tazenda
Posts: 1,213
Thanks: 7
Thanked 18 Times in 17 Posts
mv -x x passes option -x to command mv. that is not what you are intended to do
mv ./-x x does the job - since you mentioned relative path, which solved the "passing option to the command" problem
Sponsored Links
    #3  
Old Unix and Linux 08-04-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
 
Join Date: Mar 2008
Last Activity: 28 March 2011, 6:41 AM EDT
Location: /there/is/only/bin/sh
Posts: 3,653
Thanks: 0
Thanked 11 Times in 9 Posts
Quoting is to prevent interpretation by the shell, whereas option processing is handled by the program itself. The shell strips and discards quotes, so mv doesn't even see a difference between "-"x and -x (and /-/x is, frankly, neither here nor there).
    #4  
Old Unix and Linux 08-04-2008
LumpSum LumpSum is offline
Registered User
 
Join Date: Aug 2008
Last Activity: 5 August 2008, 6:14 AM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
i see, thank both of you for clearing this up for me, it is very much appreciated

im sure ill run into you lot more as i go on and on with unix. im the definition of noob at the moment
Sponsored Links
    #5  
Old Unix and Linux 08-04-2008
broli's Unix or Linux Image
broli broli is offline
Registered User
 
Join Date: Dec 2007
Last Activity: 23 July 2014, 5:32 PM EDT
Location: Argentina
Posts: 219
Thanks: 0
Thanked 0 Times in 0 Posts
and what about using \ ?

mv \-x x <---
Sponsored Links
    #6  
Old Unix and Linux 08-04-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
 
Join Date: Mar 2008
Last Activity: 28 March 2011, 6:41 AM EDT
Location: /there/is/only/bin/sh
Posts: 3,653
Thanks: 0
Thanked 11 Times in 9 Posts
broli: it's the same as quoting; it only prevents interpretation by the shell.
Sponsored Links
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Extracting string before first dash in a file name bashnewbee Shell Programming and Scripting 2 07-11-2011 12:10 PM
ignoring lines in a file thelakbe Shell Programming and Scripting 2 10-28-2010 03:17 AM
ignoring blank line in a file ali560045 Shell Programming and Scripting 4 11-12-2008 04:23 AM
How to remove a file with a leading dash '-' in it's name? GSalisbury UNIX for Advanced & Expert Users 3 05-05-2003 11:28 AM



All times are GMT -4. The time now is 06:35 AM.