Note_Tech

All technological notes.


Project maintained by simonangel-fong Hosted on GitHub Pages — Theme by mattgraham

Linux - Fundamental: Kernel

Back


I/O

Input/Output Types

I/O Name Abbreviation File Descriptor
Standard Input stdin 0
Standard Output stdout 1
Standard Error stderr 2

Null Device


Redirection

ls /usr /cdr &>output.out
cat output.out
# ls: cannot access '/cdr': No such file or directory
# /usr:
# bin
# games
# include
# lib
# lib64
# libexec
# local
# sbin
# share
# src
# tmp

tee: Redirect both display and a file

CMD DESC
ls /etc \| tee /tmp/output printed on the screen as well as
redirected to file  
# As user1 on server1, run the ls command on /etc, /dvd, and
# /var. Have the output printed on the screen as well as
# redirected to file /tmp/ioutput, and the errors forwarded to
# file /tmp/ioerror. Check both files after the execution of the
# command and analyze the results. (Hint: Input, Output, and
# Error Redirections).

ls /dvd /var > /tmp/output 2> /tmp/error

|: Pips

# the file content from the cat command will be the content of grep command
cat file | grep pattern

Wildcard

Wildcard Desc
* Matches zero or more characters
? Matches exactly one characters
[aeiou] Character class, matches exactly one of included characters
[!aeiou] Exclude exactly one of characters
[a-g],[3-6] Range
\?,\* Escape character, match a wildcard character.

ll c[aeiou]t
ll [a-d]*
cp *[[:digit:]] /tmp

rm ??

Lab: I/O Redirection

# output to a file
ls -l > file.txt
ls -l 1> file.txt      # equivalent, no space between 1 and >

cat file.txt

# output and append to a file
ls >> file.txt

# redirect from a file to a command
sort < file.txt     # sort doesn't work on file.txt

sort < file.txt > sorted_files.txt  # redirect from file to sort and output to the new txt

Redirect the Error Output

# try to ls one existing file and a not existing file, output error
ls file.txt not-here
# ls: cannot access 'not-here': No such file or directory
# file.txt

# output the std output to a file, but display error.
ls file.txt not-here > out
# ls: cannot access 'not-here': No such file or directory
cat out
# file.txt

# output the error to a file, but display std output
ls file.txt not-here 2> out.err
# file.txt
cat out.err
# ls: cannot access 'not-here': No such file or directory

# split std and err into two files
ls file.txt not-here 1>out 2> out.err
cat out
# file.txt
cat out.err
# ls: cannot access 'not-here': No such file or directory

# redirect both into a file
ls file.txt not-here > out.log 2>&1
cat out.log
# ls: cannot access 'not-here': No such file or directory
# file.txt

Redirect to Null Device

# try to ls one existing file and a not existing file, output error
ls file.txt not-here
# ls: cannot access 'not-here': No such file or directory
# file.txt

# discard error
ls file.txt not-here 2>/dev/null
# file.txt

# display error only, discard std output
ls file.txt not-here 1>/dev/null
# ls: cannot access 'not-here': No such file or directory

# discard all message,including std output and error
ls file.txt not-here >/dev/null 2>&1

Kernel

# list kernel package
yum list installed kernel*
# Installed Packages
# kernel.x86_64                       5.14.0-362.24.1.el9_3           @rhel-9-for-x86_64-baseos-rpms
# kernel.x86_64                       5.14.0-503.23.2.el9_5           @rhel-9-for-x86_64-baseos-rpms
# kernel-core.x86_64                  5.14.0-362.24.1.el9_3           @rhel-9-for-x86_64-baseos-rpms
# kernel-core.x86_64                  5.14.0-503.23.2.el9_5           @rhel-9-for-x86_64-baseos-rpms
# kernel-modules.x86_64               5.14.0-362.24.1.el9_3           @rhel-9-for-x86_64-baseos-rpms
# kernel-modules.x86_64               5.14.0-503.23.2.el9_5           @rhel-9-for-x86_64-baseos-rpms
# kernel-modules-core.x86_64          5.14.0-362.24.1.el9_3           @rhel-9-for-x86_64-baseos-rpms
# kernel-modules-core.x86_64          5.14.0-503.23.2.el9_5           @rhel-9-for-x86_64-baseos-rpms
# kernel-tools.x86_64                 5.14.0-503.23.2.el9_5           @rhel-9-for-x86_64-baseos-rpms
# kernel-tools-libs.x86_64            5.14.0-503.23.2.el9_5           @rhel-9-for-x86_64-baseos-rpms

Kernel Version

uname -r
# 5.14.0-503.23.2.el9_5.x86_64
# Major version.Major revision.kernel patch version-Redhat version.enterprise linux 9.processor architecture 

# general Linux: 5.14.0

Kernel dir

Installing the Kernel

Lab: Download and Install a New Kernel