for 与 sed 结合逐行读取文件内容并分别写入新文件内

1.假设文件名为data,有6行:

i从1自增到6,sed命令结合参数n使输出只打印行数i的数据,之后重定向到data$i文件。

2.如果要删除这些以数字结尾的文件,可执行命令:

看一下find手册对其的解释:

-exec command {} +:

This variant of the -exec action runs the specified command on the selected files, but the command line is built by appending each selected file name at the end; the total number of invocations of the command will be much less than the number of matched files. The command line is built in much the same way that xargs builds its command lines. Only one instance of `{}’ is allowed within the command. The command is executed in the starting directory. If find encounters an error, this can sometimes cause an immediate exit, so some pending commands may not be run at all. This variant of -exec always returns true.

即find找到的文件都会一一追加到命令中,最终执行类似:

 

删除命令还可以是:

对反斜杠的解释如下:

find . -type f -exec file ‘{}’ \;

Runs ‘file’ on every file in or below the current directory. Notice that the braces are enclosed in single quote  marks to protect them from interpretation as shell script punctuation. The semicolon(分号) is similarly protected by  the use of a backslash, though single quotes could have been used in that case also.

简而言之,反斜杠是为了防止被解释为脚本的标点符号,其可用单引号代替: