Chinaunix首页 | 论坛 | 博客
  • 博客访问: 532513
  • 博文数量: 119
  • 博客积分: 3167
  • 博客等级: 中校
  • 技术积分: 1215
  • 用 户 组: 普通用户
  • 注册时间: 2005-12-20 21:21
文章分类

全部博文(119)

文章存档

2015年(21)

2012年(4)

2011年(1)

2007年(11)

2006年(50)

2005年(32)

分类: LINUX

2005-12-20 21:49:16

find使用 和 一个递归

#file: ~/t.sh
#usage: ./t.sh /etc
#!/bin/bash

lsDir()
{
 if [ $# -lt 1 ] ;then
  echo "arguments error"
  exit 1
 fi
 local path=$1
 for var in `ls "$path"`
 do
  local subpath="${path}/${var}"
  if [ -d "${subpath}" ];then
   echo "${subpath} [directory]"
   lsDir $subpath
  elif [ -f "${subpath}" ];then
   echo "${subpath}  [FILE]"
  fi
 done
}

lsDir $1


用find替代ls
find /etc -type d | xargs ls  #结果是察看找到的目录里面的内容
find /etc -type d | xargs ls -d
find /etc -type f | xargs echo > /tmp/file   #把 /etc下面的文件名放到file
find /etc -type f -name tmp.txt | xargs cat > /tmp/a #文件内容cat到a
find /etc -path "/etc/setup" -prune -o print
find /etc -type d -exec ls -d {} ;

find / -size 0c -exec ls {} ;  #这样会把所有大小为0字节的目录里面文件都列出来
find / -size 0c -exec ls -d {} ;
find / -size 0c -exec echo {} ;

find / -size 0c | xargs echo

-perm mode:文件许可正好符合mode  #不是很明白
-perm +mode:文件许可部分符合mode
-perm -mode: 文件许可完全符合mode

阅读(1310) | 评论(0) | 转发(0) |
0

上一篇:bash中的变量 3

下一篇:用grep提取字符串

给主人留下些什么吧!~~