first commit
This commit is contained in:
11
content/deepin折腾笔记/第十一章/11.1.md
Executable file
11
content/deepin折腾笔记/第十一章/11.1.md
Executable file
@@ -0,0 +1,11 @@
|
||||
# 11.1 以管理员身份自启动
|
||||
|
||||
1 编辑 ~/.profile 添加下面三行内容:
|
||||
|
||||
2 sudo -S rmmod pcspkr <<EOF
|
||||
|
||||
3 password(你的密码)
|
||||
|
||||
4 EOF
|
||||
|
||||
5 在Shell脚本中,通常将EOF与 << 结合使用,表示后续的输入作为子命令或子Shell的输入直到遇到EOF为止,再返回到主Shell,即将‘你的密码’当做命令的输入。
|
||||
5
content/deepin折腾笔记/第十一章/11.10.md
Executable file
5
content/deepin折腾笔记/第十一章/11.10.md
Executable file
@@ -0,0 +1,5 @@
|
||||
# 11.10 为指定类型文件设置可执行权限
|
||||
|
||||
1 find . -name 'commit-msg' -type f -exec chmod +x {} \;
|
||||
|
||||
2 find . -name '*.sh' -type f -exec chmod +x {} \;
|
||||
5
content/deepin折腾笔记/第十一章/11.11.md
Executable file
5
content/deepin折腾笔记/第十一章/11.11.md
Executable file
@@ -0,0 +1,5 @@
|
||||
# 11.11 获取脚本文件所在路径
|
||||
|
||||
1 包含文件:$0
|
||||
|
||||
2 只要路径:`dirname "$0"`
|
||||
13
content/deepin折腾笔记/第十一章/11.12.md
Executable file
13
content/deepin折腾笔记/第十一章/11.12.md
Executable file
@@ -0,0 +1,13 @@
|
||||
# 11.12 批量文本替换
|
||||
|
||||
1 grep "old" -rl ./ |xargs sed -i "s/old/new/g"
|
||||
|
||||
2 grep "Objbase.h" -rl . --include=*.cpp --include=*.h |xargs sed -i "s/Objbase.h/objbase.h/g"
|
||||
|
||||
3 或:sed -i "s/原字符串/新字符串/g" `grep 原字符串 -rl 所在目录
|
||||
|
||||
4 或:sed -i 's|ftp://old.url/|ftp://new.url/|g' some/filepath
|
||||
|
||||
5 举例:
|
||||
|
||||
6 grep "图像" -rl . --include=*.tex |xargs sed -i "s/图像/图象/g"
|
||||
5
content/deepin折腾笔记/第十一章/11.13.md
Executable file
5
content/deepin折腾笔记/第十一章/11.13.md
Executable file
@@ -0,0 +1,5 @@
|
||||
# 11.13 获取 CPU 个数并四则运算后导出环境变量
|
||||
|
||||
1 export MAKE_JOBS=$(echo $(nproc)-1|bc)
|
||||
|
||||
2 应用:make -j $MAKE_JOBS
|
||||
7
content/deepin折腾笔记/第十一章/11.14.md
Executable file
7
content/deepin折腾笔记/第十一章/11.14.md
Executable file
@@ -0,0 +1,7 @@
|
||||
# 11.14 命令行解压缩到指定目录
|
||||
|
||||
1 tar xvf XXX.tar.xz -C /opt
|
||||
|
||||
2 不需要添加J选项,tar会根据压缩包名称识别压缩包格式。
|
||||
|
||||
3 所以xvf应该可以作为万能参数了。
|
||||
3
content/deepin折腾笔记/第十一章/11.15.md
Executable file
3
content/deepin折腾笔记/第十一章/11.15.md
Executable file
@@ -0,0 +1,3 @@
|
||||
# 11.15 通过 git 实现跨平台的 grep 用法
|
||||
|
||||
1 git grep -li pkgconfig -- \*.pr?
|
||||
3
content/deepin折腾笔记/第十一章/11.16.md
Executable file
3
content/deepin折腾笔记/第十一章/11.16.md
Executable file
@@ -0,0 +1,3 @@
|
||||
# 11.16 打印当前目录路径
|
||||
|
||||
1 pwd
|
||||
7
content/deepin折腾笔记/第十一章/11.17.md
Executable file
7
content/deepin折腾笔记/第十一章/11.17.md
Executable file
@@ -0,0 +1,7 @@
|
||||
# 11.17 初始化当前用户配置
|
||||
|
||||
1 执行此命令前,请一定要谨慎!请一定要明白你在做什么!
|
||||
|
||||
2 rm -r ~/.*
|
||||
|
||||
3 重启。
|
||||
7
content/deepin折腾笔记/第十一章/11.18.md
Executable file
7
content/deepin折腾笔记/第十一章/11.18.md
Executable file
@@ -0,0 +1,7 @@
|
||||
# 11.18 初始化 root 用户配置
|
||||
|
||||
1 执行此命令前,请一定要谨慎!请一定要明白你在做什么!
|
||||
|
||||
2 sudo rm -r /root
|
||||
|
||||
3 重启。
|
||||
5
content/deepin折腾笔记/第十一章/11.19.md
Executable file
5
content/deepin折腾笔记/第十一章/11.19.md
Executable file
@@ -0,0 +1,5 @@
|
||||
# 11.19 查询命令软链接
|
||||
|
||||
1 例如:ls -l $(which gcc)
|
||||
|
||||
2 显示:lrwxrwxrwx 1 root root 5 9月 17 22:14 /usr/bin/gcc -> gcc-6
|
||||
5
content/deepin折腾笔记/第十一章/11.2.md
Executable file
5
content/deepin折腾笔记/第十一章/11.2.md
Executable file
@@ -0,0 +1,5 @@
|
||||
# 11.2 递归更改文件所有者
|
||||
|
||||
1 sudo chown -R <用户名>:<用户名> *
|
||||
|
||||
2 find . -exec sudo chown <用户名>:<用户名> {} \;
|
||||
11
content/deepin折腾笔记/第十一章/11.20.md
Executable file
11
content/deepin折腾笔记/第十一章/11.20.md
Executable file
@@ -0,0 +1,11 @@
|
||||
# 11.20 top 命令技巧
|
||||
|
||||
1 top是一个常见的进程查看命令,在top运行界面按下h可查看帮助。
|
||||
|
||||
2 按下1:查看各CPU占用率。
|
||||
|
||||
3 按下m:查看内存使用情况。
|
||||
|
||||
4 按下c:查看命令详细路径。
|
||||
|
||||
5 按下L:搜索进程。
|
||||
5
content/deepin折腾笔记/第十一章/11.21.md
Executable file
5
content/deepin折腾笔记/第十一章/11.21.md
Executable file
@@ -0,0 +1,5 @@
|
||||
# 11.21 查看指定行的内容
|
||||
|
||||
1 查看第3行至第5行共3行:sed -n 3,5p /etc/default/grub
|
||||
|
||||
2 查看第3行和第5行共2行:sed -n "3p;5p" /etc/default/grub
|
||||
5
content/deepin折腾笔记/第十一章/11.22.md
Executable file
5
content/deepin折腾笔记/第十一章/11.22.md
Executable file
@@ -0,0 +1,5 @@
|
||||
# 11.22 搜索匹配多个关键词
|
||||
|
||||
1 区分大小写:lspci |egrep "VGA |3D"
|
||||
|
||||
2 不区分大小写:lspci |egrep -i "vga |3d"
|
||||
17
content/deepin折腾笔记/第十一章/11.23.md
Executable file
17
content/deepin折腾笔记/第十一章/11.23.md
Executable file
@@ -0,0 +1,17 @@
|
||||
# 11.23 字符串截取
|
||||
|
||||
1 以str变量为例:str=gmp-6.1.0.tar.bz2
|
||||
|
||||
2 echo ${str} |cut -d '-' -f 1 #以 ‘-’分隔,输出第1列gmp
|
||||
|
||||
3 echo ${str%%-*} #以 ‘-’分隔,最大限度从前面截取字符串gmp
|
||||
|
||||
4 echo ${str##*.} #以 ‘.’分隔,最大限度从后面截取字符串bz2
|
||||
|
||||
5 echo ${str:0:3} #从左开始输出3个字符gmp
|
||||
|
||||
6 echo ${str:4} #从左面第5个字符开始输出直到结束6.1.0.tar.bz2
|
||||
|
||||
7 echo ${str:4:5} #从第5个字符开始输出5个字符6.1.0
|
||||
|
||||
8 echo ${str:0-8} #从右开始输出8个字符.tar.bz2
|
||||
5
content/deepin折腾笔记/第十一章/11.3.md
Executable file
5
content/deepin折腾笔记/第十一章/11.3.md
Executable file
@@ -0,0 +1,5 @@
|
||||
# 11.3 从指定类型文件中查找
|
||||
|
||||
1 find . -name '*.c' | awk '{print "grep -i -nH keyword "$1}' | /bin/bash
|
||||
|
||||
2 find . -name '*.c' -exec grep -i -nH "keyword" {} \;
|
||||
5
content/deepin折腾笔记/第十一章/11.4.md
Executable file
5
content/deepin折腾笔记/第十一章/11.4.md
Executable file
@@ -0,0 +1,5 @@
|
||||
# 11.4 更好的搜索方法
|
||||
|
||||
1 grep -i "search_string" . -r --include=*.txt
|
||||
|
||||
2 grep "search_string" . -r --include=*.txt --include=*.cpp --include=*.h
|
||||
3
content/deepin折腾笔记/第十一章/11.5.md
Executable file
3
content/deepin折腾笔记/第十一章/11.5.md
Executable file
@@ -0,0 +1,3 @@
|
||||
# 11.5 将行末多个空行转换成一个空行
|
||||
|
||||
1 find . -name '*.tex' -exec sed -i '/^$/{N;/^\n*$/D}' {} \;
|
||||
3
content/deepin折腾笔记/第十一章/11.6.md
Executable file
3
content/deepin折腾笔记/第十一章/11.6.md
Executable file
@@ -0,0 +1,3 @@
|
||||
# 11.6 ls 只显示目录名
|
||||
|
||||
1 ls -l |grep ^d 或 ls -d */
|
||||
8
content/deepin折腾笔记/第十一章/11.7.md
Executable file
8
content/deepin折腾笔记/第十一章/11.7.md
Executable file
@@ -0,0 +1,8 @@
|
||||
# 11.7 ls 只显示文件
|
||||
|
||||
```
|
||||
1 ls -l |grep ^-
|
||||
|
||||
|
||||
```
|
||||
|
||||
6
content/deepin折腾笔记/第十一章/11.8.md
Executable file
6
content/deepin折腾笔记/第十一章/11.8.md
Executable file
@@ -0,0 +1,6 @@
|
||||
# 11.8 ls 显示软链接
|
||||
|
||||
```
|
||||
1 ls -n
|
||||
```
|
||||
|
||||
8
content/deepin折腾笔记/第十一章/11.9.md
Executable file
8
content/deepin折腾笔记/第十一章/11.9.md
Executable file
@@ -0,0 +1,8 @@
|
||||
# 11.9 为子目录和文件设置不同权限
|
||||
|
||||
```
|
||||
1 find . -type d -exec sudo chmod 755 {} \;
|
||||
|
||||
2 find . -type f -exec sudo chmod 644 {} \;
|
||||
```
|
||||
|
||||
2
content/deepin折腾笔记/第十一章/README.md
Executable file
2
content/deepin折腾笔记/第十一章/README.md
Executable file
@@ -0,0 +1,2 @@
|
||||
# 第十一章 Deepin 终端操作技巧集
|
||||
|
||||
Reference in New Issue
Block a user