AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题 / 483585
Accepted
Mandingo
Mandingo
Asked: 2018-11-23 20:21:24 +0800 CST2018-11-23 20:21:24 +0800 CST 2018-11-23 20:21:24 +0800 CST

必须在目录上设置哪些权限才能允许将数据附加到该目录中的文件,但不能删除该文件?

  • 772

“必须在目录上设置什么权限才能允许将数据附加到该目录中的文件,但不能删除该文件?”

据我了解,您需要“w”写入权限才能将数据附加到文件中,但这也将使您能够删除文件,但问题是要求应该为能够附加的权限设置数据到文件但不删除它。

linux
  • 2 2 个回答
  • 2085 Views

2 个回答

  • Voted
  1. Best Answer
    Haxiel
    2018-11-23T20:47:04+08:002018-11-23T20:47:04+08:00

    将数据附加到文件需要文件本身的写入权限。删除文件需要对包含文件的目录具有写权限。

    例如,我有一个名为 testdir 的目录,我已经删除了该目录的写权限:

    [haxiel@testvm1 ~]$ ls -ld testdir/
    dr-xr-xr-x. 2 haxiel haxiel 26 Nov 23 10:09 testdir/
    

    在目录中,我创建了一个名为 testfile.txt 的文件(这是在删除目录的写权限之前完成的)。

    [haxiel@testvm1 testdir]$ ls -l testfile.txt
    -rw-rw-r--. 1 haxiel haxiel 12 Nov 23 10:11 testfile.txt
    

    现在,我可以将数据附加到文件中,因为我对它有写权限:

    [haxiel@testvm1 testdir]$ echo "Line1" >> testfile.txt
    [haxiel@testvm1 testdir]$ echo "Line2" >> testfile.txt
    [haxiel@testvm1 testdir]$ cat testfile.txt
    Line1
    Line2
    

    但我无法删除该文件,因为我对其父目录没有写权限。

    [haxiel@testvm1 testdir]$ rm testfile.txt
    rm: cannot remove ‘testfile.txt’: Permission denied
    

    您可以查看此问题以获取有关目录权限的更多详细信息:执行与读取位。Linux 中的目录权限是如何工作的?

    • 3
  2. Michael Prokopec
    2018-11-23T21:06:24+08:002018-11-23T21:06:24+08:00

    目录与文件权限无关。该文件如果也可以写入,也可以删除。您可以尝试 ACL,例如:How to give permissions to read write but not delete the file,但这很容易解决。

    以下是文件权限的说明:

    (rwx------)  This area is for owner.
    (---rwx---)  This area is for group owner.
    (------rwx)  This area is for others.
    (-rwx------) The preceding - indicates a directory.
    
           Value       | Meaning
                       |
    ==========================================================================================================================================================================================================
                       |
    777    (rwxrwxrwx) | No restrictions on permissions. Anybody may do anything. Generally not a desirable setting.
    
    755    (rwxr-xr-x) | The file's owner may read, write, and execute the file. All others may read and execute the file. This setting is common for programs that are used by all users.
    
    700    (rwx------) | The file's owner may read, write, and execute the file. Nobody else has any rights. This setting is useful for programs that only the owner may use and must be kept private from others.
    
    666    (rw-rw-rw-) | All users may read and write the file.
    
    644    (rw-r--r--) | The owner may read and write a file, while all others may only read the file. A common setting for data files that everybody may read, but only the owner may change.
    
    600    (rw-------) | The owner may read and write a file. All others have no rights. A common setting for data files that the owner wants to keep private.
    
    • 1

相关问题

  • 有没有办法让 ls 只显示某些目录的隐藏文件?

  • 使用键盘快捷键启动/停止 systemd 服务 [关闭]

  • 需要一些系统调用

  • astyle 不会更改源文件格式

  • 通过标签将根文件系统传递给linux内核

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    ssh 无法协商:“找不到匹配的密码”,正在拒绝 cbc

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    如何卸载内核模块“nvidia-drm”?

    • 13 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Wong Jia Hau ssh-add 返回:“连接代理时出错:没有这样的文件或目录” 2018-08-24 23:28:13 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST
  • Martin Hope
    Bagas Sanjaya 为什么 Linux 使用 LF 作为换行符? 2017-12-20 05:48:21 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve