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?
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.
-delete
instead of -exec
, then realized that you were using rm -i
which is a good idea so I rolled back. Sorry.
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.
rm ./~
, for the same reason you said
Jun 19, 2013 at 7:10
./~
literally means "a file or folder named ~
in the current directory". There are no hacks like escape characters or inode references.
./~
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".
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.
--
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.)
Just to be safe I tried this in mac catalina:
mv '~' '~_bkp'
you can change directory to check the contents
cd '~_bkp' ls
If its empty simply 'remove'
rm -rf '~_bkp'
'rmdir' can be used too to remove the empty directory