LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 05-26-2011, 02:52 PM   #1
paziulek
Member
 
Registered: Mar 2009
Location: N.C.
Distribution: "gentoo|debian|arch"
Posts: 77

Rep: Reputation: 11
file name - special char


hello,

i managed to create a file with a following name:

-rw-r--r-- 1 root root 548517316 May 26 15:02 -f.h264.sub.avi

since it is "-" in the beginning, I am unable to rename, move etc...
the escape "\", "*" is not having an effect, including single and double quotes:

Quote:
# ls "\-f.h264.sub.avi"
ls: invalid option -- '.'

ls "\-f.h264.sub.avi"
ls \-f.h264.sub.avi
ls *avi
any other ideas?

tx

Last edited by paziulek; 05-26-2011 at 03:15 PM.
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 05-26-2011, 03:01 PM   #2
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,970

Rep: Reputation: 848Reputation: 848Reputation: 848Reputation: 848Reputation: 848Reputation: 848Reputation: 848
Move all other files out of the directory and delete the directory with "rm -r".

Markus

Edit: note that I didn't understand that the OP has an important file which got the wrong name by accident, I thought that the file was created by accident and only had to be removed. So this suggestion may be not very helpful.

Last edited by markush; 05-27-2011 at 01:16 AM.
 
0 members found this post helpful.
Old 05-26-2011, 03:06 PM   #3
paziulek
Member
 
Registered: Mar 2009
Location: N.C.
Distribution: "gentoo|debian|arch"
Posts: 77

Original Poster
Rep: Reputation: 11
Markus,

If the file with "-" in its name would be a collection of your family photos from past 10 years, would you also do it?
I want to fix it and not just get rid of the problem....

Thanks Markus...

Last edited by paziulek; 05-26-2011 at 03:08 PM.
 
Old 05-26-2011, 03:11 PM   #4
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,970

Rep: Reputation: 848Reputation: 848Reputation: 848Reputation: 848Reputation: 848Reputation: 848Reputation: 848
Well, I didn't understand this

Unfortunately I can't manage to create a file with a leading '-' so I can't try it out

what about
Code:
mv *rw-r* file.avi
Markus
 
0 members found this post helpful.
Old 05-26-2011, 03:15 PM   #5
paziulek
Member
 
Registered: Mar 2009
Location: N.C.
Distribution: "gentoo|debian|arch"
Posts: 77

Original Poster
Rep: Reputation: 11
you can not manage to create one and I cannot rename it... sounds similar.
no... *rw-r* has no reason to work...

again, the file name is : -f.h264.sub.avi


Quote:
Originally Posted by markush View Post
Well, I didn't understand this

Unfortunately I can't manage to create a file with a leading '-' so I can't try it out

what about
Code:
mv *rw-r* file.avi
Markus
 
Old 05-26-2011, 03:15 PM   #6
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, Ubuntu, SLES, CentOS
Posts: 1,753

Rep: Reputation: 320Reputation: 320Reputation: 320Reputation: 320
@ Reply

@ paziulek

Go to that directory where the files are located and run the following command:

mv ./-filename newfilename

@ Markush

You can create it by the following command:

touch ./-testfile
 
4 members found this post helpful.
Old 05-26-2011, 03:18 PM   #7
paziulek
Member
 
Registered: Mar 2009
Location: N.C.
Distribution: "gentoo|debian|arch"
Posts: 77

Original Poster
Rep: Reputation: 11
WOW! thanks!!!

the ./ does the trick!! thanks a lot T3RM1NVT0R
 
Old 05-26-2011, 03:20 PM   #8
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, Ubuntu, SLES, CentOS
Posts: 1,753

Rep: Reputation: 320Reputation: 320Reputation: 320Reputation: 320
@ Reply

You're welcome. Glad to hear that it has been resolved.
 
1 members found this post helpful.
Old 05-26-2011, 03:35 PM   #9
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,970

