Shell Dark Horse Course Brief

hot key

Ctrl + c Terminate the program running in the foreground
Ctrl + z Suspend the program running in the foreground to the background
Ctrl + d Exit equivalent exit
Ctrl + l Clear the screen
Ctrl + a |home Move the cursor to the front of the command line
Ctrl + e |end Move the cursor to the back end of the command line
Ctrl + u Delete all characters before the cursor
Ctrl + k Delete all characters after the cursor
Ctrl + r Search history commands

wildcard

symbol

effect

*

matches 0 or more of any character

matches any single character

reconciliation

[list]

Match any single character in [list], or a set of single characters [az]

[!list]

Matches any single character except in list

{string1,string2,...}

Match string1, string2 or more strings

special symbols

symbol

effect

double quotes ""

will treat the content of the quotation marks as a whole,

Allows referencing other variable values ​​via the $ sign .

single quote ''

The content of the quotation marks will be treated as a whole, and it is forbidden to quote other variable values .

Special symbols in the shell are treated as ordinary characters.

Backtick ``

Backticks are the same as $() , commands in quotes or brackets will be executed first ,

If there is nesting, backticks cannot be used.

Shell Scripts

interpreter

If you directly write the interpreter path in the script,
there may be a compatibility ,
so you can use: #!/bin/env interpreter ==> #!/bin/ env bash

bash parameter

-x : Generally used for troubleshooting, check the execution process of the script bash -x [shell script]
-n : Used to check if there is a problem with the syntax of the script bash -n [shell script]

script contents

  1. # specify the interpreter

  1. Description of the basic information of the script

  1. Script details

#!/bin/env bash

# 基本信息描述
# Name: t17.sh
# Desc: rm tmp/* + create dir1~dir3
# Path: ./
# Usage:
# Update: 20230109

pwd

ls -l /tmp1/

echo "===delete /tmp1/files==="
rm -rf /tmp1/*
ls -l /tmp1/
echo " files have been delete , /tmp1 no dir"


echo "===create /tmp1/files==="
mkdir -p /tmp1/dir{1..3}
ls -l /tmp1/
echo "/tmp1 has 3 dir"


echo "===cp sh scripts to /tmp1/files==="
cp -rf ./*.sh /tmp1/dir1
ls -l /tmp1/dir1
echo "cp finsh"


echo "scripts run success, $(date +'%F %T') finish"     # "+" 后面必须紧密连接'%F ,不能有空格

date

Linux date command | Rookie Tutorial (runoob.com)

%%   输出字符 %
%a   星期几的缩写 (Sun..Sat)
%A   星期的完整名称(Sunday..Saturday)。 
%b   缩写的月份名称(例如,Jan)
%B   完整的月份名称(例如,January)
%c   本地日期和时间(例如,Thu Mar  3 23:05:25 2005)
%C   世纪,和%Y类似,但是省略后两位(例如,20)
%d   日 (01..31)
%D   日期,等价于%m/%d/%y
%e   一月中的一天,格式使用空格填充,等价于%_d
%F   完整的日期;等价于 %Y-%m-%d
%g   ISO 标准计数周的年份的最后两位数字
%G   ISO 标准计数周的年份,通常只对%V有用
%h   等价于 %b
%H   小时 (00..23)
%I   小时 (01..12)
%j   一年中的第几天 (001..366)
%k   小时,使用空格填充 ( 0..23); 等价于 %_H
%l   小时, 使用空格填充 ( 1..12); 等价于 %_I
%m   月份 (01..12)
%M   分钟 (00..59)
%n   新的一行,换行符
%N   纳秒 (000000000..999999999)
%p   用于表示当地的AM或PM,如果未知则为空白
%P   类似 %p, 但是是小写的
%r   本地的 12 小时制时间(例如 11:11:04 PM)
%R   24 小时制 的小时与分钟; 等价于 %H:%M
%s   自 1970-01-01 00:00:00 UTC 到现在的秒数
%S   秒 (00..60)
%t   插入水平制表符 tab
%T   时间; 等价于 %H:%M:%S
%u   一周中的一天 (1..7); 1 表示星期一
%U   一年中的第几周,周日作为一周的起始 (00..53)
%V   ISO 标准计数周,该方法将周一作为一周的起始 (01..53)
%w   一周中的一天(0..6),0代表星期天
%W   一年中的第几周,周一作为一周的起始(00..53)
%x   本地的日期格式(例如,12/31/99)
%X   本地的日期格式(例如,23:13:48)
%y   年份后两位数字 (00..99)
%Y   年
%z   +hhmm 格式的数值化时区格式(例如,-0400)
%:z  +hh:mm 格式的数值化时区格式(例如,-04:00)
%::z  +hh:mm:ss格式的数值化时区格式(例如,-04:00:00)
%:::z  数值化时区格式,相比上一个格式增加':'以显示必要的精度(例如,-04,+05:30)
%Z  时区缩写 (如 EDT)

online class

Online course address

Guess you like

Origin blog.csdn.net/m0_59267075/article/details/128623648