How to remove/rename file which contains special character eg. “-x” using command line [duplicate]
up vote
0
down vote
favorite
Possible Duplicate:
What does “--” (double-dash) mean?
Can anybody explain me below things
i have file named "-xyz".
if i try to remove or move that file using command line , it's unable to move.
i tried below things :
[rahul@srv100 ~]# ls -lrt -- "-xyz"
-rw-r--r-- 1 rahul rahul 0 Dec 19 08:06 -xyz
[rahul@srv100 ~]# mv "-xyz" xyz
mv: invalid option -- x
Try `mv --help' for more information.
[rahul@srv100 ~]# mv -xyz xyz
mv: invalid option -- x
Try `mv --help' for more information.
[rahul@srv100 ~]# mv -xyz xyz
mv: invalid option -- x
Try `mv --help' for more information.
[rahul@srv100 ~]# mv '-xyz' xyz
mv: invalid option -- x
Try `mv --help' for more information.
finally i rename that file using winscp, and after trying multiple ways i got one option and it's working.
mv -- '-xyz' xyz
Wish the help of "--", i created file/directory as below
mkdir -- --abc
touch -- -xyz
So my Question is what is this "--" in bash ?
Please explain.
bash
marked as duplicate by Stéphane Chazelas, manatwork, Renan, Ulrich Dangel, George M Dec 21 '12 at 12:46
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
up vote
0
down vote
favorite
Possible Duplicate:
What does “--” (double-dash) mean?
Can anybody explain me below things
i have file named "-xyz".
if i try to remove or move that file using command line , it's unable to move.
i tried below things :
[rahul@srv100 ~]# ls -lrt -- "-xyz"
-rw-r--r-- 1 rahul rahul 0 Dec 19 08:06 -xyz
[rahul@srv100 ~]# mv "-xyz" xyz
mv: invalid option -- x
Try `mv --help' for more information.
[rahul@srv100 ~]# mv -xyz xyz
mv: invalid option -- x
Try `mv --help' for more information.
[rahul@srv100 ~]# mv -xyz xyz
mv: invalid option -- x
Try `mv --help' for more information.
[rahul@srv100 ~]# mv '-xyz' xyz
mv: invalid option -- x
Try `mv --help' for more information.
finally i rename that file using winscp, and after trying multiple ways i got one option and it's working.
mv -- '-xyz' xyz
Wish the help of "--", i created file/directory as below
mkdir -- --abc
touch -- -xyz
So my Question is what is this "--" in bash ?
Please explain.
bash
marked as duplicate by Stéphane Chazelas, manatwork, Renan, Ulrich Dangel, George M Dec 21 '12 at 12:46
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
For info,--
has nothing to do with bash. In your case, you can also use./-xyz
.
– gniourf_gniourf
Dec 21 '12 at 9:56
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Possible Duplicate:
What does “--” (double-dash) mean?
Can anybody explain me below things
i have file named "-xyz".
if i try to remove or move that file using command line , it's unable to move.
i tried below things :
[rahul@srv100 ~]# ls -lrt -- "-xyz"
-rw-r--r-- 1 rahul rahul 0 Dec 19 08:06 -xyz
[rahul@srv100 ~]# mv "-xyz" xyz
mv: invalid option -- x
Try `mv --help' for more information.
[rahul@srv100 ~]# mv -xyz xyz
mv: invalid option -- x
Try `mv --help' for more information.
[rahul@srv100 ~]# mv -xyz xyz
mv: invalid option -- x
Try `mv --help' for more information.
[rahul@srv100 ~]# mv '-xyz' xyz
mv: invalid option -- x
Try `mv --help' for more information.
finally i rename that file using winscp, and after trying multiple ways i got one option and it's working.
mv -- '-xyz' xyz
Wish the help of "--", i created file/directory as below
mkdir -- --abc
touch -- -xyz
So my Question is what is this "--" in bash ?
Please explain.
bash
Possible Duplicate:
What does “--” (double-dash) mean?
Can anybody explain me below things
i have file named "-xyz".
if i try to remove or move that file using command line , it's unable to move.
i tried below things :
[rahul@srv100 ~]# ls -lrt -- "-xyz"
-rw-r--r-- 1 rahul rahul 0 Dec 19 08:06 -xyz
[rahul@srv100 ~]# mv "-xyz" xyz
mv: invalid option -- x
Try `mv --help' for more information.
[rahul@srv100 ~]# mv -xyz xyz
mv: invalid option -- x
Try `mv --help' for more information.
[rahul@srv100 ~]# mv -xyz xyz
mv: invalid option -- x
Try `mv --help' for more information.
[rahul@srv100 ~]# mv '-xyz' xyz
mv: invalid option -- x
Try `mv --help' for more information.
finally i rename that file using winscp, and after trying multiple ways i got one option and it's working.
mv -- '-xyz' xyz
Wish the help of "--", i created file/directory as below
mkdir -- --abc
touch -- -xyz
So my Question is what is this "--" in bash ?
Please explain.
bash
bash
edited Apr 13 '17 at 12:36
Community♦
1
1
asked Dec 21 '12 at 9:12
Rahul Patil
14.7k186082
14.7k186082
marked as duplicate by Stéphane Chazelas, manatwork, Renan, Ulrich Dangel, George M Dec 21 '12 at 12:46
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Stéphane Chazelas, manatwork, Renan, Ulrich Dangel, George M Dec 21 '12 at 12:46
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
For info,--
has nothing to do with bash. In your case, you can also use./-xyz
.
– gniourf_gniourf
Dec 21 '12 at 9:56
add a comment |
For info,--
has nothing to do with bash. In your case, you can also use./-xyz
.
– gniourf_gniourf
Dec 21 '12 at 9:56
For info,
--
has nothing to do with bash. In your case, you can also use ./-xyz
.– gniourf_gniourf
Dec 21 '12 at 9:56
For info,
--
has nothing to do with bash. In your case, you can also use ./-xyz
.– gniourf_gniourf
Dec 21 '12 at 9:56
add a comment |
3 Answers
3
active
oldest
votes
up vote
1
down vote
accepted
As others have already mentioned --
is used to delimit options from arguments. If you execute a program and specify any arguments the program has no way of distinguishing if the specified arguments should be interpreted as a command line option or an argument. That is the reason why a prefix for options was introduced -
/ --
or /
on windows, i.e. -rf
,--help
or /?
As you may have files beginning with a such an prefix or any other special name which could be interpreted --
was introduced to delimit command line options from normal arguments, i.e. every argument after --
will not be treated as a command line option but just as a argument. getopt (1)
, a standard solution to parse arguments, for example supports the --
delimiter which means any program using getopt
automatically supports the --
delimiter.
If you want to work with files starting with special characters like -
you can also just add ./
in front of them as they now don't start with -
so they won't be interpreted as command line option, for your example it would be mkdir ./--abc
add a comment |
up vote
1
down vote
This is used to tell the command that after that point no more command options are accepted.
So
rm -- -abc
means that it will ignore the - from the abc.
for more information you can refer to:
http://tldp.org/LDP/abs/html/special-chars.html
2
Not really ignore the-
from the-abc
. Instead, it will not consider-abc
to be an option, since after the--
, no more options are interpreted, only arguments.
– gniourf_gniourf
Dec 21 '12 at 9:58
add a comment |
up vote
1
down vote
It's an indicator to the individual commands to stop interpreting further command line arguments as options.
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
As others have already mentioned --
is used to delimit options from arguments. If you execute a program and specify any arguments the program has no way of distinguishing if the specified arguments should be interpreted as a command line option or an argument. That is the reason why a prefix for options was introduced -
/ --
or /
on windows, i.e. -rf
,--help
or /?
As you may have files beginning with a such an prefix or any other special name which could be interpreted --
was introduced to delimit command line options from normal arguments, i.e. every argument after --
will not be treated as a command line option but just as a argument. getopt (1)
, a standard solution to parse arguments, for example supports the --
delimiter which means any program using getopt
automatically supports the --
delimiter.
If you want to work with files starting with special characters like -
you can also just add ./
in front of them as they now don't start with -
so they won't be interpreted as command line option, for your example it would be mkdir ./--abc
add a comment |
up vote
1
down vote
accepted
As others have already mentioned --
is used to delimit options from arguments. If you execute a program and specify any arguments the program has no way of distinguishing if the specified arguments should be interpreted as a command line option or an argument. That is the reason why a prefix for options was introduced -
/ --
or /
on windows, i.e. -rf
,--help
or /?
As you may have files beginning with a such an prefix or any other special name which could be interpreted --
was introduced to delimit command line options from normal arguments, i.e. every argument after --
will not be treated as a command line option but just as a argument. getopt (1)
, a standard solution to parse arguments, for example supports the --
delimiter which means any program using getopt
automatically supports the --
delimiter.
If you want to work with files starting with special characters like -
you can also just add ./
in front of them as they now don't start with -
so they won't be interpreted as command line option, for your example it would be mkdir ./--abc
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
As others have already mentioned --
is used to delimit options from arguments. If you execute a program and specify any arguments the program has no way of distinguishing if the specified arguments should be interpreted as a command line option or an argument. That is the reason why a prefix for options was introduced -
/ --
or /
on windows, i.e. -rf
,--help
or /?
As you may have files beginning with a such an prefix or any other special name which could be interpreted --
was introduced to delimit command line options from normal arguments, i.e. every argument after --
will not be treated as a command line option but just as a argument. getopt (1)
, a standard solution to parse arguments, for example supports the --
delimiter which means any program using getopt
automatically supports the --
delimiter.
If you want to work with files starting with special characters like -
you can also just add ./
in front of them as they now don't start with -
so they won't be interpreted as command line option, for your example it would be mkdir ./--abc
As others have already mentioned --
is used to delimit options from arguments. If you execute a program and specify any arguments the program has no way of distinguishing if the specified arguments should be interpreted as a command line option or an argument. That is the reason why a prefix for options was introduced -
/ --
or /
on windows, i.e. -rf
,--help
or /?
As you may have files beginning with a such an prefix or any other special name which could be interpreted --
was introduced to delimit command line options from normal arguments, i.e. every argument after --
will not be treated as a command line option but just as a argument. getopt (1)
, a standard solution to parse arguments, for example supports the --
delimiter which means any program using getopt
automatically supports the --
delimiter.
If you want to work with files starting with special characters like -
you can also just add ./
in front of them as they now don't start with -
so they won't be interpreted as command line option, for your example it would be mkdir ./--abc
answered Dec 21 '12 at 12:26
Ulrich Dangel
20.2k25771
20.2k25771
add a comment |
add a comment |
up vote
1
down vote
This is used to tell the command that after that point no more command options are accepted.
So
rm -- -abc
means that it will ignore the - from the abc.
for more information you can refer to:
http://tldp.org/LDP/abs/html/special-chars.html
2
Not really ignore the-
from the-abc
. Instead, it will not consider-abc
to be an option, since after the--
, no more options are interpreted, only arguments.
– gniourf_gniourf
Dec 21 '12 at 9:58
add a comment |
up vote
1
down vote
This is used to tell the command that after that point no more command options are accepted.
So
rm -- -abc
means that it will ignore the - from the abc.
for more information you can refer to:
http://tldp.org/LDP/abs/html/special-chars.html
2
Not really ignore the-
from the-abc
. Instead, it will not consider-abc
to be an option, since after the--
, no more options are interpreted, only arguments.
– gniourf_gniourf
Dec 21 '12 at 9:58
add a comment |
up vote
1
down vote
up vote
1
down vote
This is used to tell the command that after that point no more command options are accepted.
So
rm -- -abc
means that it will ignore the - from the abc.
for more information you can refer to:
http://tldp.org/LDP/abs/html/special-chars.html
This is used to tell the command that after that point no more command options are accepted.
So
rm -- -abc
means that it will ignore the - from the abc.
for more information you can refer to:
http://tldp.org/LDP/abs/html/special-chars.html
answered Dec 21 '12 at 9:20
BitsOfNix
4,09321631
4,09321631
2
Not really ignore the-
from the-abc
. Instead, it will not consider-abc
to be an option, since after the--
, no more options are interpreted, only arguments.
– gniourf_gniourf
Dec 21 '12 at 9:58
add a comment |
2
Not really ignore the-
from the-abc
. Instead, it will not consider-abc
to be an option, since after the--
, no more options are interpreted, only arguments.
– gniourf_gniourf
Dec 21 '12 at 9:58
2
2
Not really ignore the
-
from the -abc
. Instead, it will not consider -abc
to be an option, since after the --
, no more options are interpreted, only arguments.– gniourf_gniourf
Dec 21 '12 at 9:58
Not really ignore the
-
from the -abc
. Instead, it will not consider -abc
to be an option, since after the --
, no more options are interpreted, only arguments.– gniourf_gniourf
Dec 21 '12 at 9:58
add a comment |
up vote
1
down vote
It's an indicator to the individual commands to stop interpreting further command line arguments as options.
add a comment |
up vote
1
down vote
It's an indicator to the individual commands to stop interpreting further command line arguments as options.
add a comment |
up vote
1
down vote
up vote
1
down vote
It's an indicator to the individual commands to stop interpreting further command line arguments as options.
It's an indicator to the individual commands to stop interpreting further command line arguments as options.
edited Dec 21 '12 at 12:11
Renan
14.3k65376
14.3k65376
answered Dec 21 '12 at 9:20
Anil Tallapragada
112
112
add a comment |
add a comment |
For info,
--
has nothing to do with bash. In your case, you can also use./-xyz
.– gniourf_gniourf
Dec 21 '12 at 9:56