Rep: Reputation: 848Reputation: 848Reputation: 848Reputation: 848Reputation: 848Reputation: 848Reputation: 848
Thanks T3RM1NVT0R, it works, maybe I can use it once.

Markus
 
Old 05-26-2011, 03:38 PM   #10
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux
Posts: 2,850
Blog Entries: 1

Rep: Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897
Code:
touch -- -thisfile.txt
mv -- -thisfile.txt thisfile.txt
This is how I take care of dashed files. The first creates a file, the second renames it.

The double dash will work with a fairly large portion of commands. Tar, rsync, mv, cp, etc. etc.

Good thing to know.

Last edited by szboardstretcher; 05-26-2011 at 03:40 PM.
 
5 members found this post helpful.
Old 05-26-2011, 03:42 PM   #11
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,970

Rep: Reputation: 848Reputation: 848Reputation: 848Reputation: 848Reputation: 848Reputation: 848Reputation: 848
Quote:
Originally Posted by szboardstretcher View Post
Code:
touch -- -thisfile.txt
mv -- -thisfile.txt thisfile.txt
This is how I take care of dashed files. The first creates a file, the second renames it.

The double dash will work with a fairly large portion of commands. Tar, rsync, mv, cp, etc. etc.

Good thing to know.
Well, I found this in the manpage of bash
Code:
 --        A  -- signals the end of options and disables further option processing.  Any arguments after the -- are treated as
                 filenames and arguments.  An argument of - is equivalent to --.
which explains the issue. With -- you tell the shell that the - is not part of an option.

Markus
 
1 members found this post helpful.
Old 05-26-2011, 03:52 PM   #12
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, Ubuntu, SLES, CentOS
Posts: 1,753

Rep: Reputation: 320Reputation: 320Reputation: 320Reputation: 320
@ Reply

@ szboardstretcher

Thank you. I learned one more way!!

@ Markush

Thank you for the explanation on the functioning of --
 
Old 05-26-2011, 04:54 PM   #13
Telengard
Member
 
Registered: Apr 2007
Location: USA
Distribution: Kubuntu 8.04
Posts: 579
Blog Entries: 8

Rep: Reputation: 147Reputation: 147
Lightbulb Can also be done with the perl "rename" script

prename

Code:
foo$ cp -- infile -f.h264.sub.avi
foo$ ls -1
chargen
-f.h264.sub.avi
infile
t
foo$ rename 's/^-//' <<< '-f.h264.sub.avi'
foo$ ls -1
chargen
f.h264.sub.avi
infile
t
 
Old 05-26-2011, 07:33 PM   #14
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713
Note that this actaully has nothing whatsoever to do with bash - the commands themselves interpret the "-".

Quote:
Originally Posted by markush
Move all other files out of the directory and delete the directory with "rm -r".
What on earth were you thinking when you said that!?!?!?!?!?
 
Old 05-27-2011, 01:13 AM   #15
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,970

Rep: Reputation: 848Reputation: 848Reputation: 848Reputation: 848Reputation: 848Reputation: 848Reputation: 848
Quote:
Originally Posted by MTK358 View Post
...What on earth were you thinking when you said that!?!?!?!?!?
Well, I thought the file was created by accident and had to be removed, I did not understand that it was an important file which by accident got the wrong name.

Markus
 
  


Reply

Tags
filename, rename


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Programing Question: Reading file line by line.. then char by char in each line adriumroot Programming 8 05-30-2010 01:55 AM
Problem getting Sed to work with special char inputs. shaselai Programming 8 10-23-2009 01:10 PM
error while printing special char "tcl" khodeir Programming 2 07-05-2009 08:30 AM
gvim - double quote char always replaced with two single quotes in special modes JazzItSelf Linux - Software 4 09-16-2008 11:26 AM
Read First Char from file in C++ ckoniecny Programming 2 09-30-2006 03:43 AM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration