How do I use shell commands with a directory that contains '-' like '-78059735'?
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I have an external program that generates directories with strings that are negative integers. I am trying to use basic shell commands including cd
and ls
with this directory, for example:
cd -78059735
Understandably, this fails because this looks like command line options starting with -7.
-bash: cd: -7: invalid option
Similarly, these variations also fail:
cd "-78059735"
cd "-78059735"
cd '-78059735'
cd '-78059735'
cd -78059735
How do I interact with this troublesome directory through the shell?
bash shell escape-characters
add a comment |Â
up vote
1
down vote
favorite
I have an external program that generates directories with strings that are negative integers. I am trying to use basic shell commands including cd
and ls
with this directory, for example:
cd -78059735
Understandably, this fails because this looks like command line options starting with -7.
-bash: cd: -7: invalid option
Similarly, these variations also fail:
cd "-78059735"
cd "-78059735"
cd '-78059735'
cd '-78059735'
cd -78059735
How do I interact with this troublesome directory through the shell?
bash shell escape-characters
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have an external program that generates directories with strings that are negative integers. I am trying to use basic shell commands including cd
and ls
with this directory, for example:
cd -78059735
Understandably, this fails because this looks like command line options starting with -7.
-bash: cd: -7: invalid option
Similarly, these variations also fail:
cd "-78059735"
cd "-78059735"
cd '-78059735'
cd '-78059735'
cd -78059735
How do I interact with this troublesome directory through the shell?
bash shell escape-characters
I have an external program that generates directories with strings that are negative integers. I am trying to use basic shell commands including cd
and ls
with this directory, for example:
cd -78059735
Understandably, this fails because this looks like command line options starting with -7.
-bash: cd: -7: invalid option
Similarly, these variations also fail:
cd "-78059735"
cd "-78059735"
cd '-78059735'
cd '-78059735'
cd -78059735
How do I interact with this troublesome directory through the shell?
bash shell escape-characters
bash shell escape-characters
asked 41 mins ago
mattm
1114
1114
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
3
down vote
It is because the command cd
treats the character followed by -
as valid option flag for it to work. Since 7
is not a valid one for cd
it is failing with the error you are seeing.
In such cases you can specify end of command line options by doing a double dash before the command name --
as below. The below command implies that the command line options for cd
are complete and there are no other flags expected after --
cd -- -78059735/
You can even have other flags provided before --
which would work just fine. The below command for mkdir
which takes an option -p
to create a directory if it does not exist before works just fine with a string having -
, provided you give an end of command line options flag right after -p
mkdir -p -- /tmp/-78059735
ls -d /tmp/*
/tmp/-78059735
rm
command to delete a directory also works just fine as below
rm -vrf -- /tmp/-78059735
removed directory '/tmp/-78059735'
add a comment |Â
up vote
2
down vote
cd ./-78059735
ls ./-78059735
It works for me.
New contributor
Gounou is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
It is because the command cd
treats the character followed by -
as valid option flag for it to work. Since 7
is not a valid one for cd
it is failing with the error you are seeing.
In such cases you can specify end of command line options by doing a double dash before the command name --
as below. The below command implies that the command line options for cd
are complete and there are no other flags expected after --
cd -- -78059735/
You can even have other flags provided before --
which would work just fine. The below command for mkdir
which takes an option -p
to create a directory if it does not exist before works just fine with a string having -
, provided you give an end of command line options flag right after -p
mkdir -p -- /tmp/-78059735
ls -d /tmp/*
/tmp/-78059735
rm
command to delete a directory also works just fine as below
rm -vrf -- /tmp/-78059735
removed directory '/tmp/-78059735'
add a comment |Â
up vote
3
down vote
It is because the command cd
treats the character followed by -
as valid option flag for it to work. Since 7
is not a valid one for cd
it is failing with the error you are seeing.
In such cases you can specify end of command line options by doing a double dash before the command name --
as below. The below command implies that the command line options for cd
are complete and there are no other flags expected after --
cd -- -78059735/
You can even have other flags provided before --
which would work just fine. The below command for mkdir
which takes an option -p
to create a directory if it does not exist before works just fine with a string having -
, provided you give an end of command line options flag right after -p
mkdir -p -- /tmp/-78059735
ls -d /tmp/*
/tmp/-78059735
rm
command to delete a directory also works just fine as below
rm -vrf -- /tmp/-78059735
removed directory '/tmp/-78059735'
add a comment |Â
up vote
3
down vote
up vote
3
down vote
It is because the command cd
treats the character followed by -
as valid option flag for it to work. Since 7
is not a valid one for cd
it is failing with the error you are seeing.
In such cases you can specify end of command line options by doing a double dash before the command name --
as below. The below command implies that the command line options for cd
are complete and there are no other flags expected after --
cd -- -78059735/
You can even have other flags provided before --
which would work just fine. The below command for mkdir
which takes an option -p
to create a directory if it does not exist before works just fine with a string having -
, provided you give an end of command line options flag right after -p
mkdir -p -- /tmp/-78059735
ls -d /tmp/*
/tmp/-78059735
rm
command to delete a directory also works just fine as below
rm -vrf -- /tmp/-78059735
removed directory '/tmp/-78059735'
It is because the command cd
treats the character followed by -
as valid option flag for it to work. Since 7
is not a valid one for cd
it is failing with the error you are seeing.
In such cases you can specify end of command line options by doing a double dash before the command name --
as below. The below command implies that the command line options for cd
are complete and there are no other flags expected after --
cd -- -78059735/
You can even have other flags provided before --
which would work just fine. The below command for mkdir
which takes an option -p
to create a directory if it does not exist before works just fine with a string having -
, provided you give an end of command line options flag right after -p
mkdir -p -- /tmp/-78059735
ls -d /tmp/*
/tmp/-78059735
rm
command to delete a directory also works just fine as below
rm -vrf -- /tmp/-78059735
removed directory '/tmp/-78059735'
edited 24 mins ago
answered 30 mins ago


Inian
2,945822
2,945822
add a comment |Â
add a comment |Â
up vote
2
down vote
cd ./-78059735
ls ./-78059735
It works for me.
New contributor
Gounou is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
2
down vote
cd ./-78059735
ls ./-78059735
It works for me.
New contributor
Gounou is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
2
down vote
up vote
2
down vote
cd ./-78059735
ls ./-78059735
It works for me.
New contributor
Gounou is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
cd ./-78059735
ls ./-78059735
It works for me.
New contributor
Gounou is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 18 mins ago
New contributor
Gounou is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
answered 31 mins ago
Gounou
663
663
New contributor
Gounou is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Gounou is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Gounou is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f476180%2fhow-do-i-use-shell-commands-with-a-directory-that-contains-like-78059735%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password