[英]extract output from command and pipe it on the command
所以基本上我在/var/log/xxx.log中有日志文件。 這些日志文件每天都會更改,因此我必須使用: ls -lt /var/log/ 以找出最新的日志。 我用了:
ls -lt /var/log/ | head -2 | tail -1 | awk '{print $9}'
提取名稱,但是如何將它與沒有“cd”的目錄路徑結合起來? 喜歡:
ls -lt /var/log/ | head -2 | tail -1 | awk '{print $9}' | tail -100 /var/log/[from pipe]
您可以簡單地替換awk '{print $9}' | tail -100 /var/log/[from pipe]
awk '{print $9}' | tail -100 /var/log/[from pipe]
by tail -100 /var/log/$(awk '{print $9}')
查找目錄中不到一天前已更改或創建的文件的更好方法是:
find /var/log/ -type f -maxdepth 1 -mtime -1
解釋:
-type f : only look for files
-maxdepth 1 : only look inside this directory
-mtime -1 : only look for the once, being changed at most one day ago
祝你好運
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.