TPoly
asked on
delete files/folders
hi, i have a folder named -0.05_lt
i would like to delete it and its contents from the command shell
however, i could not delete it and could not cd into the folder as well
this is the error msg i get when i try to cd into -0.05_lt:
bash: cd: illegal option: -0
cd: usage: cd [-PL] [dir]
this folder is being ftp from somewhere else, that's y i need to delete from command shell
hope someone can help
thanks
p.s/ using debian linux
i would like to delete it and its contents from the command shell
however, i could not delete it and could not cd into the folder as well
this is the error msg i get when i try to cd into -0.05_lt:
bash: cd: illegal option: -0
cd: usage: cd [-PL] [dir]
this folder is being ftp from somewhere else, that's y i need to delete from command shell
hope someone can help
thanks
p.s/ using debian linux
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Oops, I mean
cd -- -0.05_lt (to change to the directory -0.05_lt)
cd -- -0.05_lt (to change to the directory -0.05_lt)
use cd "-0.05_lt"
ie. folder name in double quotes.
also you can remove directory same way.
rm -fr "-0.05_lt"
cnu....
ie. folder name in double quotes.
also you can remove directory same way.
rm -fr "-0.05_lt"
cnu....
re: chikkala_cnu ..That won't work
cd "-0.05_lt" Will work because cd is a shell builtin, and the quoting will actually stop the current shell
from reading the -
but the quoting will be removed from the arguments supplied to the rm program when it
is exec()'d, rm will see:
arg0 = rm
arg1 = -fr
arg2 = -0.05_lt
And interpret the -0.05_lt as an option list
Expect to see rm: invalid option -- 0
cd "-0.05_lt" Will work because cd is a shell builtin, and the quoting will actually stop the current shell
from reading the -
but the quoting will be removed from the arguments supplied to the rm program when it
is exec()'d, rm will see:
arg0 = rm
arg1 = -fr
arg2 = -0.05_lt
And interpret the -0.05_lt as an option list
Expect to see rm: invalid option -- 0
Mysidia,
you are right, thanks for the information.
cnu...
you are right, thanks for the information.
cnu...
Yeah, it's because the folder contains "-", another way of deleting it, if there isn't another folder that ends with 05_lt, is to type "rm -rf *05_lt".
Mixing rm -rf with any wildcard is a dangerous proposal.
You need to do a careful check first to make sure everything that matches *05_lt is an intended target.
It's quite easy to accidentally get burned while using wildcards, even if you know all the risks and exactly how to use them.
i.e. may be better to instead do:
echo *05_lt
^echo^rm -rf^
After all a very simple typo like "rm -rf * 05_lt" could wipe out everything in the present directory
The echo at least gives you a little time to think about what you're removing
It's best to either use -i instead of -f or type out the exact name if you want to remove exactly one file or directory (use tab completion if you want typing convenience, but check carefully before hitting enter)
You need to do a careful check first to make sure everything that matches *05_lt is an intended target.
It's quite easy to accidentally get burned while using wildcards, even if you know all the risks and exactly how to use them.
i.e. may be better to instead do:
echo *05_lt
^echo^rm -rf^
After all a very simple typo like "rm -rf * 05_lt" could wipe out everything in the present directory
The echo at least gives you a little time to think about what you're removing
It's best to either use -i instead of -f or type out the exact name if you want to remove exactly one file or directory (use tab completion if you want typing convenience, but check carefully before hitting enter)
rm -rf /full/path/to/-0.05
i.e give the full path to the directory
or even a rm -rf ./-0.05 will work