All technological notes.
| I/O Name | Abbreviation | File Descriptor |
|---|---|---|
| Standard Input | stdin |
0 |
| Standard Output | stdout |
1 |
| Standard Error | stderr |
2 |
Input(stdin) - 0
< symbol
Output(stdout) - 1
> symbol
>> symbol
Error(stderr) - 2
2> / 2>> can be used to redirect output.Null Device
>/dev/null: Redirect output to nowhere.
>
>>
<
&
file descriptor is being used.2>&1
&>file
2>file
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|
command-output | command-inputExample:
# the file content from the cat command will be the content of grep command
cat file | grep pattern
| 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. |
Named Character Classes
[[:alpha:]]: Matches alphabetic characters[[:lower:]]: Matches lower-case letters[[:upper:]]: Matches upper-case letters[[:digit:]]: Matches any one digit 0-9[[:alnum:]]: Matches all alphanumeric characters[[:space:]]: Matches white space[[:blank:]]: Matches blank characters, such as space and tab[[:cntrl:]]: Matches control characters[[:graph:]]: Matches graphical characters[[:print:]]: Matches printable characters[[:punct:]]: Matches punctuation charactersll c[aeiou]t
ll [a-d]*
cp *[[:digit:]] /tmp
rm ??
# 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
# 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
# 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
# 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
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