LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 02-07-2008, 08:15 PM   #1
mjchin
LQ Newbie
 
Registered: Dec 2007
Posts: 11

Rep: Reputation: 0
Delete File


I was archiving some files and accidentally used the command:
"tgz -czvf Filename.tgz directory name"

I now have a file named " -czvf.tgz " and I cannot delete it, even as root. I tried rm -czvf.tgz and mv -czvf.tgz test.tgz in an attempt to rename it but none seems to work. Any ideas?

Thanks
 
Old 02-07-2008, 08:23 PM   #2
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Blue Ridge Mountain
Distribution: Debian Jessie, Linux Mint 17
Posts: 7,750

Rep: Reputation: 271Reputation: 271Reputation: 271
Quote:
Originally Posted by mjchin View Post
I was archiving some files and accidentally used the command:
"tgz -czvf Filename.tgz directory name"

I now have a file named " -czvf.tgz " and I cannot delete it, even as root. I tried rm -czvf.tgz and mv -czvf.tgz test.tgz in an attempt to rename it but none seems to work. Any ideas?

Thanks
What error message does rm give you?

------------------
Steve Stites
 
Old 02-07-2008, 08:23 PM   #3
gankoji
Member
 
Registered: Nov 2007
Location: Southern California
Distribution: Slackware-13.0 x86_64, Slackware 12.2, slackware64-current
Posts: 225

Rep: Reputation: 35
what user did you create the archive as?

log in as that user and try to delete it from there. Are you using Ubuntu? I've heard that their version of root isn't really root.
If so, then add your user account to the sudoers file (/etc/sudoers) and beneath that add rm (the command you want to be able to sudo). Then, try removing the file using

sudo rm -cvzf.tgz

and then typing your password. Hopefully this helps.

Happy Hunting :-)
 
Old 02-07-2008, 08:24 PM   #4
b0nd
Senior Member
 
Registered: Jan 2005
Distribution: Slackware, BackTrack, Windows XP
Posts: 1,020

Rep: Reputation: 45
Quote:
Originally Posted by mjchin View Post
I was archiving some files and accidentally used the command:
"tgz -czvf Filename.tgz directory name"

I now have a file named " -czvf.tgz " and I cannot delete it, even as root. I tried rm -czvf.tgz and mv -czvf.tgz test.tgz in an attempt to rename it but none seems to work. Any ideas?

Thanks
probably it might be in use so you were not being able to delete or move it. Reboot the machine and you will be able to remove it.


regards
 
Old 02-07-2008, 08:47 PM   #5
Uncle_Theodore
Member
 
Registered: Dec 2007
Location: Charleston WV, USA
Distribution: Slackware 12.2, Arch Linux Amd64
Posts: 896

Rep: Reputation: 60
Your file name starts with a dash. That's why you can't remove it, probably... Try
rm ./-cvzf.tgz
instead.
 
Old 02-07-2008, 08:51 PM   #6
leonscape
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Debian SID / KDE 3.5
Posts: 2,313

Rep: Reputation: 47
Its a simpler matter than you think...

rm ./-czvf.tgz

as this moves the character away from the beginning at it no longer looks like an option.
 
Old 02-07-2008, 08:52 PM   #7
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
Or rm "-cvzf.tgz"
 
Old 02-07-2008, 09:03 PM   #8
leonscape
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Debian SID / KDE 3.5
Posts: 2,313

Rep: Reputation: 47
billymayday: that won't actually work, In the same way you can't create a file with

touch "-cvzf.tgz"

but can with

touch ./-cvzf.tgz

Brief partly inaccurate discription follows
Double quotes simply prevent spaces being argument separators, single quotes do the same but don't allow expansion of variables ie '$path'. So - is still the first part of the argument, making the argument an option part.
 
Old 02-07-2008, 09:23 PM   #9
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
You can use "rm -- -cvzf.tgz". The double dashes tells bash that there are no more arguments so the dash can be taken literally.

So to demonstrate, you could enter:
touch -- -stupid.name
rm -- stupid.name

As you already noticed the touch command needs the double dashes as well for the same reason that they are needed for the "rm" command. Otherwise the shell takes the characters following the dash as arguments.
 
  


Reply


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
Can't delete a file .... jimbob-2k7 Linux - Newbie 13 12-03-2007 10:48 AM
how to delete a particular file from tar file majalee Linux - Software 2 07-12-2006 05:53 AM
Can Delete a File mtoedtli2 Linux - Newbie 3 07-14-2004 05:18 PM
Tried to delete file as root but it says I don't have permission to delete it! beejayzed Mandriva 23 03-12-2004 03:46 AM
Delete contents of the file, but not file? mikeshn Linux - General 9 05-28-2003 07:47 AM


All times are GMT -5. The time now is 03:01 PM.

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