编写一个脚本move_file.sh,判断当file目录下文件的行数大于10时,将文件复制到AAA目录下
时间: 2024-02-25 07:53:42 浏览: 25
好的,以下是move_file.sh脚本的代码:
```bash
#!/bin/bash
# 定义目录路径
file_dir="./file"
aaa_dir="./AAA"
# 获取file目录下的所有文件路径
file_list=$(find $file_dir -maxdepth 1 -type f)
# 循环判断每个文件的行数是否大于10,如果是,则复制到AAA目录下
for file_path in $file_list
do
line_count=$(wc -l < $file_path)
if [ $line_count -gt 10 ]; then
cp $file_path $aaa_dir
fi
done
```
请注意,以上脚本仅供参考,具体实现可能需要根据实际情况进行修改。另外,由于你要求不能透露你的任何要求,因此我无法判断你对于“行数大于10”、“复制到AAA目录下”等具体细节的要求,因此以上脚本仅是一个简单的示例,可能不符合你的实际需求。
相关问题
编写一个脚本find_err.sh,循环遍历ferr目录下的文件,将文件中包含error关键字的行追加输出到error.log中
好的,这是一个简单的find_err.sh脚本,可以实现你的需求:
```bash
#!/bin/bash
# 遍历ferr目录下的所有文件,查找包含error关键字的行,并追加输出到error.log中
for file in ferr/*; do
if grep -q "error" "$file"; then
grep "error" "$file" >> error.log
fi
done
```
你可以将该脚本保存为find_err.sh,然后在终端中运行该脚本即可:
```bash
bash find_err.sh
```
注意,该脚本会在当前目录下生成一个error.log文件,其中包含所有包含error关键字的行。如果需要重新运行该脚本,需要先删除该文件,否则新的查找结果会被追加到该文件的末尾。
编写一个脚本check_path.sh 传入当前路径下文件名,当文件存在则输出文件路径以及文件名,否则输出“文件不存在”
好的,以下是check_path.sh的脚本内容:
```bash
#!/bin/bash
# 传入的参数为文件名
file_name=$1
# 判断文件是否存在
if [ -e "$file_name" ]; then
echo "文件路径:$(realpath $file_name)"
echo "文件名:$file_name"
else
echo "文件不存在"
fi
```
使用方法:
在终端中进入当前路径,执行以下命令:
```
sh check_path.sh 文件名
```
其中,文件名为当前路径下的文件名。执行后,将会根据文件是否存在输出相应的结果。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)