Open LingYanSi opened 3 years ago
按照文件大小对文件进行排序,-sk表示显示文件的kb,sort -n 表示按照文件名排序
find src | grep -E "\.(js)$" | xargs du -sk | sort -n
倒序输出
find src | grep -E "\.(js)$" | xargs du -sk | sort -n | tail
获取cpu信息 cat /proc/cpuinfo
-R
遍历所有文件-h
不输出文件路径-o
只输出匹配到的内容-E
使用正则匹配获取指定文件件下的所有域名地址
grep -RhoE "https?://[^/?'\"$]+" src | sort | uniq
包工头查看指定分支、指定时间后,commit提交人数排行,不能代表一切但有一定的价值
git log --format='%an' --after="2021-01-01" | sort | uniq -c | sort
mac命令复制到剪切板 pbcopy
,与其对应的是 pbpaste
cat search.log | cat | sort -V | pbcopy
在mac中请不要使用系统自带的sed命令,转而使用gun-sed,安装命令为 brew install gnu-sed,然后调用gsed
系统自带的sed在使用 sed -i
的时候会出现不符合预期的问题(与tldr sed上的文档不一致)
- Replace the first occurrence of a string in a file, and print the result:
sed 's/find/replace/' filename
- Replace all occurrences of an extended regular expression in a file:
sed -E 's/regex/replace/g' filename
- Replace all occurrences of a string in a file, overwriting the file (i.e. in-place):
sed --in-place='' 's/find/replace/g' filename
- Replace only on lines matching the line pattern:
sed '/line_pattern/s/find/replace/' filename
- Print only text between n-th line till the next empty line:
sed -n 'line_number,/^$/p' filename
- Apply multiple find-replace expressions to a file:
sed -e 's/find/replace/' -e 's/find/replace/' filename
- Replace separator / by any other character not used in the find or replace patterns, e.g., #:
sed 's#find#replace#' filename
背景:想替换一个文件内的 \/\/
字符串,发现踩进一个坑里面了。
const url1 = 'https:\/\/www.exx.com'
execSync(`find tmp | grep -E '\\.(js|css|html|php)' | xargs gsed -i 's#${url1}#xxxx#' `, { stdio: 'inherit' })
按照上面的写法,无论如何也无法替换成功,很着迷。仔细思考了一下,其实还是转译字符的问题
需要注意转译字符
首先在js字符串中 \ 需要表示为 \\
在bash中同理 \ 需要表示为 \\
那么在js字符串中的bash命令的\ 需要写成 \\\\ 四倍的快乐,谁用谁知道
如果直接调用一个shell脚本就没有这么多事情了
const url = 'https://www.exx.com'
execSync(`find tmp | grep -E '\\.(js|css|html|php)' | xargs gsed -i 's#${url}#xxxx#g' `, { stdio: 'inherit' })
const url1 = 'https:\\\\/\\\\/www.exx.com'
execSync(`find tmp | grep -E '\\.(js|css|html|php)' | xargs gsed -i 's#${url1}#xxxx#' `, { stdio: 'inherit' })
ps:
对于sed,见上面的文档。其不是按照/
来进行分割的,而是根据s后面的一个字符作为分割字符,一般书写为s/old/new/
形式,但其实也可以写成s#olf#new#
或者 s$old$new$
cp
是无法满足需求的,可以使用rsync
代替。rsync
不仅可以用在不同服务间同步文件,也可以本机上同步文件
rsync -av icp/* icp-xx/ --exclude .git
find src | grep -Ei "/view.js$" | xargs grep -Eoh '^allPage\[[^]]+' | awk -F "[\"']" '{print $2}' | sort | uniq -n
对单引号添加\
是不行的 '["\']'
,必须换个姿势对"
添加\
\t
awk '{print $1}'
awk -F '[,]' 'print $1'
$@
= stores all the arguments in a list of string
$*
= stores all the arguments as a single string
$#
= stores the number of arguments
$0
current script absolute path
$1
first arguments
$2
second arguments
define a list, you can use it as $@
list=(src app-*)
单行输出文本信息,需要注意的是的需要在结尾处输出
echo -ne 'something \r';
sleep 1
echo -ne 'something1 \r';
sleep 1
echo 'something done';
使用dirname方法可以获取指定文件路径的父级文件夹路径
BASEDIR=$(dirname "$0")
echo "$BASEDIR"
获取某个文件夹下某种类型文件的大小
获取某种类型文件的个数