我在 linux 服務器中有一個檔案夾 /srv/log/ ,其中有包含服務器名稱的子檔案夾:
服務器1 服務器2 服務器3 服務器4
我需要一個命令來顯示這些檔案夾中的內容,但只顯示文本檔案“del_list”中的特定內容:
服務器2 服務器4
我正在嘗試使用回圈:
for i in `cat del_list`; do `ls /srv/log/$i/`; done
但它只顯示了這些服務器的一部分和錯誤:
-bash: folder1: command not found
-bash: folder2: command not found
但是還有許多其他檔案夾:'folder2,folder3' 那里但我無法使用我的命令列出它們,我在這里做錯了什么?
uj5u.com熱心網友回復:
for i in `cat del_list`; do ls /srv/log/$i/; done
在命令后面沒有反引號 do
uj5u.com熱心網友回復:
如果您可以運行 python scrpit:
#! /usr/bin/python3
import subprocess
import os
with open("del_list", "r") as f:
data = f.read().split(" ")
for file in data:
filepath = "/srv/log/" file
if os.path.isdir(filepath):
subprocess.check_call("ls " filepath, shell=True)
else:
print("Path " filepath " not exist!")
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/354115.html
