Linux命令随记

来自三线的随记

记一些容易忘掉的组合命令。。太杂碎不适宜单开页面

命令参数简要使用

find -type f -size +10M -exec ls -lh {} \;

ls /dev/sd{a,b}

使用grep去过滤一些- (hyphen) 开头的字符串

echo "--123" | grep -- --123

原理:

--
Delimit the option list. Later arguments, if any, are treated as operands even if they begin with ‘-’. For example, ‘grep PAT -- -file1 file2’ searches for the pattern PAT in the files named -file1 and file2.

使用 jq 命令只取第一层key name

jq 'keys' config.json

使用jq配合storcli命令获取raid虚拟磁盘名字或者定位os盘名字

定位方法: https://www.superweb999.com/article/654883.html (DG/VD就是 raid的卷组/系统里卷组的顺序 对应关系)

storcli /c0 /vall show J | jq '(.Controllers[]."Response Data"."Virtual Drives"[])'|jq 'select(.Name == "OTHER_RAID0")'
storcli /c0 /vall show J | jq '(.Controllers[]."Response Data"."Virtual Drives")

在使用ssh-copy-id命令设置公钥免密的时候同时指定会话加密算法

ssh-copy-id -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o "Ciphers=aes256-cbc" -i ~/.ssh/key-file [email protected]

Linux 音频架构ALSA中的Alsa工具

显示的是当前所有可用的麦克风设备:

pi@raspberrypi:~ $ arecord -l

**** List of CAPTURE Hardware Devices ****

card 1: CameraB409241 [USB Camera-B4.09.24.1], device 0: USB Audio [USB Audio]

  Subdevices: 1/1

  Subdevice #0: subdevice #0

显示的是当前所有可用的音频输出设备

pi@raspberrypi:~ $ aplay -l

**** List of PLAYBACK Hardware Devices ****

card 0: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]

  Subdevices: 8/8

  Subdevice #0: subdevice #0

  Subdevice #1: subdevice #1

  Subdevice #2: subdevice #2

  Subdevice #3: subdevice #3

  Subdevice #4: subdevice #4

  Subdevice #5: subdevice #5

  Subdevice #6: subdevice #6

  Subdevice #7: subdevice #7

card 0: ALSA [bcm2835 ALSA], device 1: bcm2835 ALSA [bcm2835 IEC958/HDMI]

  Subdevices: 1/1

  Subdevice #0: subdevice #0

apt-get install sox libsox-fmt-all

libsox-fmt-all包含mp3的解码器和其它格式的解码器。

播放音乐:

$ play Crystals.mp3
systemctl daemon-reload

大括号扩展 - 理论

Bash 有个功能叫大括号扩展,大括号包围的,用逗号隔开的参数会扩展为独立的多个参数。
花括号用来匹配一组用逗号分隔的字符串中的任一个。左花括号之前的所有字符称为前文(preamble),右花括号之后的所有字符称为后文(preamble)。前文和后文都是可选的。花括号中不能包含不加引号的空白符。
PS: 按照百(bai)度(du)的说法,这个叫做大括号-> {},但是他也叫做花括号

大括号扩展 - 实验记录

使用 ls 命令配合测试大括号扩展特性1

前提: touch test1 test2 test3 test4 test10

预期结果: test1 test2 test3 test4 test10 be showed

ls
ls test[1,4] test1 test4 ×
ls test[1,10] test1 ×
ls test[1-4] test1 test2 test3 test4
ls test[1-9] test1 test2 test3 test4
ls test[1-10] test1 ×
ls test{1,9} ls: cannot access 'test9': No such file or directory

test1

×
ls test{1,4} test1  test4 x
ls test{1-9} ls: cannot access 'test{1-9}': No such file or directory x
ls test{1-10} ls: cannot access 'test{1-10}': No such file or directory x
going to completed


使用 ls 命令配合测试大括号扩展特性2

前提: touch testa testb testc testd

预期结果: testa testb testc testd be showed

ls
ls test[a,d] testa  testd ×
ls test[a-d] testa  testb  testc  testd
ls test[a-e] testa  testb  testc  testd
ls test{a,d} testa  testd ×
ls test{a,e} ls: cannot access 'teste': No such file or directory

testa

×
ls test{a-d} ls test{a-d}

ls: cannot access 'test{a-d}': No such file or directory

x
ls test{a-e} ls test{a-e}

ls: cannot access 'test{a-e}': No such file or directory

x
going to completed


使用 touch 命令配合测试大括号扩展特性1

预期结果: touch testa testb testc testd

实验结果:

touch
touch test[a,d] 只有 test[a,d] 文件 ×
touch test[a-d] 只有 test[a-d] 文件 ×
touch test{a-d} 只有 test{a-d}文件 ×
touch test{a,d} 有testa, testd文件 ××

使用 touch 命令配合测试大括号扩展特性2

预期结果: touch test1 test2 test3 test4

实验结果:

touch
touch test[1,4] 只有 test[1,4] 文件 ×
touch test[1-4] 只有 test[1-4] 文件 ×
touch test{a-d} 只有 test{1-4}文件 ×
touch test{a,d} 有test1, test4文件 ××

????????going to completed