Solved

delete files/folders

Posted on 2004-08-18
8
6,756 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:TPoly
8 Comments
 
LVL 11

Expert Comment

by:avizit
ID: 11838049
try

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

0
 
LVL 23

Accepted Solution

by:
Mysidia earned 50 total points
ID: 11838096
The problem is the "-" is interpreted as a command line option.

Place -- in the command line and nothing following it will be interpreted as an option

So
rmdir -- -0.05_lt

would be the command to remove the directory

cd -- -y
would be the command to change to that directory

And

rm -rf -- -0.05_lt

Would be the command for recursive removal
0
 
LVL 23

Expert Comment

by:Mysidia
ID: 11838100
Oops, I mean
cd -- -0.05_lt   (to change to the directory  -0.05_lt)
0
 
LVL 1

Expert Comment

by:chikkala_cnu
ID: 11838210
use cd "-0.05_lt"

ie. folder name in double quotes.

also you can remove directory same way.

rm -fr "-0.05_lt"


cnu....
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 23

Expert Comment

by:Mysidia
ID: 11838246
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
0
 
LVL 1

Expert Comment

by:chikkala_cnu
ID: 11838380
Mysidia,

you are right, thanks for the information.

cnu...
0
 
LVL 1

Expert Comment

by:uxlin
ID: 12030654
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".
0
 
LVL 23

Expert Comment

by:Mysidia
ID: 12031762
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)
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will explain how to make squid prevent malwares in five easy steps: Squid is a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now