12 janv. 2016

Supprimer un fichier qui commence par un tiret (ou plus)

Un fichier avait généré un fichier commençant par "--". Mais malencontreusement, la commande rm essaie d'interpréter le tiret...

Heureusement voici un article de l'excellent blog Nixcraft qui explique comment se sortir de cette délicate situation


"I am a new Unix shell user at my university shell server. Accidentally, I had created a file called -foo. Now, how do I remove a file with a name starting with '-' under UNIX-like or Linux operating system?

You can use standard UNIX/Linux rm command. All you have to do is instruct the rm command not to follow end of command line flags by passing double dash -- option before -foo file name.

Many user creates these kind of file accidentally with dashes. If you attempt to remove such file via rm command, UNIX and Linux will attempt to use them as command-line options and the command will display out with an error. So how do you get rid of these files and delete them on a UNIX?


rm command syntax


Use rm command to remove files or directories as follows:
rm -- -foo

OR
rm ./-foo

OR
rm ./-filename
Other options: Unix remove file with dash

Some more options remove the ---- Dashes ---- on a Unix-like system:


rm ./-Foo
rm "./---bar"
rm -- -F
rm -- ---footbal
## Edit file ##
vi  "./--foo"

SOURCE: http://www.cyberciti.biz/faq/unix-linux-remove-strange-names-files/ "

Aucun commentaire:

Enregistrer un commentaire