shell怎么把某个目录下的所有文件名记录到一个文本中,然后把非空的文件拷贝到另一目录

shell怎么把某个目录下的所有文件名记录到一个文本中,然后把非空的文件拷贝到另一目录

查看当前目录下的文件:
find . -type f

查看当前目录下的文件夹:
find . -type d

如果文件file1不为空:
if [ -s file1 ];then
     echo "file1 不为空"
fi

最后大概是这么写,路径楼主自己改一下:

Python code?12345678910111213 #!/bin/sh   for f in `find ./testdir -type f`; do         if [ -s $f ];then                 echo $f is not empty.                 echo copy $f                 cp $f ~/backup         else                echo $f is empty.         fi done
#!/bin/bash find /etc -type f > list.txt while read line; do     size=$(ls -l $line | awk '{print $5}')     if [[ $size != 0 ]]; then         cp $line /tmp/     fi done < list.txt

find /etc -type f | nl > urfile

Copyright © 2007-2012 www.chuibin.com 六维论文网 版权所有