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 FormatOption MeaningExample Output
date +%clocale’s date timeSat May 9 11:49:47 2020
date +%xlocale’s date05/09/20
date +%Xlocale’s time11:49:47
date +%Alocale’s full weekday nameSaturday
date +%Blocale’s full month nameMay
date +%m-%d-%YMM-DD-YYYY date format05-09-2020
date +%DMM/DD/YY date format05/09/20
date +%FYYYY-MM-DD date format2020-05-09
date +%THH:MM:SS time format11:44:15
date +%uDay of Week6
date +%UWeek of Year with Sunday as first day of week18
date +%VISO Week of Year with Monday as first day of week19
date +%jDay of Year130
date +%ZTimezonePDT
date +%mMonth of year (MM)05
date +%dDay of Month (DD)09
date +%YYear (YY)2020
date +%HHour (HH)11
date +%HHour (HH) in 24-hour clock format11
date +%IHour in 12-hour clock format11
date +%plocale’s equivalent of AM or PMAM
date +%Psame as %p but in lower caseam
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

标签: shell

添加新评论