簡體   English   中英

使用bash命令從文件中檢索純文本密碼

[英]retrieve plaintext password from file using bash command

我想從已知文件中讀取一個值。

文件位於/root/.my.cnf並包含

[client]
password='PosftGlK2y'

我想返回PosftGlK2y-理想情況下使用一個簡單的襯紙命令。

我努力了

cat /root/.my.cnf | grep password

返回密碼='PosftGlK2y'

我相信有更好的方法。

您可以直接跳過catgrep ,然后使用'分隔符將其管道傳輸到awk

grep password /root/.my.cnf | awk -F"'" '{print $2}'

或者,您可以完全跳過grep,而僅使用awk進行搜索和提取。

awk -F"'" '/^password=/{print $2}' /root/.my.cnf

您可以使用cut來分割'字符上的行:

grep password= /root/.my.cnf | cut -d "'" -f 2

退貨

PosftGlK2y

cut命令在定界符( -d標志)上分割一行,並返回由f標志指定的列。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM