服务器中根据文件名检索文件
-
要在Linux中查找特定文件名的文件,可以使用find命令或locate命令。
-
使用find命令。例如,要在当前目录及其子目录中查找名为example.txt的文件:
find . -name "example.txt"
但是find命令可能有访问权限的限制,导致不能检索成功。
find: ‘./run/systemd/unit-root’: Permission denied
find: ‘./run/systemd/resolve/netif’: Permission denied
find: ‘./run/systemd/inaccessible’: Permission denied
-
使用locate命令。例如,要在整个系统中查找名为example.txt的文件:
locate -r ".*example.txt"
locate命令检索没有权限限制,可以检索相关的文件,不会出现Permission denied。检索成功则返回检索到的文件,检索不到则不返回任何东西。 -
linux模糊查找命令
find命令,grep命令,locate命令进行模糊查找