不定期更新学习到的Linux 脚本及命令
- 统计当前文件夹下的cpp代码行数
find ./ -name '*.cpp' | xargs cat | grep -v ^$ |wc -l
输出为一个数,表示非空行的代码行数
如果文件名中带有空格,那么使用cat
命令会将空格拆开,导致文件读取错误,所以要用引号将文件名括起来,使用sed
命令可以替换字符串
find ./ -name '*.cpp' | sed "s/.*$/'&'/g" | xargs cat |grep -v '^$'| wc -l
使用sed
前管道输出为
./19. Remove Nth Node From End of List/一次遍历.cpp
./19. Remove Nth Node From End of List/顺序计数遍历.cpp
使用sed
后替换为
'./19. Remove Nth Node From End of List/一次遍历.cpp'
'./19. Remove Nth Node From End of List/顺序计数遍历.cpp'
其它语言代码同理
tree
命令能生成目录结构或目录下的文件结构,这个命令我是在Windows cmd下学到的,cmd下tree
命令的部分使用为
列出目录结构
>tree
H:.
├─models
└─题目二
├─体育
├─娱乐
└─科技
列出目录下的文件结构
>tree /f
H:.
│
├─models
│ model.svm
│
└─题目二
│ test.txt
│
├─体育
│ 0.txt
│ 0seg.txt
│
├─娱乐
│ 0.txt
│ 0seg.txt
│
└─科技
0.txt
0seg.txt
Linux下也有tree
命令,功能与Windows下的类似,我便不再逐一列出了
- 其余许多管道命令,需要一点点积累