[英]Linux Sed -e argument
I have the following command in my backup rotate script to remove old backups. 我的备份旋转脚本中有以下命令,以删除旧的备份。 It works as it ensure the latest backup is retained. 它可以确保保留最新备份,因此可以正常工作。
ls -t | sed -e '1,1d' | xargs -d '\n' rm
I'm unsure of the sed -e
argument is doing though. 我不确定sed -e
参数是否正在执行。 When I check man sed
I get: 当我检查man sed
我得到:
-e script, --expression=script -e脚本,--expression =脚本
add the script to the commands to be executed
I can't find details of what my current script argument '1,1d'
is attempting to do. 我找不到我当前的脚本参数'1,1d'
正在尝试执行的操作的详细信息。 Can anyone help? 有人可以帮忙吗?
d
elete lines 1
to 1
. d
elete线1
至1
。 It just removes the first line. 它只是删除第一行。
For testing, type: 要进行测试,请键入:
seq 10
vs. 与
seq 10 | sed -e '1,1d'
-e script
is adding the script to the sed-command-list. -e script
添加到sed-command-list。 script
is used here as synonym for string, in difference to script-file in the option -f script-file
. script
在这里用作字符串的同义词,与选项-f script-file
文件中的-f script-file
。 That's why the argument is usually put into quotes (which could be omitted here). 这就是为什么该参数通常用引号引起来(可以在此处省略)。 The script/string may inlcude a sequence of commands. 脚本/字符串可以包括一系列命令。
You may use more then one -e '<sed-cmd>'
, which are then applied to the input line in sequence. 您可以使用多个-e '<sed-cmd>'
,然后依次将它们应用于输入行。 For example sed -e 's/kitty/cat/g' -e 's/cat/lion/g'
. 例如sed -e 's/kitty/cat/g' -e 's/cat/lion/g'
。 Sometimes it is easier to understand where all the lions came from. 有时更容易理解所有狮子的来源。
d
is one of the commands which accept address ranges. d
是接受地址范围的命令之一。 1,1
is the address range, here from line 1 to line1, which could be shortened to 1d
1,1
是地址范围,从第1行到第1行,可以缩短为1d
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.