Google Answers Logo
View Question
 
Q: Remove --exclude file from a directory in RedHat Linux box ( Answered 5 out of 5 stars,   0 Comments )
Question  
Subject: Remove --exclude file from a directory in RedHat Linux box
Category: Computers > Operating Systems
Asked by: schmerold-ga
List Price: $10.00
Posted: 24 Mar 2004 08:37 PST
Expires: 23 Apr 2004 09:37 PDT
Question ID: 319990
I used wrong syntax in tar:
  tar -zcf --exclude bu?.* $bakname /home/* /etc/*

Now I have a file named --exclude, I meant to exclude files named bu?.*

1. What is correct syntax?

2. How do I delete this file ?

I've tried:
[root@STL1 root]# rm --exclude
rm: unrecognized option `--exclude'
Try `rm --help' for more information.
[root@STL1 root]# rm "--exclude"
rm: unrecognized option `--exclude'
Try `rm --help' for more information.
[root@STL1 root]# rm *
rm: unrecognized option `--exclude'
Try `rm --help' for more information.
[root@STL1 root]#
Answer  
Subject: Re: Remove --exclude file from a directory in RedHat Linux box
Answered By: maniac-ga on 24 Mar 2004 10:15 PST
Rated:5 out of 5 stars
 
Hello Schmerold,

Hmm. The first question is a little puzzling but appears to be caused
by a mix up in the order of arguments. Try something like:
  tar czf $bakname --exclude 'bu?.*' /home/* /etc/*
which should do the job for you. Note that when using the "f"
parameter, the filename for that tar archive should immediately follow
the "f". That is how you got the file named --exclude. You also should
quote the parameter for --exclude to prevent name expansion by the
shell. The rest is pretty standard. I did a quick check of the above
solution in a directory with five files in it:
  a  b  --exclude bu1.x and bu2.x
and got a compressed tar archive with only
  a  b  --exclude
in it (which appears to be what you wanted).

The solution to the second problem is pretty straight forward, but
somewhat difficult to find. The solution may vary based on what Unix
(or Linux) system you are using.

Try:
  rm -- --exclude
or
  rm ./--exclude
It may also be possible to use
  rm - --exclude
on some systems as well.

Either of the first two should work, try the third if the first does not.

To quote from 
  info rm
  (fileutils.info.gz) rm invocation

One common question is how to remove files whose names begin with a -.
GNU 'rm', like every program that uses the 'getopt' function to parse
its arguments, lets you use the '--' option to indicate that all
following options are non-options. To remove a file called '-f' in the
current directory, you could type either:
  rm -- -f
or:
  rm ./-f

The Unix 'rm' program's use of a single '-' for this purpose predates
the development of the getopt standard syntax.

A good search phrase to find other good examples would be to use
  remove file "starting  with"
which brings up several other alternative methods. The first link at
http://www.ittepic.edu.mx/eBooks/computacion/80oreilly/books/unix2/upt/ch23_15.htm
suggests using
  rm -i *
which gives you the option to delete (or not) each file.

  --Maniac
schmerold-ga rated this answer:5 out of 5 stars and gave an additional tip of: $5.00
Maniac, Thanks for the help. You got me out of the corner I painted myself into.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy