Terminal-笔记-1.0
文章目录
- @[toc]
- 装饰终端的显示 增加易读性
- 取消/激活Zsh皮肤
- Lecture 1: The Shell (2020)
- 查看日期
- 返回argument - echo
- 关于目录的命令 pwd、 cd -、随机游走:
- 关于ls --help 无法在macOS中运行的问题
- dash
- mv 重命名/更改文件所处的位置
- 重命名
- 移动位置
- Input stream and ouput stream
- 把命令的输出内容写入一个文件(使用>的意思是overwrite)
- 运行python文件,将结果写入一个文件
- 重定向cat < hello.txt >hello2.txt
- 把命令的输出内容写入一个文件(使用>>的意思是append)
- 使用pip->| 连接两个命令
- Data wrangling lecture-------curl | grep?
- 超级用户sudo
- tee 命令
- References:
#安装 Zsh-终端皮肤
装饰终端的显示 增加易读性
macOS下测试可以成功使用的命令
手动安装:
先从git上clone下来整个仓库:
git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
安装:将zshrc.zsh-template 拷贝到根目录下~/.zshrc
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
安装完成之后退出当前会话重新打开一个终端窗口,就可以看见彩色的终端了。
取消/激活Zsh皮肤
You can just use exec
to replace your current shell with a new shell:
Switch to bash
:
exec bash
Switch to zsh
:
exec zsh
This won’t affect new terminal windows or anything, but it’s convenient [5].
Lecture 1: The Shell (2020)
查看日期
➜ Desktop date
Sat May 16 10:54:02 ADT 2020
返回argument - echo
➜ ~ echo hello
hello
使用逃逸字符
➜ ~ echo hello\ world\ with\ spaces
hello world with spaces
系统会在$PATH 变量下寻找所有可能存放命令源文件的地方,来决定是否执行你的文件
➜ terminal_demo echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion.app/Contents/Public:/Library/TeX/texbin:/Library/Apple/usr/bin
可以使用which命令查看 echo这个东西是在哪里存放的(macOS)
➜ terminal_demo which echo
echo: shell built-in command
关于目录的命令 pwd、 cd -、随机游走:
➜ terminal_demo pwd
/Users/lianda_duan/Downloads/terminal_demopwd-----> print working directly➜ terminal_demo ls
➜ terminal_demo pwd
/Users/lianda_duan/Downloads/terminal_demo
➜ terminal_demo cd ..
➜ Downloads pwd
/Users/lianda_duan/Downloadscd - 命令: 回到上次所处的文件位置
➜ Downloads cd -
~/Downloads/terminal_demo
➜ terminal_demo 在系统的目录中随机游走(与随机过程的随机游走区分开),直到找到bin目录下的 echo命令 返回参数hello\ world
➜ terminal_demo ../../../../../bin/echo hello\ world
hello world
关于ls --help 无法在macOS中运行的问题
On line 222 of _episodes/02-filedir.md, this command does not work on Max OSX, which implements BSD ls
rather than GNU ls
:
$ ls --help
I get this on a Mac:
$ ls --help
ls: illegal option -- -
usage: ls [-ABCFGHLOPRSTUWabcdefghiklmnopqrstuwx1] [file ...]
See this on that topic. I suggest replacing ls --help
by man ls
, which works for both BSD and GNU tools [4].
dash
-l long use a long listing format
➜ terminal_demo ls -l
total 0
-rw-r--r-- 1 lianda_duan staff 0 May 17 09:27 demo.py
-rw-r--r-- 1 lianda_duan staff 0 May 17 09:27 demo_2.py
Permission first_group owner
➜ terminal_demo cd /
➜ / ls -l
total 10
drwxrwxr-x+ 69 root admin 2208 May 14 21:07 Applications
drwxr-xr-x 69 root wheel 2208 May 13 17:02 Library
drwxr-xr-x@ 8 root wheel 256 Dec 5 04:23 System
drwxr-xr-x 5 root admin 160 Dec 5 04:21 Users
drwxr-xr-x 4 root wheel 128 May 14 21:40 Volumes
drwxr-xr-x@ 38 root wheel 1216 Apr 10 23:12 bin
drwxr-xr-x 2 root wheel 64 Nov 9 2019 cores
dr-xr-xr-x 3 root wheel 4666 Apr 24 23:17 dev
lrwxr-xr-x@ 1 root admin 11 Dec 5 07:25 etc -> private/etc
lrwxr-xr-x 1 root wheel 25 Apr 24 23:17 home -> /System/Volumes/Data/home
Group-3 read-write-execute
➜ / ls -l /bin
total 4848
-rwxr-xr-x 1 root wheel 35824 Apr 6 17:39 [
-r-xr-xr-x 1 root wheel 623472 Apr 6 17:39 bash
-rwxr-xr-x 1 root wheel 36768 Apr 6 17:39 cat
-rwxr-xr-x 1 root wheel 47264 Apr 6 17:39 chmod
-rwxr-xr-x 1 root wheel 42272 Apr 6 17:39 cp
-rwxr-xr-x 1 root wheel 529424 Apr 6 17:39 csh
-rwxr-xr-x 1 root wheel 110848 Apr 6 17:39 dash
-rwxr-xr-x 1 root wheel 41872 Apr 6 17:39 date
-rwxr-xr-x 1 root wheel 45120 Apr 6 17:39 dd
-rwxr-xr-x 1 root wheel 36512 Apr 6 17:39 df
-rwxr-xr-x 1 root wheel 31264 Apr 6 17:39 echo
-rwxr-xr-x 1 root wheel 67200 Apr 6 17:39 ed
-rwxr-xr-x 1 root wheel 36240 Apr 6 17:39 expr
mv 重命名/更改文件所处的位置
重命名
➜ terminal_demo ls
demo.py demo_2.py demo_storage
➜ terminal_demo echo "rename file demo.py->dddd.py"
rename file demo.py->dddd.py
➜ terminal_demo mv demo.py dddd.py
➜ terminal_demo ls
dddd.py demo_2.py demo_storage
移动位置
➜ terminal_demo ls demo_storage
➜ terminal_demo mv dddd.py demo_storage
➜ terminal_demo ls demo_storage
dddd.py
rmdir
only allowed to remove empty file for safty consern
Input stream and ouput stream
把命令的输出内容写入一个文件(使用>的意思是overwrite)
➜ terminal_demo echo "这是我写入的内容" > hello.txt
➜ terminal_demo ls
demo_2.py demo_storage hello.txt
➜ terminal_demo cat hello.txt
这是我写入的内容
运行python文件,将结果写入一个文件
➜ terminal_demo vim demo_2.py
➜ terminal_demo python demo_2.py > hello.txt
➜ terminal_demo cat demo_2.py
for _ in range(10):print(_)
➜ terminal_demo cat hello.txt
0
1
2
3
4
5
6
7
8
9
重定向cat < hello.txt >hello2.txt
这里实际上将调用
cat < hello.txt
的输出结果输入到另一个文件hello2.txt中。
➜ terminal_demo cat hello.txt
0
1
2
3
4
5
6
7
8
9
➜ terminal_demo cat < hello.txt > hello2.txt
➜ terminal_demo cat hello2.txt
0
1
2
3
4
5
6
7
8
9
➜ terminal_demo
把命令的输出内容写入一个文件(使用>>的意思是append)
➜ terminal_demo vim demo_2.py
➜ terminal_demo cat demo_2.py
for _ in range(3):print(_)
➜ terminal_demo python demo_2.py >hello3.py
➜ terminal_demo cat hello3.py
0
1
2
➜ terminal_demo python demo_2.py >> hello3.py
➜ terminal_demo cat hello3.py
0
1
2
0
1
2
使用pip->| 连接两个命令
其中tail 是显示最后一行
#列出所有
➜ terminal_demo ls -l
total 32
-rw-r--r-- 1 lianda_duan staff 29 May 17 10:02 demo_2.py
drwxr-xr-x 3 lianda_duan staff 96 May 17 09:39 demo_storage
-rw-r--r-- 1 lianda_duan staff 20 May 17 09:50 hello.txt
-rw-r--r-- 1 lianda_duan staff 20 May 17 10:00 hello2.txt
-rw-r--r-- 1 lianda_duan staff 12 May 17 10:02 hello3.py
#显示最后一行
➜ terminal_demo ls -l | tail -n1
-rw-r--r-- 1 lianda_duan staff 12 May 17 10:02 hello3.py
#显示最后两行
➜ terminal_demo ls -l | tail -n2
-rw-r--r-- 1 lianda_duan staff 20 May 17 10:00 hello2.txt
-rw-r--r-- 1 lianda_duan staff 12 May 17 10:02 hello3.py
#无用 测试
➜ terminal_demo ls -l | tail
total 32
-rw-r--r-- 1 lianda_duan staff 29 May 17 10:02 demo_2.py
drwxr-xr-x 3 lianda_duan staff 96 May 17 09:39 demo_storage
-rw-r--r-- 1 lianda_duan staff 20 May 17 09:50 hello.txt
-rw-r--r-- 1 lianda_duan staff 20 May 17 10:00 hello2.txt
-rw-r--r-- 1 lianda_duan staff 12 May 17 10:02 hello3.py
#显示最后一行(另一种写法)
➜ terminal_demo ls -l | tail -1
-rw-r--r-- 1 lianda_duan staff 12 May 17 10:02 hello3.py
#显示最后两行(另一种写法)
➜ terminal_demo ls -l | tail -2
-rw-r--r-- 1 lianda_duan staff 20 May 17 10:00 hello2.txt
-rw-r--r-- 1 lianda_duan staff 12 May 17 10:02 hello3.py
Data wrangling lecture-------curl | grep?
➜ terminal_demo curl --head --silent google.com
HTTP/1.1 301 Moved Permanently
Location: http://www.google.com/
Content-Type: text/html; charset=UTF-8
Date: Sun, 17 May 2020 13:17:21 GMT
Expires: Tue, 16 Jun 2020 13:17:21 GMT
Cache-Control: public, max-age=2592000
Server: gws
Content-Length: 219
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN
➜ terminal_demo curl --head --silent google.com | grep -i content-length
Content-Length: 219
➜ terminal_demo curl --head --silent google.com | grep -i content-length
Content-Length: 219
➜ terminal_demo curl --head --silent baidu.com
HTTP/1.1 200 OK
Date: Sun, 17 May 2020 13:19:28 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: Mon, 18 May 2020 13:19:28 GMT
Connection: Keep-Alive
Content-Type: text/html➜ terminal_demo curl --head --silent baidu.com | grep -i content-length
Content-Length: 81
#这个命令在mac 下不可运行, 在ubuntu中可以
#返回一个长度信息
➜ terminal_demo curl --head --silent baidu.com | grep -i content-length | cut --delimiter=' ' -f2
超级用户sudo
sudo + any_command_you_wantsudo 1060 | sudo tee brughtness
tee 命令
这个命令可以写入东西到一个文件里面并查看内容
tee 命令
echo 1060 | sudo tee brightness
echo 1 | sudo tee brightness
这个命令只在linux中使用,在mac中用的是open:
xdg-open xxxx.html
Exercise
Link:https://missing.csail.mit.edu/2020/course-shell/
References:
[1] https://www.youtube.com/watch?v=Z56Jmr9Z34Q&t=2003s
[2] https://missing.csail.mit.edu/2020/course-shell/
[3] https://zhuanlan.zhihu.com/p/19556676 终端装饰器参考
[4] https://github.com/swcarpentry/shell-novice/issues/447
[5] https://stackoverflow.com/questions/10341271/switching-from-zsh-to-bash-on-osx-and-back-again/10341338
Terminal-笔记-1.0相关推荐
- [转载]秀脱linux实战笔记linux-kernel-3.0.3实战篇
+++++++++++++++++++++++++++++++++++++++++++++++++++++++ 秀脱linux实战笔记linux-kernel-3.0.3实战片篇: QQ: 6 ...
- 使用screen的时候出现了如下错误: Cannot open your terminal '/dev/pts/0' - please check.
问题描述: 在Ubuntu14.04上使用screen的时候出现了如下错误:Cannot open your terminal '/dev/pts/0' - please check. 解决办法: 可 ...
- RK3399学习笔记 1.0.3---python环境 Firefly Core-3399pro-jd4 Win10上RKNN工具安装
RK3399学习笔记 1.0.3---python环境 Firefly Core-3399pro-jd4 Win10上RKNN工具安装 读取模型各层 1,最好在Conda下新建一个虚拟环境进行安装. ...
- Nginx重启时提示nginx: [emerg] bind() to 0.0.0.0解决方法 老蒋 发布于 2019-06-03 分类:运维笔记 评论(0) 2000+站长交流QQ群: 59
c 老蒋 发布于 2019-06-03 分类:运维笔记 评论(0) 2000+站长交流QQ群: 594467847(资源和技术交流) 昨天下午老蒋在一台服务器中折腾迁移数据问题的时候,重启Nginx的 ...
- 数据库系统概论(第5版)学习笔记 第0章——走进数据库系统
数据库系统概论(第5版)笔记 第0章--走进数据库系统 走进数据库系统 数据库系统概论(第5版)笔记 第0章--走进数据库系统 0.为什么要学它? 1.数据库系统的发展经历了三代演变 2.造就了四位图 ...
- 从零开始游戏开发笔记(0):前期准备
从零开始游戏开发笔记(0):前期准备(持续更新中) 一.开发软件 1.1 游戏引擎 1.2 美工软件 1.3 音乐软件 1.4 插件 二.教程.素材 1.1 学习教程 1.2 素材网站 三.其他技能 ...
- Python学习笔记 1.0 基础内容篇章
Python学习笔记 1.0 基础内容篇章 注释 变量 一.定义变量 二.使用变量 bug和debug bug: Debug工具: 数据类型 认识数据类型 在定义数据类型时发生的错误: 数据类型的补表 ...
- 数据可视化清新版【chart.js】学习笔记8.0—极地图(Polar Area)
Polar Area--(极地图) 极地面积图类似于饼图,但每个线段具有相同的角度 - 线段的半径因值而异.当我们想要显示类似于饼图的比较数据,同时也要显示上下文的值的范围时通常使用这种类型的图表. ...
- QT笔记第0篇__Qt基本介绍
QT笔记第0篇__Qt基本介绍 一.引言 二.Qt简介 三.特点: 四.相关网址 五.参考资料 一.引言 由于算法的实现过程中常常需要制作一些demo来进行功能展示,最开始打算用mfc,于是看了一段几 ...
- linux学习笔记2.0
ilinux学习笔记 Linux哲学思想 一切都是一个文件(包括硬件) **小型,单一用途的程序 ** **链接程序,共同完成复杂的任务 ** **避免令人困惑的用户界面 ** 配置数据存储在文本中 ...
最新文章
- 关于ThinkPHP的一些编程技巧
- 实战项目三:爬取QQ群中的人员信息
- QML基础类型之geocircle
- Ajax(jquery)
- cookies丢失 同域名_后端设置Cookie前端跨域获取丢失问题(基于springboot实现)
- prd展示html文件,prd目的.html
- 数mysql据分析优化_从零开始学习数据分析-mysql架构与优化理论
- Oracle Sharding
- [hgoi#2019/2/16t1]math
- UVA10025 The ? 1 ? 2 ? ... ? n = k problem【数学规律】
- cookie 操作
- 转:KVC与KVO机制
- linux下的pdf工具下载,Linux系统下的PDF好帮手 LinuxPDFeditor
- python实现多线程输出123123
- 三菱PLC FX5U 伺服机器人程序
- 大胜凭德--入行选领导(转载分析)
- [Game Engine]开源游戏框架(转至wiki)
- 《MultiPoseNet: Fast Multi-Person Pose Estimation using Pose Residual Network》论文阅读
- 输入验证码,一直报错验证码错误(内网多服务器)
- [机缘参悟-19]:鬼谷子-捭阖篇-阴阳即矛盾,是万事万物的基本属性,也是鬼谷子哲学的根基之一