Linux常用命令组合

时间:2023-03-09 04:52:22
Linux常用命令组合

1、删除除某个文件或文件夹外的所有的内容

ll |grep -v test |xargs rm -rf

find . -maxdepth 1 -type d|grep -v test|xargs rm -rf '{}' \;

find . -maxdepth 1|grep -v test |xargs rm -rf '{}' \;

2、复制当前目录下所有目录到其父目录

find . -maxdepth 1 -type d -exec \cp -rf '{}' ../ \;

3、移动当前目录至目标目录

find . -maxdepth 1 -type d -exec mv '{}' /data/web \;

4、删除当前目录下所有的文件

find . -maxdepth 1 -type f -exec rm -rf '{}' \;

ll|grep 'xxx'|awk '{print $9}'|xargs rm -rf

5、查找文件中是否存在某些字符串中的一个或多个

find . -type f |xargs grep  -ril  -E 'passthru|exec|system|chroot|scandir|chgrp|chown';

6.xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option

find . -type f -print0 |xargs -0 grep -ri 'parse_template'

7.指定删除(只在当前目录执行)

find . -maxdepth 1 -type d|egrep -v '(story|cost|visa|.)'|xargs -exec rm -rf {} \;

find . -maxdepth 1 -type d|egrep -v '(case|download|experience|guid|guidance|guide|machine|news)'|xargs -exec rm -rf {} \;

find . -type f -print0|xargs -0 egrep -ril "maimai"|xargs -i cp {} /data/bugs/150726

find . -type f -name "*.inc.php" -exec cp {} /data/bugs/150726 \;

8.移动数据到指定目录(DISCUZ升级)

mv `ls|egrep -v "data|config|uc_client|uc_server|old"` /data/bbs/old/

9.批量转换文件格式

find . -type d -exec mkdir -p /data/utf/{} \;  //将当前目录结构批量生成到/data/utf中
find . -type f -exec iconv -f GBK -t UTF-8 {} -o /data/utf/{} \; //将转换好的文件存入/data/utf中

10.查找替换文件

find /data/web/ -type f -exec sed -i 's#www.xxx.org#demo.xxx.org#g' {} \;