missing-semester

1.the shell

cd

cd改变当前的目录

pwd查看当前目录

cd -可以在当前目录和上一级目录之间切换

leo@leo-virtual-machine [19:30:18] [~] 
-> % cd /home       

leo@leo-virtual-machine [18:44:25] [/home] 
-> % pwd
/home

ls -l

ls -l显示文件的详细信息

leo@leo-virtual-machine [18:49:00] [~] 
-> % ls -l
总用量 48
drwxr-xr-x 2 leo  leo  4096  5月  1 13:43 公共的
drwxr-xr-x 2 leo  leo  4096  5月  1 13:43 模板
drwxr-xr-x 2 leo  leo  4096  5月  1 13:43 视频
drwxr-xr-x 3 leo  leo  4096  5月  1 17:11 图片
drwxr-xr-x 2 leo  leo  4096  5月  1 13:43 文档
drwxr-xr-x 3 leo  leo  4096  5月  3 00:41 下载
drwxr-xr-x 2 leo  leo  4096  5月  1 13:43 音乐
drwxr-xr-x 2 leo  leo  4096  5月  1 13:43 桌面
-rw-r--r-- 1 root root    4 10月  4 18:37 brightness
  1. 首字母 d 表示是一个 directory
  2. 前三个字母组,表示 owner of the file 的权限
  3. 中间三个字母组,表示 group of the file 的权限
  4. 最后三个字母组,表示 anyone else 的权限
  • 三个字母的意思:read, write, execute

rmdir

只当文件夹为空的时候才能删除文件夹

ctrl + l

clean the terminal

cat

cat 支持的形式 cat filenamecat < filename

zl@LAPTOP-ZL ~/rust_learn> cat main.rs
fn main() {
    println!("hello, world!");
}
zl@LAPTOP-ZL ~/rust_learn> cat < main.rs
fn main() {
    println!("hello, world!");
}

> >> redirection

  • 单个 > 命令会 overwrite 文件
  • 双 >> 命令会在文件后 append
zl@LAPTOP-ZL ~/rust_learn> cat < main.rs > test.rs
zl@LAPTOP-ZL ~/rust_learn> cat test.rs
fn main() {
    println!("hello, world!");
}
zl@LAPTOP-ZL ~/rust_learn> cat < main.rs >> test.rs
zl@LAPTOP-ZL ~/rust_learn> cat test.rs
fn main() {
    println!("hello, world!");
}
fn main() {
    println!("hello, world!");
}

| pipe character

将左侧的程序的输出当作右侧程序的输入。

tail -n 表示输出最后几行:

zl@LAPTOP-ZL ~/rust_learn> ls -l | tail -n2
drwxrwxrwx 1 zl   zl      4096 Sep 12 14:42 the_slice_type
drwxrwxrwx 1 zl   zl      4096 Sep  9 09:05 variables

tail -n +<N+1> 表示输出从第N行开始的内容: 例如 tail -n +2 表示输出从第2行开始的内容。

ref: linux - Print a file, skipping the first X lines, in Bash - Stack Overflow

pipe 配合 grep 使用:

zl@LAPTOP-ZL ~/> curl --head --silent baidu.com
HTTP/1.1 200 OK
Date: Sat, 08 Feb 2020 05:20:44 GMT
Server: Apache
Last-Modified: Tue, 12 Jan 2010 13:48:00 GMT
ETag: "51-47cf7e6ee8400"
Accept-Ranges: bytes
Content-Length: 81
Cache-Control: max-age=86400
Expires: Sun, 09 Feb 2020 05:20:44 GMT
Connection: Keep-Alive
Content-Type: text/html

zl@LAPTOP-ZL ~/> curl --head --silent baidu.com | grep Server
Server: Apache

zl@LAPTOP-ZL ~> pstree -ap | grep fish
  |       `-fish,3051
  |           |-grep,9658 --color=auto fish
  |                   |   |   `-fish,3839

open file before "sudo echo"

$ cd /sys/class/backlight/thinkpad_screen
$ sudo echo 3 > brightness
An error occurred while redirecting file 'brightness'
open: Permission denied

上述的 permission denied 是由于:

the shell (which is authenticated just as your user) tries to open the brightness file for writing, before setting that as sudo echo’s output

command line - Cannot echo "hello" > x.txt even with sudo? - Ask Ubuntu

shell 会在执行 sudo echo 之前就进行打开文件进行写入。

解决方法为:

$ echo 3 | sudo tee brightness

tee

tee 命令会将输入写入文件并打印到标准输出。

Copy standard input to each FILE, and also to standard output.

zl@LAPTOP-ZL ~/rust_learn> echo "Hello world" | tee test.rs
Hello world
zl@LAPTOP-ZL ~/rust_learn> cat test.rs
Hello world

 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值