Skip to main content

Linux常用命令

参考资料:https://www.runoob.com/w3cnote/linux-common-command-2.html

创建目录 or 文件

https://www.runoob.com/linux/linux-comm-mkdir.html

$ mkdir -p [绝对路径目录 or 相对路径目录] # mkdir ./hello/test/project
$ touch [绝对路径目录文件 or 相对路径目录文件] # touch ./hello/test/project/test.js

拷贝 cp

https://www.runoob.com/linux/linux-comm-cp.html

$ cp -ir [源文件 or 目录] [目标目录] # cp -ir ./hello ../test
$ cp -lr [源文件 or 目录] [目标目录]
  • ir 表示复制一个目录时,如果已存在,这作出提示由用户判断是否覆盖
  • lr 表示给目录创建一个软链接
  • 复制目录时必须携带 -r 参数

剪切 or 改名 mv

https://www.runoob.com/linux/linux-comm-mv.html

$ mv [old_name] [new_name] # 修改文件名
$ mv -fb [源目录 or 文件] [目标目录 or 文件] # 移动目录,如果存在则创建备份
$ mv -ib [源目录 or 文件] [目标目录 or 文件] # 文件覆盖时进行提示

删除 rm

https://www.runoob.com/linux/linux-comm-rm.html

$ rm -ri [目录路径] # 会逐一询问删除的目录或文件,是否需要删除
$ rm -rf [目录路径] # 强制删除,不会询问
$ rm -rf *.json # 删除当前目录所有以 .json 结尾的文件

注意:回收站中是无法找到被删除的,rm 删除的文件不可恢复

路径切换

$ cd ~ # 进入根目录
$ cd - # 等价于 cd ../

写入内容 echo

https://blog.csdn.net/xukai871105/article/details/35834703

$ echo -e "const sum = (a, b) => a + b;" >> ./test.js
$ echo -e "
dquote> function sum(a, b) {
dquote> return a + b;
dquote> }
dquote> " >> ./aus.js

查看内容 cat

https://www.runoob.com/linux/linux-comm-cat.html

$ cat -net ./aus.js
1 1231241$
2 $
3 hello$
4 i am a boy.$
5 lalalal$
6 dududu$
7 $
8 $
9 function sum(a, b) {$
10 return a + b;$
11 }$
12 $

查看符号链接真实地址

$ pwd -P # 查看当前所在软链接的真实位置
$ ls -al # 查看当前目录所有文件的真实位置