Linux,How to delete a file named "-C" [closed] - linux

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
I have a file named "-C". How can I delete it? This doesn't work:
rm -rf -C
I guess I need to use escape characters.

rm ./-C
That should do it, given you're in the correct directory.

you can use '--' to delimit the option list.
touch -- -aname # will create '-aname' file
rm -- -aname # will delete it
more details in coreutils info pages.

either
rm -rf "-C"
or
rm -rf ./-C

Did you try escaping the "-" character?
rm -rf "\-C"

Related

Unix directory deletion: [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 1 year ago.
Improve this question
There was a directory structure on my linux server like this A/$b/
From my home directory executed a command
rm -rf A/$b.
After executing this command, The directory A itself was deleted.
Any idea what would have happened in the background?
A $ sign indicates the start of a variable in most shell languages.
If $b is not defined then your command would resolve as:
rm -rf A/
… which would delete the A directory.
To include the $ in the path you need to escape it:
rm -rf A/\$B

linux cp file at the same directory but do not want cd to that directory [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
what i do
$ cp /etc/libvirt/qemu/centos7.8.xml{,123.xml}
what happend
$ ls /etc/libvirt/qemu/
centos7.8.xml centos7.8.xml123.xml
but what i want is
$ ls /etc/libvirt/qemu/
centos7.8.xml 123.xml
i don't want to use the follow , write /etc/libvirt/qemu twice:
$ cp /etc/libvirt/qemu/centos7.8.xml /etc/libvirt/qemu/123.xml
and i know what {,_backup} mean.
any way?
like follow ? no such format
cp /etc/libvirt/qemu/centos7.8.xml{123.xml}
Using bash extension brace expansion you can do the following:
cp /etc/libvirt/qemu/{centos7.8.xml,123.xml}
or even:
cp /etc/libvirt/qemu/{centos7.8,123}.xml

How to delete folders that start with "--" through command line [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 years ago.
Improve this question
After running a bad command my computer generates folders that start with "--". When I run ls I get something like:
workspace
--workspace
I don't know how to delete these folders through the command line.
rm -r --workspace does not work. I only have access to this machine through CLI so I can't delete them using the gui.
My OS is Linux 18.04
You need to tell rm to stop parsing and use your arguments verbatim. You do this by passing a final -- argument before the file or folder name.
rm -r -- --workspace

How to delete a file whose owner is set to 777 by mistake on linux [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
Tried with a few things I could think of without success. Ideas? Thanks.
You should be able to delete the file if you run the remove command with sudo
sudo rm /path/to/file.txt
thanks to everyone. The answer is when all attempts to change owner of the file fail, check the owner of its parent directory :).
If it's your server, you can just sudo rm file.
rm -rf filename if you have the permission do delete the file
Otherwise:
sudo chown user filename && rm -rf filename where user is your username.

On Linux, what is the correct way to completely empty a directory without deleting it? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
Obvious solutions such as rm -rf directory/* will forget hidden files, for example. What is the correct way to do this?
My use case is the following: my directory is a subfolder of a root controlled directory, created by root and chowned to my user. If I delete it, I won't have the permissions to re-create it. However I want to make sure it's completely clean at the start of my process.
Try this :
find directory -mindepth 1 -delete
You can use:
shopt -s dotglob
rm -rf directory/*
This will delete hidden files also (starting with a dot).
Or else use find -delete:
cd directory
find . -delete
You can use
rm -rf /some/path/.* deletes all hidden files in that dir

Resources