Vit*_*you 0 shell io-redirection stderr
当我为 grub 创建配置文件时,我在 VGA 控制台上遇到某种错误(至少我认为这是一个错误),
grub-mkconfig -o /boot/grub/grub.cfg
Run Code Online (Sandbox Code Playgroud)
我试图将 stderr 和 stdout 重定向到一个名为 ~/grub_error 的文件中,如下所示:
grub-mkconfig -o /boot/grub/grub.cfg 2>&1 ~/grub_error
Run Code Online (Sandbox Code Playgroud)
然而,我认为是一个错误,仍然打印到屏幕上(~/grub_error 已将 stdout 重定向到它,所以我认为我没有犯语法错误)。
我还注意到,当我grub-mkconfig
在 X 会话中的终端中运行时,显示在 VGA 控制台上的“错误”没有出现。还有什么我应该重定向的,因为错误看起来很严重,类似于“......可能导致文件系统损坏”。可能值得注意的是,我使用的是带有 GPT 的 BIOS 机器,所以我有一个 bios_boot 分区,并且错误说明了 /dev/sda1(我的 bios_boot 分区)没有和 ext4 文件系统(它没有)并且不应该)。
[ 2709.836576] EXT4-fs (sda1): VFS: Can't find ext4 filesystem
[ 2709.839402] EXT4-fs (sda1): VFS: Can't find ext4 filesystem
[ 2709.841988] EXT4-fs (sda1): VFS: Can't find ext4 filesystem
[ 2709.846191] XFS (sda1): Invalid superblock magic number
[ 2709.850344] FAT-fs (sda1): invalid media value (0xe2)
[ 2709.850806] FAT-fs (sda1): Can't find a valid FAT filesystem
[ 2709.853194] FAT-fs (sda1): invalid media value (0xe2)
[ 2709.853781] FAT-fs (sda1): Can't find a valid FAT filesystem
[ 2709.855905] ntfs: (device sda1): is_boot_sector_ntfs(): Invalid boot sector checksum.
[ 2709.855913] ntfs: (device sda1): read_ntfs_boot_sector(): Primary boot sector is invalid.
[ 2709.856367] ntfs: (device sda1): read_ntfs_boot_sector(): Mount option errors=recover not used. Aborting without trying to recover.
[ 2709.856902] ntfs: (device sda1): ntfs_fill_super(): Not an NTFS volume.
[ 2709.859565] VFS: Can't find a Minix filesystem V1 | V2 | V3 on device sda1.
[ 2709.861950] hfsplus: unable to find HFS+ superblock
[ 2709.863881] ufs: You didn't specify the type of your ufs filesystem
mount -t ufs -o ufstype=sun|sunx86|44bsd|ufs2|5xbsd|old|hp|nextstep|nextstep-cd|openstep ...
>>>WARNING<<< Wrong ufstype may corrupt your filesystem, default is ufstype=old
[ 2709.867491] ufs: ufs_fill_super(): bad magic number
[ 2709.872393] hfs: can't find a HFS filesystem on dev sda1
Run Code Online (Sandbox Code Playgroud)
您将 stderr 重定向到 stdout,但您还需要重定向 stdout 本身。你只是错过了>
,重定向的顺序非常重要。
grub-mkconfig -o /boot/grub/grub.cfg >~/grub_error 2>&1
Run Code Online (Sandbox Code Playgroud)
https://www.gnu.org/software/bash/manual/html_node/Redirections.html
至于控制台和终端输出之间的区别(并且控制台上似乎没有重定向),这通常表示内核消息。打开另一个终端并输入dmesg -w
. 然后再次运行程序或脚本。您应该会看到 dmesg 命令输出的未在控制台中重定向或在终端中不存在的消息。