博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Linux常用命令组合
阅读量:4678 次
发布时间:2019-06-09

本文共 2147 字,大约阅读时间需要 7 分钟。

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' {} \;

 

11、查找并控制文件输出

find . -type f -name '*html*'|xargs grep -rils '雅思成绩'|cut -c3-|awk -F: '{ print "http://www.xxx.com.cn/zhuanti/"$1 }'

 

12、删除指定大小的文件和空目录

find . -type f -size -2k -exec rm -rf {} \;

 

find . -type d -empty|xargs rm -rf {} \;

 

13、截取组合输出内容

find . -maxdepth 1 -type d|sort|awk {'print "rm -rf /data/wiseway/" substr($1,3) "#mv /home/" substr($1,3) " /data/wiseway/"'}

 

14、根据查询结果改变目录所有人

find . -maxdepth 1 -type d -user apache -exec chown -R nobody:nobody {} \;

 

15、根据查询结果生成目录权限控制文件

find /data/wiseway -maxdepth 1 -type d -user root|sort|awk {'print "<Directory \"" $1 "\">\n\t<FilesMatch \".php\">\n\t\tOrder Allow,Deny\n\t\tDeny from all\n\t</FilesMatch>\n</Directory>"'} >>DirSecurity.conf

 

转载于:https://www.cnblogs.com/hcduguo/p/4528222.html

你可能感兴趣的文章
编译适用于TP-Link WR703N的OpenWRT固件
查看>>
Ubuntu16下编译linux内核,报"mkimage" command not found错的解决
查看>>
Nginx启动SSL功能,并进行功能优化,你看这个就足够了
查看>>
php 创建简单的Restful WebAPI(三)
查看>>
C#遍历DataSet中数据的几种方法总结
查看>>
linux tomcat安装以及配置
查看>>
Git——Git的简单介绍【一】
查看>>
Vue源码学习三 ———— Vue构造函数包装
查看>>
winform编程中的跨线程访问资源(转)
查看>>
自制操作系统Antz(5)——深入理解保护模式与进入方法
查看>>
Creating one array of strings in c fails ,why?
查看>>
POJ 3683 Priest John's Busiest Day(2-sa路径输出,4级)
查看>>
hdu 1244 Max Sum Plus Plus Plus(DP线性区间)
查看>>
4.unity3D 预设的一例
查看>>
XP Sp3 开机就要激活,否则无法登录windows桌面
查看>>
转:智能模糊测试工具 Winafl 的使用与分析
查看>>
初识 Fuzzing 工具 WinAFL
查看>>
python:学习自顶向下程序设计:竞技体育模拟
查看>>
整数中1出现的次数(important)
查看>>
【转】软件设计模式六大原则详解
查看>>