46
17
I just noticed that I have a file called ~
in my ~
-directory.
$ ls -la ~
...
-rw-r----- 1 x1 x1 733962240 Mar 1 17:55 ~
...
Any idea how I can mv
or rm
it?
46
17
I just noticed that I have a file called ~
in my ~
-directory.
$ ls -la ~
...
-rw-r----- 1 x1 x1 733962240 Mar 1 17:55 ~
...
Any idea how I can mv
or rm
it?
55
The pretty much ultimate solution when it comes to files that can't be deleted by normal means:
ls -il
The first column will show the inode number of the files.
find . -inum [inode-number] -exec rm -i {} \;
This will delete the file with the specified inode-number after verification.
This answer didn't work for me. Ubuntu 14.04 LTS – KhoPhi – 2016-03-01T02:43:54.167
The answer worked, but the tilde directory kept being re-created by eclipse. Had to clear the tilde out of the default workspace in eclipse/configuration/.settings/org.eclipse.ui.ide.prefs – rickfoosusa – 2016-05-21T19:35:25.310
This worked. Perhaps the the solution by rici is good too, but I didn't try. Thanks a lot! – scrrr – 2013-06-19T07:46:41.660
Yes, rici's answer is good too. And I think it's better because it's simpler. – Andrey Regentov – 2013-06-20T04:51:47.267
nice, +1. I changed your answer to use -delete
instead of -exec
, then realized that you were using rm -i
which is a good idea so I rolled back. Sorry. – terdon – 2013-06-26T23:21:08.663
Don't worry. Always glad when somebody deems my answers worthy of their time :) – Squeezy – 2013-06-29T22:19:57.703
47
You should be able to refer to that file as ~/~
(without quotes) because tilde-expansion only applies the the tilde (~
) at the very beginning of the word.
@CarlosCampderrós consider making that an answer. I would deem it as the "best" and most straightforward solution, compared to other answers since ./~
literally means "a file or folder named ~
in the current directory". There are no hacks like escape characters or inode references. – ADTC – 2018-01-11T17:36:17.557
@ADTC: in defence of my answer, it does not require changing the CWD, whereas using ./~
does. After five years, my memory is a little fuzzy, but I think that is why I suggested ~/~
rather than the more normal ./~
: The question specifically refers to "a file named ~
in [OP's] home directory"; not "in the current directory". – rici – 2018-01-11T18:20:33.803
@rici That makes sense, and in the context of the question it would be appropriate. But I do like to see answers that are general, or speak generally first before expounding more to the question's specific case. That's my defense :D – ADTC – 2018-01-12T00:31:01.383
17also, going to the folder and rm ./~
, for the same reason you said – Carlos Campderrós – 2013-06-19T07:10:34.950
20
Quote it (rm '~'
) or escape it (rm \~
).
It's always either of those (also for e.g. $
), or add --
to prevent the file name from being interpreted as argument: rm -- -i
removes the file named -i
; also useful for rm -- *
when you want to delete all files in the current directory: No accidental rm -f *
just because a file is named like that.
@Bob Well, rm -- *
does what it says on the tin (what else would you expect?). You won't accidentally rm -f *
though, just because there's a file named -f
. – Daniel Beck – 2015-05-26T13:18:39.507
It's a nuance that those unfamiliar with shell expansion might make a mistake with. I'm just suggesting making that a bit clearer in the answer. – Bob – 2015-05-26T15:44:44.957
Hm, no that doesn't seem to work.. I tried the single quotes, the escaping and backticks.. he doesn't pick up the file. Says either it doesn't exist or interprets ~ as the home-directory.. – scrrr – 2013-06-19T05:08:56.127
@scrrr What's your shell? – Daniel Beck – 2013-06-19T07:49:41.023
bash. But problem solved the inode way. – scrrr – 2013-06-19T09:06:54.360
@scrrr Glad your problem is solved, but now I want to know why bash escapes don't work the same way on your system as it does on mine. – Isaac Rabinovitch – 2013-06-25T21:28:09.763
1Careful. --
only stops the following arguments being interpreted as parameters - it doesn't prevent the shell from performing its expansion (e.g. *
), which is what's happening here. (I know you suggested it as an alternative for other situations, but a warning would be good.) – Bob – 2014-01-30T00:17:03.950
Try to delete it by i-node. – gronostaj – 2013-06-19T05:25:37.717