Some basic command
cd , ls , mv , cp , rm , mkdir , cat , echo , which , date , and man .
创建名称带空格的文件夹
mkdir My\ floder
mkdir 'My floder'
方法:利用转义字符或把整个文件夹名称用单引号包裹。
rmdir
: remove empty directories.- 参数用‘空格’来分隔
touch 1st.txt 2nd.txt
参考: 终于!Shell命令,我来啦!
输入输出流(stream)
默认情况就两个流,一个输入,一个输出。
通常情况下,通过键盘输入信息到输入流,在通过输出流显示到屏幕上。
尖括号 <``>
<
:输入功能>
:输出功能
举栗子 🌰
写入功能
echo hello > hello.txt
创建 hello.txt , 并把 hello 写入 hello.txt
复制功能
cat < hello.txt > hello2.txt
cat 查看 hello.txt 的内容,并把信息输出到 hello2.txt(输出过程同1.) —— 代替了
cp
命令。双大于号
cat < hello.txt >> hello2.txt
ta的作用是追加(append),而不是覆写(overwrite)。
这样,hello2.txt 现在内容为:hello <br> hello
管道符
|
(pipe)
意思是:取左侧程序的输出,成为右侧程序的输入。
举个栗子 🌰
ls -al | tail -n3
tail 见 man tail
。
root 用户
sudo su
普通用户的标识符是 $ ; root 的标识符是 # 。
一直在普通用户身份下,做到root用户权限 执行写入命令的方法
echo 500 | sudo tee brightness
sudo echo 500 > brightness
命令超过了sudo echo 的写入权限,所以借用 tee
命令执行。(见man tee
)
xdg-open命令
这个命令只能在Linux使用,(在MacOs是open
)它可以用来打开任何东西,html,文件夹,文档,etc.
lecture1 课后题个人思考/收获
- 第4题
我把“Write the following into that file, one line at a time”理解成“把下面的内容用一行命令一次性地写入文件里面”了(原题是一次一行的写入,想考 echo , > , >> )。然后我不会,于是我就先用了 echo, > , >> 的写法写了一遍;然后去搜了一下 “echo 换行”。
echo -e 'hello\nworld!' > helloworld.txt
-e
: 使 echo