3 Basic Commands and Simple Shell Scripts Once you have your first Red Hat Enterprise Linux rhel


games, initramfs, iscsi, kdump, logrotate, misc, mlocate



Download 1.85 Mb.
View original pdf
Page15/67
Date26.02.2024
Size1.85 Mb.
#63678
1   ...   11   12   13   14   15   16   17   18   ...   67
Pablo Iranzo Gómez, Pedro Ibáñez Requena, Miguel Pérez Colino, Scott McCarty - Red Hat Enterprise Linux 9 Administration-Packt Publishing (2022) -chap 3 82 - 180
games, initramfs, iscsi, kdump, logrotate, misc, mlocate,
NetworkManager, os-prober, PackageKit, plymouth, polkit-
1, private, rhsm, rpm, rpm-state, rsyslog, samba, selinux,
setroubleshoot, smartmontools, sss, systemd, tpm2-tss, udisks2,
unbound, xfsdump
The /root/var-files.txt file now contains both the comma-separated list for var and for
/var/lib.
Now, we can try to list a non-existing directory to see an error being printed:
[root@rhel-instance
]# ls -m /non

ls: cannot access 'non No such file or directory
The output we see is an error and is treated differently by the system than regular messages. We can try to redirect the output to a file:
[root@rhel-instance
]# ls -m non > non-listing.txt

ls: cannot access 'non No such file or directory
[root@rhel-instance
]# cat non-listing.txt

[root@rhel-instance
]#

We can see that using the standard redirect, with a command providing an error message, will show the error message (via STDERR) onscreen and create an empty file. This is because the file contains the output of the common information messages that are shown via STDOUT. We can still capture the output of the error, redirecting STDERR, by using 2>:
[root@rhel-instance
]# ls -m/non 2> /root/error.txt

[root@rhel-instance
]# cat /root/error.txt

ls: cannot access 'non No such file or directory
Now, we can redirect the standard output and the error output independently.

Basic Commands and Simple Shell Scripts
80
Now, we want to count the number of files and directories in var. For that, we are going to use the wc command, which stands for word count, with thew option to only focus on counting words. To do so, we will redirect the output of ls to it by using a pipe represented by |:
[root@rhel-instance
]# ls -m var | wc -w


Download 1.85 Mb.

Share with your friends:
1   ...   11   12   13   14   15   16   17   18   ...   67




The database is protected by copyright ©ininet.org 2024
send message

    Main page