Thumbnail: Linux

CS6.NULL Lecture1

by on under Linux
2 minute read

一些常用指令和它们的意思

打印当前路径
pwd == “print work directory”

改变路径到目标路径
cd == “change directory”

在路径中表示当前路径
. == “current directory”

上一个目录
.. == “parent directory”

改变路径到 home
cd ~ : change directory to home.

返回到之前的目录
cd - : change directory to where you were previously in.

重命名文件 & 移动文件
mv 这个指令的逻辑非常的 amazing, 它可以单纯的重命名文件:
# rename hello to world
mv hello world
你也可以在目标名称前加上个路径,这样它就能移动文件了。 # 把 hello.md 移动到父目录并改名为 world.md
mv hello.md ../world.md

复制文件 cp 类似于 mv, 你可以复制文件并且顺带改个名字。

 # 把 hello.md 复制到父目录并改名为 world.md
 cp hello.md ../world.md

建立一个文件夹
如果文件夹名字中带空格,要用 \ 转义,或者把文件名改成字符串格式

 # make a directory called 'Photos'
 mkdir "Photos"	
 # make a directory called 'My Photos'
 mkdir My\ Photos	
 # make a directory called 'My Photos'
 mkdir "My Photos"	

删除文件

 # 删除上一级目录下的 test2.cpp
 rm ../test2.cpp	
 # 删除一个空的文件夹
 rmdir      
 # 删除一个文件夹及其内部所有文件
 rm -rf     

打开对应操作的帮助文件
man == “manual pages”

# show manual_pages of ls
# press button q to quit
man ls     

将文件的内容作为这个程序的输入
< == “rewire the input for this program to be the contents of this file”

# prints the content of hello.txt
cat < hello.txt

将这个程序的输入写入并覆盖到这个文件内
> == “rewire the output of the preceding program into this file”

# get content of hello and write them to hello2
cat < hello > hello2

将这个程序的输入写入但不覆盖到这个文件内
>> == “Append”

# what's in hello2.txt will be "hellohello"
cat < hello.txt >> hello2.txt

打印一个文件的内容
cat == “prints the content of a file”

将左边程序的输出作为右边程序的输入
| == “take the output of the program to the left and make it the input of the program to the right”

# print the last line of "ls -l"
ls -l \ | tail -n1	
# write the last line of "ls -l" to ls.txt
ls -l \ | tail -n1 > ls.txt 

关于权限
如果要到达一个目录的话,你需要有其所有父目录与其本身的执行权限,即:execute -- x 权限。
To cd to a directory, you must have execute permission on all parent directory of that directory and the directory itself.

Linux