linux - bash中删除用户时删除目录

标签 linux bash scripting userdel

如何创建一个 bash 脚本,如果用户被删除,该脚本将删除目录的内容?假设我有一个 user1和一些名为 somedata 的文件。我想编写删除文件 somedata 的脚本,当 user1已删除。

我正在尝试创建 bash 文件,该文件将在其中循环。到目前为止我想出了:

#!/bin/bash
if userdel $user1
then 
find . -name "somedata" -exec rm -rf 
fi

最佳答案

您可能正在寻找 userdel-r 选项。
来自 man page :

-r, --remove

Files in the user's home directory will be removed along with the home directory itself and the user's mail spool. Files located in other file systems will have to be searched for and deleted manually. The mail spool is defined by the MAIL_DIR variable in the login.defs file.

请注意,用户很可能在其主目录之外创建文件,这些文件在用户被删除后很难跟踪。

关于linux - bash中删除用户时删除目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35243011/

相关文章:

bash - 返回命令的 pid 而不是返回 tee pid

JavaScript 代码到类图

c++ - 将源代码与反汇编代码匹配

c - 奇怪的 'asm'操作数有不可能的约束错误

bash - 错误处理将一切都视为错误

linux - 如何在使用箭头进行导航的 bash 脚本中创建界面?

bash - 为什么在没有为测试提供任何参数时,在 bash 中使用 -f 进行测试会返回 true?

linux - Mongo 连接溢出

linux - 我应该如何找到几个可能字符的索引?

linux - 使用 awk 计算另一个文件中模式出现的次数