有没有办法从 Linux 服务器执行 grep 或 ls -l 并返回具有扩展属性的任何文件或目录?
我将使用 BladeLogic 将命令传递给目标服务器,并收集信息并将其处理到 Blade 中的结果表中。
答案1
您正在搜索的命令是
lsattr -R /directory/to/be/searched
来自 Linux 手册 ( man lsattr
) 的lsattr
:
NAME
lsattr - list file attributes on a Linux second extended file system
SYNOPSIS
lsattr [ -RVadv ] [ files... ]
DESCRIPTION
lsattr lists the file attributes on a second extended file system. See
chattr(1) for a description of the attributes and what they mean.
OPTIONS
-R Recursively list attributes of directories and their contents.
这是以非特权用户身份在我的主目录中执行该命令的输出。
$ lsattr -R | more
-------------e-- ./zz.txt
-------------e-- ./VirtualBox VMs
./VirtualBox VMs:
-------------e-- ./VirtualBox VMs/Ollie2
./VirtualBox VMs/Ollie2:
-------------e-- ./VirtualBox VMs/Ollie2/Ollie2.vbox
-------------e-- ./VirtualBox VMs/Ollie2/Ollie2.vbox-prev
-------------e-- ./VirtualBox VMs/Ollie2/Logs
./VirtualBox VMs/Ollie2/Logs:
-------------e-- ./VirtualBox VMs/Ollie2/Logs/VBox.log
-------------e-- ./VirtualBox VMs/Ollie2/Logs/VBox.log.1
-------------e-- ./VirtualBox VMs/Ollie2/Logs/VBox.log.2
-------------e-- ./VirtualBox VMs/Ollie2/Logs/VBox.log.3
-------------e-- ./VirtualBox VMs/Ollie2/Ollie2.vdi
-------------e-- ./VirtualBox VMs/JH
./VirtualBox VMs/JH:
-------------e-- ./VirtualBox VMs/JH/JH.vbox-prev
-------------e-- ./VirtualBox VMs/JH/JH.vbox
-------------e-- ./VirtualBox VMs/JH/JH.vdi
等等。
答案2
很简单,进入可疑文件夹,运行命令:
lsattr -laR | grep +immutable