Linux Command Tips

1.delete all executable files under certain directory

find /directory -type f -executable -delete

or

find /directory  -type f -executable -exec rm -f {} \;

Above command will delete the executable files in sub-directory.

To specifically delete all executable files in your home directory (not in sub-directories) and ask you whether you want to delete each file you can do something like

find ~ -type f -executable -maxdepth 0 -exec rm -i {} \;

 

2.删除子目录下所有后缀名相同的文件

//以 .cpp为例
find -name "*.cpp" | xargs rm
  • find命令将在当前目录下查找子目录与文件,查找结果包含符合条件的子目录和当前目录及子目录的文件(search for files in a directory hierarch)
  • xargs命令是给其他命令传递参数的一个过滤器,也是组合多个命令的一个工具。它擅长将标准输入数据转换成命令行参数,xargs能够处理管道或者stdin并将其转换成特定命令的命令参数。
posted @ 2015-05-13 23:25  fosmj  阅读(155)  评论(0编辑  收藏  举报