当前位置:首页 » 编程软件 » 编程打印

编程打印

发布时间: 2025-02-19 13:32:59

1. 如何用shell编程打印出目录下的所有文件内容

1)看下面的脚本a1.sh,假设要显示目录/home/user/tmp/下面的所有的文件和(子)目录的名字:

$ cat a1.sh
#!/bin/bash

for file in /home/user/tmp/*
do
echo $file
done

2)假设目录/home/user/tmp/下面的所有的文件和(子)目录如下:

$ ls
1.txt 2.txt a1.sh a.sh b.sh email_back m1.doc tmp

3)运行脚本:
$ a1.sh (或者./a1.sh)
/home/user/tmp/1.txt
/home/user/tmp/2.txt
/home/user/tmp/a1.sh
/home/user/tmp/a.sh
/home/user/tmp/b.sh
/home/user/tmp/email_back
/home/user/tmp/m1.doc
/home/user/tmp/tmp

4)脚本a1.sh的作用只是显示文件和子目录的列表,要显示文件的内容,脚本继续改造,内容如下,看脚本a2.sh:

$ cat a2.sh
#!/bin/bash

for file in /home/shiqingd/tmp/*
do
echo $file
if [ -f $file ]; then
cat $file
fi
done

脚本a2.sh可以达到目的。

热点内容
java返回this 发布:2025-10-20 08:28:16 浏览:645
制作脚本网站 发布:2025-10-20 08:17:34 浏览:936
python中的init方法 发布:2025-10-20 08:17:33 浏览:632
图案密码什么意思 发布:2025-10-20 08:16:56 浏览:821
怎么清理微信视频缓存 发布:2025-10-20 08:12:37 浏览:731
c语言编译器怎么看执行过程 发布:2025-10-20 08:00:32 浏览:1066
邮箱如何填写发信服务器 发布:2025-10-20 07:45:27 浏览:299
shell脚本入门案例 发布:2025-10-20 07:44:45 浏览:160
怎么上传照片浏览上传 发布:2025-10-20 07:44:03 浏览:852
python股票数据获取 发布:2025-10-20 07:39:44 浏览:763