linux 常用 shell 大杂烩 合集
linux shell 批量修改文件后缀名
rename 's/\.csv/\.txt/' *
linux shell 批量转换文件名大小写
rename 'y/A-Z/a-z/' *
(反着写就是小写变大写)
linux shell 删除所有文件的后缀名
rename 's/.csv//' *
或者
rename 's/\.bak$//' *.bak
linux shell 给所有文件添加后缀名
rename 's/$/\.txt/' *
linux shell 在所有文件名前添加某个字符串
rename 's/^/const/' *
hexdump 十六进制输出数据
echo -ne "const.net.cn" |hexdump -C
00000000 63 6f 6e 73 74 2e 6e 65 74 2e 63 6e |const.net.cn|
0000000c
echo -ne "const.net.cn" |hexdump -e '16/1 "%02X " "\n"'
63 6F 6E 73 74 2E 6E 65 74 2E 63 6E
linux shell 执行字符串命令
cmd="echo hello word"
$cmd
或者
eval $cmd
linux shell date string
Date Format | Option Meaning | Example Output |
---|---|---|
date +%c | locale’s date time | Sat May 9 11:49:47 2020 |
date +%x | locale’s date | 05/09/20 |
date +%X | locale’s time | 11:49:47 |
date +%A | locale’s full weekday name | Saturday |
date +%B | locale’s full month name | May |
date +%m-%d-%Y | MM-DD-YYYY date format | 05-09-2020 |
date +%D | MM/DD/YY date format | 05/09/20 |
date +%F | YYYY-MM-DD date format | 2020-05-09 |
date +%T | HH:MM:SS time format | 11:44:15 |
date +%u | Day of Week | 6 |
date +%U | Week of Year with Sunday as first day of week | 18 |
date +%V | ISO Week of Year with Monday as first day of week | 19 |
date +%j | Day of Year | 130 |
date +%Z | Timezone | PDT |
date +%m | Month of year (MM) | 05 |
date +%d | Day of Month (DD) | 09 |
date +%Y | Year (YY) | 2020 |
date +%H | Hour (HH) | 11 |
date +%H | Hour (HH) in 24-hour clock format | 11 |
date +%I | Hour in 12-hour clock format | 11 |
date +%p | locale’s equivalent of AM or PM | AM |
date +%P | same as %p but in lower case | am |
date '+%F %T'
2021-12-30 16:26:50
linux 编码转换显示hexstring
echo -n d6d0b9fa |xxd -r -p |iconv -f gb2312 -t utf8
中国
echo -n 中国 |iconv -f utf8 -t gb2312 |xxd -p
d6d0b9fa
echo -n 中国 |xxd -p
e4b8ade59bbd
echo -n e4b8ade59bbd |xxd -r -p
中国
使用ss 查看网络监听连接
ss -nlput
ss -h
-h, --help this message
-V, --version output version information
-n, --numeric don't resolve service names
-r, --resolve resolve host names
-a, --all display all sockets
-l, --listening display listening sockets
-o, --options show timer information
-e, --extended show detailed socket information
-m, --memory show socket memory usage
-p, --processes show process using socket
-i, --info show internal TCP information
--tipcinfo show internal tipc socket information
-s, --summary show socket usage summary
--tos show tos and priority information
-b, --bpf show bpf filter socket information
-E, --events continually display sockets as they are destroyed
-Z, --context display process SELinux security contexts
-z, --contexts display process and socket SELinux security contexts
-N, --net switch to the specified network namespace name
-4, --ipv4 display only IP version 4 sockets
-6, --ipv6 display only IP version 6 sockets
-0, --packet display PACKET sockets
-t, --tcp display only TCP sockets
-S, --sctp display only SCTP sockets
-u, --udp display only UDP sockets
-d, --dccp display only DCCP sockets
-w, --raw display only RAW sockets
-x, --unix display only Unix domain sockets
--tipc display only TIPC sockets
--vsock display only vsock sockets
-f, --family=FAMILY display sockets of type FAMILY
FAMILY := {inet|inet6|link|unix|netlink|vsock|tipc|xdp|help}
-K, --kill forcibly close sockets, display what was closed
-H, --no-header Suppress header line
-O, --oneline socket's data printed on a single line
显示所有IP地址
ip -4 a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
2: enp0s31f6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
inet 192.168.10.8/24 brd 192.168.10.255 scope global noprefixroute enp0s31f6
valid_lft forever preferred_lft forever
inet 192.168.1.64/24 brd 192.168.1.255 scope global noprefixroute enp0s31f6
valid_lft forever preferred_lft forever
inet 192.168.3.64/24 brd 192.168.3.255 scope global noprefixroute enp0s31f6
valid_lft forever preferred_lft forever
inet 192.169.5.64/24 brd 192.169.5.255 scope global noprefixroute enp0s31f6
valid_lft forever preferred_lft forever
inet 192.168.6.64/24 brd 192.168.6.255 scope global noprefixroute enp0s31f6
valid_lft forever preferred_lft forever
inet 192.168.2.64/24 brd 192.168.2.255 scope global noprefixroute enp0s31f6
valid_lft forever preferred_lft forever
linux shell directory md5sum
使用md5sum 校验整个目录
生成md5sum.txt
find . -type f |xargs md5sum > /path/to/file/md5sum.txt
md5sum -c /path/to/file/md5sum.txt
listing md5sum for all files
Therefore you should be able to run this command to get the result you want:
find -type f -exec md5sum "{}" +
If you really want to use pipe, then you need to tell find to delimit the responses with a null and xargs to expect null delimited arguments like this:
find -type f -print0 |xargs -0 md5sum
linux shell 写一条日志记录到syslog
Log a message to your client, eg:
logger -t hello-world -s 'Hello World - 1'
获取网卡mac地址,并设置为hostname
hostname `cat /sys/class/net/eth0/address |sed 's/://g'`
iptables 自动保存
sudo apt-get install iptables-persistent
本文链接地址:https://const.net.cn/644.html