标题:find命令详解,实例查看当前目录文件总数 出处:刘新修 时间:Tue, 10 Sep 2013 23:43:54 +0000 作者:刘新修 地址:http://liuxinxiu.com:80/linux-find/ 内容: 查看当前目录文件总数: [root@vps 1010 shellimage]#find . -type f |wc -l 上面这个是查看当前目录文件总数,如果是要查看指定目录的总数则: [root@vps 1010 shellimage]#find /uploadimages -type f |wc -l 这里的f是表示文件,改成d则表示目录. ********************************************************************************** 1:查找文件find . -type f -name "*.html"|xargs grep ‘yourstring’2:查找并替换find -name '要查找的文件名' | xargs perl -pi -e 's|被替换的字符串|替换后的字符串|g'下面这个例子就是将当前目录及所有子目录下的所有*.shtml文件中的”“替换为”(空)“.find . -type f -name "*.shtml"|xargs perl -pi -e 's|| |g'这里用到了Perl语言,perl -pi -e在Perl 命令中加上-e 选项,后跟一行代码,那它就会像运行一个普通的Perl 脚本那样运行该代码.从命令行中使用Perl 能够帮助实现一些强大的、实时的转换。认真研究正则表达式,并正确地使用,将会为您省去大量的手工编辑工作。 3:批量修改文件夹权限 find . -type -d -name *.html|xargs chmod 755 4:批量修改文件权限 find . -type -f -name *.html|xargs chmod 644 一些其它参考 find -name april* 在当前目录下查找以april开始的文件 find -name april* fprint file 在当前目录下查找以april开始的文件,并把结果输出到file中 find -name ap* -o -name may* 查找以ap或may开头的文件 find /mnt -name tom.txt -ftype vfat 在/mnt下查找名称为tom.txt且文件系统类型为vfat的文件 find /mnt -name t.txt ! -ftype vfat 在/mnt下查找名称为tom.txt且文件系统类型不为vfat的文件 find /tmp -name wa* -type l 在/tmp下查找名为wa开头且类型为符号链接的文件 find /home -mtime -2 在/home下查最近两天内改动过的文件 find /home -atime -1 查1天之内被存取过的文件 find /home -mmin +60 在/home下查60分钟前改动过的文件 find /home -amin +30 查最近30分钟前被存取过的文件 find /etc -name 'srm*' 查找/etc 下以srm打头的文件 find ./ -name "*.php" | xargs grep '关键字' 查找当前目录下面所有的php文件里面某个关键字 Generated by Bo-blog 2.1.1 Release