我在远程计算机上有一个文件(这么说,因为我不知道到底是谁创建了它),我必须删除它。
user@machine:~/folder$ ls
lift_proto.db.lock.db
并且权限是这样的:
user@machine:~/folder$ ls -al
total 12
drwxrwxrwx 2 root root 4096 2012-03-06 20:57 .
drwxr-xr-x 26 user group 4096 2012-03-06 20:53 ..
-rw-r--r-- 1 root root 126 2012-03-06 20:57 lift_proto.db.lock.db
尝试删除:
user@machine:~/folder$ sudo rm lift_proto.db.lock.db
什么也没有发生:
user@machine:~/folder$ ls
lift_proto.db.lock.db
我见过那个问题,但这并没有多大帮助:
user@machine:~/folder$ lsattr
-----------------e- ./lift_proto.db.lock.db
此外,我先后尝试将文件的所有权user
和权限更改为 777,但随后我删除了该文件,但它仍然以 root 所有权和旧权限返回。
我最后的猜测是有人以某种方式从其他地方同步该文件(顺便说一句,有什么办法可以看到它吗?),如果没有(例如,您看到有一些带有属性或等的东西),我该如何删除它?
更新1:
-f
的标志rm
不能解决问题
更新2:stat
这是之前和之后的 输出:
user@machine:~/folder$ stat lift_proto.db.lock.db
File: `lift_proto.db.lock.db'
Size: 126 Blocks: 8 IO Block: 4096 regular file
Device: 900h/2304d Inode: 20054245 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2012-03-06 21:30:40.600796566 +0400
Modify: 2012-03-06 21:30:40.600796566 +0400
Change: 2012-03-06 21:30:40.600796566 +0400
user@machine:~/folder$ sudo rm -f lift_proto.db.lock.db
user@machine:~/folder$ stat lift_proto.db.lock.db
File: `lift_proto.db.lock.db'
Size: 126 Blocks: 8 IO Block: 4096 regular file
Device: 900h/2304d Inode: 20054245 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2012-03-06 21:32:36.621421452 +0400
Modify: 2012-03-06 21:32:36.621421452 +0400
Change: 2012-03-06 21:32:36.621421452 +0400
更新3
跟踪输出
user@machine:~/folder$ sudo strace rm -f lift_proto.db.lock.db
execve("/bin/rm", ["rm", "-f", "lift_proto.db.lock.db"], [/* 14 vars */]) = 0
brk(0) = 0x8c9000
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc967443000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=42930, ...}) = 0
mmap(NULL, 42930, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fc967438000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/libc.so.6", O_RDONLY) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0`\355\1\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1572232, ...}) = 0
mmap(NULL, 3680296, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fc966ea3000
mprotect(0x7fc96701d000, 2093056, PROT_NONE) = 0
mmap(0x7fc96721c000, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x179000) = 0x7fc96721c000
mmap(0x7fc967221000, 18472, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fc967221000
close(3) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc967437000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc967436000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc967435000
arch_prctl(ARCH_SET_FS, 0x7fc967436700) = 0
mprotect(0x7fc96721c000, 16384, PROT_READ) = 0
mprotect(0x60e000, 4096, PROT_READ) = 0
mprotect(0x7fc967445000, 4096, PROT_READ) = 0
munmap(0x7fc967438000, 42930) = 0
brk(0) = 0x8c9000
brk(0x8ea000) = 0x8ea000
open("/usr/lib/locale/locale-archive", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=2027984, ...}) = 0
mmap(NULL, 2027984, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fc966cb3000
close(3) = 0
open("/usr/share/locale/locale.alias", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=2570, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc967442000
read(3, "# Locale name alias data base.\n#"..., 4096) = 2570
read(3, "", 4096) = 0
close(3) = 0
munmap(0x7fc967442000, 4096) = 0
open("/usr/lib/locale/en_US.UTF-8/LC_IDENTIFICATION", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/en_US.utf8/LC_IDENTIFICATION", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=373, ...}) = 0
mmap(NULL, 373, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fc967442000
close(3) = 0
open("/usr/lib/gconv/gconv-modules.cache", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=26048, ...}) = 0
mmap(NULL, 26048, PROT_READ, MAP_SHARED, 3, 0) = 0x7fc96743b000
close(3) = 0
open("/usr/lib/locale/en_US.UTF-8/LC_MEASUREMENT", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/en_US.utf8/LC_MEASUREMENT", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=23, ...}) = 0
mmap(NULL, 23, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fc96743a000
close(3) = 0
open("/usr/lib/locale/en_US.UTF-8/LC_TELEPHONE", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/en_US.utf8/LC_TELEPHONE", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=59, ...}) = 0
mmap(NULL, 59, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fc967439000
close(3) = 0
open("/usr/lib/locale/en_US.UTF-8/LC_ADDRESS", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/en_US.utf8/LC_ADDRESS", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=155, ...}) = 0
mmap(NULL, 155, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fc967438000
close(3) = 0
open("/usr/lib/locale/en_US.UTF-8/LC_NAME", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/en_US.utf8/LC_NAME", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=77, ...}) = 0
mmap(NULL, 77, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fc967434000
close(3) = 0
open("/usr/lib/locale/en_US.UTF-8/LC_PAPER", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/en_US.utf8/LC_PAPER", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=34, ...}) = 0
mmap(NULL, 34, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fc967433000
close(3) = 0
open("/usr/lib/locale/en_US.UTF-8/LC_MESSAGES", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/en_US.utf8/LC_MESSAGES", O_RDONLY) = 3
fstat(3, {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
close(3) = 0
open("/usr/lib/locale/en_US.utf8/LC_MESSAGES/SYS_LC_MESSAGES", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=57, ...}) = 0
mmap(NULL, 57, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fc967432000
close(3) = 0
open("/usr/lib/locale/en_US.UTF-8/LC_MONETARY", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/en_US.utf8/LC_MONETARY", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=286, ...}) = 0
mmap(NULL, 286, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fc967431000
close(3) = 0
open("/usr/lib/locale/en_US.UTF-8/LC_COLLATE", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/en_US.utf8/LC_COLLATE", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=1170770, ...}) = 0
mmap(NULL, 1170770, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fc967313000
close(3) = 0
open("/usr/lib/locale/en_US.UTF-8/LC_TIME", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/en_US.utf8/LC_TIME", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=2454, ...}) = 0
mmap(NULL, 2454, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fc967312000
close(3) = 0
open("/usr/lib/locale/en_US.UTF-8/LC_NUMERIC", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/en_US.utf8/LC_NUMERIC", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=54, ...}) = 0
mmap(NULL, 54, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fc967311000
close(3) = 0
open("/usr/lib/locale/en_US.UTF-8/LC_CTYPE", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/en_US.utf8/LC_CTYPE", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=256324, ...}) = 0
mmap(NULL, 256324, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fc9672d2000
close(3) = 0
ioctl(0, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo ...}) = 0
unlinkat(AT_FDCWD, "lift_proto.db.lock.db", 0) = 0
close(0) = 0
close(1) = 0
close(2) = 0
exit_group(0) = ?
答案1
该文件是一个氢2文件锁,来自举起基于(网络)的应用程序。 H2使用了一个有趣的文件锁定协议,如果该数据库正在使用,该文件将立即重新创建。
(文件名与该框架的默认持久性数据库名称匹配。)
如果您希望删除该文件,则需要停止正在运行该数据库的任何应用程序服务器。 (但你真的吗?)
您的strace
输出清楚地表明取消链接成功。
unlinkat(AT_FDCWD, "lift_proto.db.lock.db", 0) = 0
索引节点号可以重复使用。文件系统可以使用它们想要的任何分配策略,但没有什么可以阻止它们重新分配相同的索引节点号。
在空闲的 ext3 文件系统上:
$ touch a
$ stat -c %i a
593358
$ rm a
$ touch a
$ stat -c %i a
593358
$ touch a b
$ stat -c %i a b
593358
593362
$ rm a b
$ touch b a
$ stat -c %i a b
593362
593358
答案2
您是否尝试使用 inode 值删除它?以下教程对此进行了解释:linux下如何删除带空格的文件
本质上,您可以使用以下命令检索文件的索引节点ls -il
(索引节点是列表中的第一个数字,然后您可以使用:
find . -inum 123456 -exec rm -i {} \;
(将 123456 替换为您通过 找到的索引节点号ls -il
。)