|
最近需要写个脚本查找符合条件的文件mv到指定目录下以属主命名的子目录。主要是2个步骤,1.找到符合条件的文件,2.将符合条件的文件mv到指定目录下以属主命名的子目录。
例:
我find /home -type f -name "file_*"
找到下列符合条件的文件
/home/grp1/usera/dir1/file_xuul1
/home/userb/deph1/deph2/file_asd.log
/home/grp2/userc/log3
mv文件到/home/target,mv后的文件路径如下:
/home/target/usera/file_xuul1
/home/target/userb/file_asd.log
/home/target/userc/log3
我只想到了用ls -l /home/grp1/usera/dir1/file_xuul1 | awk 这样去获取属主,然后到/home/target/下建立以属主命名的目录,然后mv文件到对应目录下。
由于符合条件的文件较多,用户也比较多,300个用户左右,符合条件的文件一般再1000个左右。
请各位帮忙想想更好效率的办法,先谢了。 |
|