![如何重定向 grub-mkpasswd-pbkdf2 的输出?](https://linux22.com/image/868467/%E5%A6%82%E4%BD%95%E9%87%8D%E5%AE%9A%E5%90%91%20grub-mkpasswd-pbkdf2%20%E7%9A%84%E8%BE%93%E5%87%BA%EF%BC%9F.png)
我在命令行环境中工作,因此我习惯将输出重定向到文本文件。在这种情况下,我需要为 GRUB2 设置密码,但尝试使用重定向和相应的实用程序会使其停止打印到屏幕上,因此我无法输入所需的密码。我该如何解决这个问题?
答案1
将输出通过管道传输到tee
,它将其输入打印到stdout
多个文件(也可选择打印到多个文件):
grub-mkpasswd-pbkdf2 | tee out
% grub-mkpasswd-pbkdf2 | tee out
Enter password:
Reenter password:
PBKDF2 hash of your password is grub.pbkdf2.sha512.10000.CF99115D7DE57D065ECA4420F829FACD1FEDDD1C08ACFDDEBBB6C2948DECECCA37DEBE4F0FB37FC8CAE385A1A440663225AFB2E79B4E69557F2F9BD13AB6E586.5D5AA1A70E60CF1C09AB6B9EF831996E3F60DF7B85ADE364C7E469DC88BAAE3D8DE0F1C2A5E60267170580564AF2A36DADA663DE2DF4407562A90FEAC7E78262
% cat out
Enter password:
Reenter password:
PBKDF2 hash of your password is grub.pbkdf2.sha512.10000.CF99115D7DE57D065ECA4420F829FACD1FEDDD1C08ACFDDEBBB6C2948DECECCA37DEBE4F0FB37FC8CAE385A1A440663225AFB2E79B4E69557F2F9BD13AB6E586.5D5AA1A70E60CF1C09AB6B9EF831996E3F60DF7B85ADE364C7E469DC88BAAE3D8DE0F1C2A5E60267170580564AF2A36DADA663DE2DF4407562A90FEAC7E78262
答案2
grub-mkpasswd-pbkdf2
将提示和加密密码写入标准输出,因此即使提示不可见,您仍然可以输入密码,按Enter,再次输入,然后Enter再次按:
$ grub-mkpasswd-pbkdf2 > bar
$ cat bar
Enter password:
Reenter password:
PBKDF2 hash of your password is grub.pbkdf2.sha512.10000.40D06FD775735FA1E05AA2A732A588F79493CF7071718EFE99DEFFF06706421849716160D668D90D29139AD1A2537862DFCD6D1D172AEC7DF6552D948C472315.93544ED4795D377AB1C7FC40BA2079872F7AF19440931A7A0A71D7441C6EB563AE5438B60050F0573CF55FBD2FF0BF3ACE4811898794DD589E0BF4F184C9996C