shell编程: 获得目录下(包括子目录)所有文件名,路径和文件大小
2015-09-11 15:41
906 查看
要获得目录下(包括子目录)所有文件名,路径和文件大小用shell应该是最简便的
shell脚本: lsdir.sh
#!/bin/bash
function ergodic(){
for file in `ls $1`
do
if [ -d $1"/"$file ]
then
ergodic $1"/"$file
else
local path=$1"/"$file
local name=$file
local size=`du --max-depth=1 $path|awk '{print $1}'`
echo $name $size $path
fi
done
}
IFS=$'\n' #这个必须要,否则会在文件名中有空格时出错
INIT_PATH=".";
ergodic $INIT_PATH
shell脚本: lsdir.sh
#!/bin/bash
function ergodic(){
for file in `ls $1`
do
if [ -d $1"/"$file ]
then
ergodic $1"/"$file
else
local path=$1"/"$file
local name=$file
local size=`du --max-depth=1 $path|awk '{print $1}'`
echo $name $size $path
fi
done
}
IFS=$'\n' #这个必须要,否则会在文件名中有空格时出错
INIT_PATH=".";
ergodic $INIT_PATH
#!/bin/bash function ergodic(){ for file in `ls $1` do if [ -d $1"/"$file ] then ergodic $1"/"$file else local path=$1"/"$file echo $path fi done } IFS=$'\n' INIT_PATH="`pwd`"; ergodic $INIT_PATH
相关文章推荐
- Linux重新学习--shell--正则表达式
- 在.bashrc文件中定义函数
- Amazon EC2 vps申请和shell登录方法
- [SuperM]Shell编程课堂笔记+PPT总结
- shell script创建库
- Shell之-获取tomcat_Log
- Linux Shell 脚本中字符串的连接方法
- 常用的也是最容易忘记的Shell知识
- linux shell数组赋值方法(常用)
- shell按行读取文件的3种方法
- shell script数组使用函数输出
- 收集整理比较全 shell sed 命令与实例教程
- shell实现多进程,对数据库进行备份。
- php最短一句话后门webshell
- Shell脚本-良好的习惯
- jenkins 通过shell启动java应用程序会随着job完成而被自动关闭的解决方法
- Android系统在超级终端下必会的命令大全(adb shell命令大全)
- shell 自动执行参数脚本并判断(一个折腾的下午)
- Bash基础
- Android 设备,如何root,执行adb shell,查看设备中的数据库信息等