如何创建一个 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 thelogin.defs
file.
请注意,用户很可能在其主目录之外创建文件,这些文件在用户被删除后很难跟踪。
关于linux - bash中删除用户时删除目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35243011/