命令行入门整理-阅读Command Line Crash Course

The only piece of advice I am going to give you is this: Shut up and type all this in.

作者这一条建议延续了之前Learn XX the hard way的风格思路,强调了练习的重要性——虽然枯燥、但是必要。


 

练习部分

Exercise 1: The Setup

  • For Linux, we can use the Terminal; for Windows, w can use the Powershell.
  • Remember, some command lines in Linux are different from the ones in Windows Powershell.
  • 在Linux系统中我们可以通过终端来进行命令行操作,在Windows中,我们则可使用内置的PowerShell(其实Win10系统更推荐WSL这一Linux内置测试版本来进行练习操作!)。

 

Exercise 2: Paths, Folders, Directories ( pwd )

  • pwd means “printing working directory”.
    “directory” is another name for “folder”.
  • 打印工作所在文件夹位置
$ pwd
/home/hibetterhyj

 

Exercise 3: If You Get Lost

  • Whenever you get lost, it is most likely because you were typing commands and have no idea where you’ve ended up. The next thing is you need to have a way of getting back to where you are safe, your home.
  • 当在文件夹路径中迷路时,可以用一下的方法回到主目录。
$ pwd
cd ~
pwd
/home/hibetterhyj

 

Exercise 4: Make a Directory ( mkdir )

  • mkdir means “make dircetory”
  • 新建文件夹
$ mkdir temp
# 建立一个叫做 temp 的文件夹
$ mkdir -p temp/stuff/things/frank/joe/alex/john
# 建立一个叫做 john 的文件夹,并且建立上级目录
$ mkdir “I have fun”
# 建立一个叫做 I have fun 的文件夹,使用双引号的原因在于新建的文件名中含有空格。

 

Exercise 5: Change Directory ( cd )

  • cd means “Change directory ”
  • 打开文件夹
$ cd folder_name
# 打开文件夹
$ cd ..
# 返回上级目录 (move "up" in the tree and path)
$ cd ../..
# 返回多层上级目录
$ cd ~
# 返回主目录
$ cd -
# 返回上次工作所在目录

 

Exercise 6: List Directory ( ls )

  • ls means “list directory”
  • 列出所在文件内的文件与文件夹
$ ls
# 列出本文件夹内的文件与文件夹
$ ls <folder_name>
# 列出指定文件夹内的文件与文件夹
$ ls -lR
# 列出本文件夹及子文件夹内的文件的详细信息

 

Exercise 7: Remove Directory ( rmdir )

  • rmdir means “remove directory”
  • 移除文件夹
$ remdir <dir>
# 移除指定文件夹
$ rm -rf <dir>
# 移除包含文件的文件夹

 

Exercise 8: Move Around ( pushd, popd )

  • pushd means “save the current location and go to a new location”
  • 保存当前的目录,并转到指定目录
  • popd means “return the saved location”
    -回到之前保存的位置
$ pushd <dir>
# 改变当前目录到指定目录,并保存当前的目录在堆栈顶端
$ pushd
# 将第二个目录置于第一个目录之上,并改变到指定文件夹
$ popd <dir>
# 改变当前目录,跳转到堆栈顶端保存的目录,并将堆栈顶端的目录删除,可以多配合 pwd 命令行

PS: this cannot work in PowerShell !

 

Exercise 9: Make Empty Files ( touch, new-item )

  • touch means “make an empty file”(or new-item on Windows
  • 新建一个文件
$ touch <file_name>
# 新建一个文件,一般以txt为主,可以通过 ls 查看

 

Exercise 10: Copy a File ( cp )

  • cp means “copy s file from one location to another”
  • 复制一个文件

 

(未完待续……)

 

 

  • 参考资料

[1]:Learn Python the Hard Way·Appendix https://learnpythonthehardway.org/python3/appendixa.html

 

 

本文使用 CC BY-NC-SA 3.0 Unported 协议进行许可,相关说明
本文链接:https://hibetterheyj.github.io/weblog/2017/08/20/after-reading-the-command-line-crash-course/