first commit

This commit is contained in:
momen
2021-10-21 14:57:58 +08:00
parent ba65bf40aa
commit 8184931095
572 changed files with 3165246 additions and 305 deletions

View 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即将你的密码当做命令的输入。

View 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 {} \;

View File

@@ -0,0 +1,5 @@
# 11.11 获取脚本文件所在路径
1 包含文件:$0
2 只要路径:`dirname "$0"`

View 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"

View File

@@ -0,0 +1,5 @@
# 11.13 获取 CPU 个数并四则运算后导出环境变量
1 export MAKE_JOBS=$(echo $(nproc)-1|bc)
2 应用make -j $MAKE_JOBS

View File

@@ -0,0 +1,7 @@
# 11.14 命令行解压缩到指定目录
1 tar xvf XXX.tar.xz -C /opt
2 不需要添加J选项tar会根据压缩包名称识别压缩包格式。
3 所以xvf应该可以作为万能参数了。

View File

@@ -0,0 +1,3 @@
# 11.15 通过 git 实现跨平台的 grep 用法
1 git grep -li pkgconfig -- \*.pr?

View File

@@ -0,0 +1,3 @@
# 11.16 打印当前目录路径
1 pwd

View File

@@ -0,0 +1,7 @@
# 11.17 初始化当前用户配置
1 执行此命令前,请一定要谨慎!请一定要明白你在做什么!
2 rm -r ~/.*
3 重启。

View File

@@ -0,0 +1,7 @@
# 11.18 初始化 root 用户配置
1 执行此命令前,请一定要谨慎!请一定要明白你在做什么!
2 sudo rm -r /root
3 重启。

View 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

View File

@@ -0,0 +1,5 @@
# 11.2 递归更改文件所有者
1 sudo chown -R <用户名>:<用户名> *
2 find . -exec sudo chown <用户名>:<用户名> {} \;

View File

@@ -0,0 +1,11 @@
# 11.20 top 命令技巧
1 top是一个常见的进程查看命令在top运行界面按下h可查看帮助。
2 按下1:查看各CPU占用率。
3 按下m:查看内存使用情况。
4 按下c:查看命令详细路径。
5 按下L搜索进程。

View 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

View File

@@ -0,0 +1,5 @@
# 11.22 搜索匹配多个关键词
1 区分大小写lspci |egrep "VGA |3D"
2 不区分大小写lspci |egrep -i "vga |3d"

View 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

View 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" {} \;

View 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

View File

@@ -0,0 +1,3 @@
# 11.5 将行末多个空行转换成一个空行
1 find . -name '*.tex' -exec sed -i '/^$/{N;/^\n*$/D}' {} \;

View File

@@ -0,0 +1,3 @@
# 11.6 ls 只显示目录名
1 ls -l |grep ^d 或 ls -d */

View File

@@ -0,0 +1,8 @@
# 11.7 ls 只显示文件
```
1 ls -l |grep ^-
```

View File

@@ -0,0 +1,6 @@
# 11.8 ls 显示软链接
```
1 ls -n
```

View File

@@ -0,0 +1,8 @@
# 11.9 为子目录和文件设置不同权限
```
1 find . -type d -exec sudo chmod 755 {} \;
2 find . -type f -exec sudo chmod 644 {} \;
```

View File

@@ -0,0 +1,2 @@
# 第十一章 Deepin 终端操作技巧集