Recently used Linux related knowledge collection

Posted Jun 28, 20202 min read

Online debugging tool: https://c.runoob.com/compile/18

Standard Stream

In the field of computers, flow is used to describe the concept of data transmission. Just like water flow, it has an initial source and a downstream outlet.

When executing a Linux command, three standard streams will be created, followed by standard input(stdin), standard output(stdout), and standard error(stderr). All Linux commands provide one end of each standard stream, and the other end may be connected to a terminal, pipe, file, or other command.

Normally, standard input corresponds to the keyboard, and standard output and standard error correspond to the terminal screen(common log information). But we can also do redirection, common redirection of standard output to a file, or to a pipeline.

Redirect to file
At this time, the terminal screen no longer outputs Hello world, but directly writes to the file type.

echo "Hello"> app.log
echo "world" >> app.log #>> Redirect by appending

Redirect to pipeline
The original meaning of the pipeline is a more visual concept, which is characterized by connectability. Here, pipeline means the output of one command as the input of another command.

curl -XGET "http://elasticsearch:9200/_cat/indices" | awk -F" "'{print $3}' | sort | uniq

Common commands

echo

String output

echo'Hello World!'

Print template string

str="Hello"
echo "$str World"

The output is directed to a file, and the log can be saved to a file

echo'Hello World!'

Print the processed result

echo "cm9vdA==" | base64 --decode #root

Commonly used Linux commands

cat

Connect the file and print to the standard output device.

cat app.log

Of course, you can also redirect to other files

cat app.log> t1.txt
cat 1.txt

pwd

Show current directory

pwd #/User/dg/code

rm

Used to delete files or directories

rm app.log
rm work #rm:work:is a directory
rm -rf homework#-r delete the directory and the following files one by one -f directly delete without confirmation

chmod

File permission settings

#rreadable w writable x executable X
chmod -R r+w * #-R Recursively set the current directory and subdirectories
chmod -R 777 ./#abc r4 w2 x1

Reference materials:
https://www.howtogeek.com/435...