您的位置:首页 > 新闻 > 热点要闻 > bash代码片段snippets

bash代码片段snippets

2024/10/14 6:13:19 来源:https://blog.csdn.net/weixin_42849849/article/details/141599252  浏览:    关键词:bash代码片段snippets

bash代码片段


# Rename all *.txt to *.text
for file in *.txt; domv -- "$file" "${file%.txt}.text"
done
while read x z y; doof="xag.1/$x.png" if="xag/$y.png"cp $if $of	  
done < db.log 
tree -L 2 | sed 's/\xc2\xa0/ /g' > ~/Downloads/1.txt
du -sh -t 100M *

移除重复行

#整行比较
awk '!seen[$0]++' file
#第一个field比较
awk '!seen[$1]++' file

按指定field排序

#按第二个field排序
sort -k2,2 file

按起始10个字符去重复

uniq -w 10 file 

od输出二进制文件数据

od -x -v -A n --width=100 ./x.bin >od.txt

计算文本文件每行的md5

cat od.txt | perl -MDigest::MD5=md5_hex -nlE'say md5_hex($_)' >db_x.txt

文件分割

cat ../xtotal.pad | split -a 4 -d -l 52

一份文件复制两次

n=0;
for x in x*; do y=`printf "y%04d" $n` && ((n=n+1)) && cp $x $yy=`printf "y%04d" $n` && ((n=n+1)) && cp $x $y
done

生成所有文件md5sum

md5sum x*

ffmpeg批量提取多个视频中图像

 n=1; for x in round.0/*;do echo $x;  fmt=frame${n}.%04d.png; ffmpeg -i $x -vf "fps=2" $fmt; ((n=n+1)); done

printout.sh

#!/bin/bashhexpattern="0-9a-f"
pattern='$LZSKGHVRMTBCDEF'
input=$1cat $input | sed 's/\s//g' | tr $hexpattern $pattern  | awk  'BEGIN{print} {print " ", $0}'

padding.pl

#!/usr/bin/perl$pad='9999';
$nword_per_line=50;
$nline_per_page=52;$num_of_lines=0;
while(<>)
{@array=split;$nword=@array;while($nword < $nword_per_line){push(@array,$pad);$nword+=1;}$str=join(" ",@array);print $str,"\n";$num_of_lines+=1;
}while($num_of_lines%$nline_per_page)
{print $str, "\n";$num_of_lines+=1;
}

dispatch.sh

#!/bin/bash#set -xfor((n=0;n<200;n+=20)); do((s=n))((e=n+19))d=`printf '%03d-%03d\n' $s $e`[ -e $d ] && rm -rf $d && echo "delete $d"mkdir -p $dfor ((i=s;i<=e;i++));dox=`printf 'x%03d\n' $i`[ -e $x ] || exitmv $x $d/.done
done

find path prune

find . -path './backup/*' -prune -o -path './.git/*' -prune -o type f -o -iname '*.f90' | xargs wc -l | sort -n 

数字列表

for f in x00{01..11};do echo $f 
done for f in x00{1..9}{a..b};do echo $f
done 

单个字符匹配(glob-expansion)

#!/bin/bashecho "Matching Directories:"for dir in [p-xP-X]*; doif [ -d "$dir" ]; thenls -d "$dir"fi
done

watch

watch tail -n 15 mylogfile.txt

tee

#stdout&stderr重定向到tee 
xxxx |& tee run.loog 

cygpath

cygpath "D:\xxxx"
网络资源

Awesome Bash

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com