当工作文件和需求过多时,需要各种命令配合使用:
1.rm 删除不满足条件的文件
rm -r !(data) #删除不满足条件的文件,删除data以外的文件
rm -rf !(file1|file2) #删除file1 和file2以外的文件
ls | grep -v keep | xargs rm #删除keep文件之外的所有文件
find ./test/ | grep -v keep | xargs rm #删除当前test文件夹中keep文件之外的所有文件
2.显示当前目录的绝对路径
ls `pwd`/file #显示file的绝对路径
3.查看zip
zipinfo file.zip
4.删掉尾部两行
head -n -2 a.txt
从第六行开始显示
tail -n +6 a.txt
5.在文件首行加一行
sed -e '1i 2add pdf' filter.contig.coverage.result |less
sed -n '1~2p' a.txt #提取奇数行
sed -n '0~2p' a.txt #提取偶数行
6.给指定人开权限
setfacl -R -m u:账户名:rwx ./
6.统计文件数量(参考地址现在不见了???哎):
find . -maxdepth 1 -type d | while read dir; do count=$(find "$dir" -type f | wc -l); echo "$dir : $count"; done >file_stat
-maxdepth 1 过滤目录的深度
-type d 文件类型为目录
-type f 文件类型为文件
7.grep -v 排除多个输出结果:
grep test somefile | grep -v -e error -e critical -e warning
grep test somefile | grep -vE '(error|critical|warning)'
grep test somefile | grep -vE 'error|critical|warning'
8.grep 查找多个输出结果: egrep相当于grep -E。
grep -E 'CDS|exon|gene' test.gff3
grep -v "CDS\|exon\|gene' test.gff3
9.递归替换文件名
sed -i "s/zhangsan/lisi/g" `grep zhangsan -rl /modules`
sed -i.bak 's/a/b/g' a.txt #sed 之后备份
10.fa转单行
les *fa|perl -e '{$/=">";<>;while (<>){chomp;($id,$seq)=split /\n/,$_,2;$seq=~s/\n//g;print ">$id\n$seq\n";}}' >fmt.fa
网友评论