linux命令
命令格式
linux命令格式为:
命令 [ 选项 ] [参数]
[]代表可选
查看帮助文档
help
可以使用help命令查看帮助文档 例如:ls --help
或者ls -help
man
manual 手册,是linux提供的一个手册,包含了大多数命令 可以使用man 命令
来查看命令的用法,例如man ls
自动补全
和很多地方的快捷键一样,使用tab键自动补全,当有唯一的时,会直接自动补全,当不唯一时,第一次按tab键没有反应,当按下第二次tab键时,会显示可选择的,当输入不重复的字符,再次按下tab键,会自动补全
查看历史命令
history
使用history可以查看已经输入过的命令,例如:
caicai@caicai-VirtualBox:~$ history
1 mocp
2 su
3 sudo moc
4 sudo apt install moc
5 sudo ./VBoxLinuxAdditions.run
6 gedit a.txt
7 ll
8 sudo apt-get install virtual-box-guest-x11
9 VBoxClient-all
10 sudo apt-get install virtual-box-guest-x11
文件磁盘相关命令
- 查看文件信息
ls
list的简写功能是列出目录文件
ls -a
列出所有文件包括隐藏的
caicai@caicai-VirtualBox:~$ ls
1 Documents examples.desktop Music Public Videos
Desktop Downloads mumu Pictures Templates
caicai@caicai-VirtualBox:~$ ls -a
. Downloads Public
.. examples.desktop .ssh
1 .gnupg .sudo_as_admin_successful
.bash_history .ICEauthority Templates
.bash_logout .local .thunderbird
.bashrc .mozilla .vboxclient-clipboard.pid
.cache mumu .vboxclient-display.pid
.config Music .vboxclient-draganddrop.pid
.dbus Pictures .vboxclient-seamless.pid
Desktop .presage Videos
Documents .profile .xinputrc
ls -l
以列表的形式显示文件的详细信息
caicai@caicai-VirtualBox:~$ ls -l
total 52
drwxr-xr-x 2 caicai caicai 4096 10月 16 09:19 1
drwxr-xr-x 2 caicai caicai 4096 10月 16 09:19 Desktop
drwxr-xr-x 2 caicai caicai 4096 10月 15 16:00 Documents
drwxr-xr-x 2 caicai caicai 4096 10月 15 16:00 Downloads
-rw-r--r-- 1 caicai caicai 8980 10月 15 15:34 examples.desktop
drwxr-xr-x 3 caicai caicai 4096 10月 16 20:07 mumu
drwxr-xr-x 2 caicai caicai 4096 10月 15 16:00 Music
drwxr-xr-x 2 caicai caicai 4096 10月 16 14:39 Pictures
drwxr-xr-x 2 caicai caicai 4096 10月 15 19:15 Public
drwxr-xr-x 2 caicai caicai 4096 10月 15 16:00 Templates
drwxr-xr-x 2 caicai caicai 4096 10月 15 16:00 Videos
ls -lh
友好的显示文件详细信息
caicai@caicai-VirtualBox:~$ ls -lh
total 52K
drwxr-xr-x 2 caicai caicai 4.0K 10月 16 09:19 1
drwxr-xr-x 2 caicai caicai 4.0K 10月 16 09:19 Desktop
drwxr-xr-x 2 caicai caicai 4.0K 10月 15 16:00 Documents
drwxr-xr-x 2 caicai caicai 4.0K 10月 15 16:00 Downloads
-rw-r--r-- 1 caicai caicai 8.8K 10月 15 15:34 examples.desktop
drwxr-xr-x 3 caicai caicai 4.0K 10月 16 20:07 mumu
drwxr-xr-x 2 caicai caicai 4.0K 10月 15 16:00 Music
drwxr-xr-x 2 caicai caicai 4.0K 10月 16 14:39 Pictures
drwxr-xr-x 2 caicai caicai 4.0K 10月 15 19:15 Public
drwxr-xr-x 2 caicai caicai 4.0K 10月 15 16:00 Templates
drwxr-xr-x 2 caicai caicai 4.0K 10月 15 16:00 Videos
- 输出重定向命令
linux允许将命令执行结果重定向到文件中
注意:>会覆盖原来的,>>00000000是追加 =
例如ls >ls.txt
caicai@caicai-VirtualBox:~$ ls
1 Documents examples.desktop mumu Pictures Templates
Desktop Downloads ls.txt Music Public Videos
caicai@caicai-VirtualBox:~$ more ls.txt
1
Desktop
Documents
Downloads
examples.desktop
ls.txt
mumu
Music
Pictures
Public
Templates
Videos
- 分屏显示
more 文件
文件过大时可以使用more 分屏查看,每次显示一页,按下空格翻页,q停止
ctrl + b返回上一页
ctrl + f查看下一页 - 管道 |
一个命令的输出可以通过管道作为另一个命令的输入 - 清屏
clear
快捷键ctrl + l - 切换目录
cd
cd ~
切换到当前用户的主目录cd 路径
切换到路径cd -
切换到上次切换的路径cd .
切换到当前目录cd ..
切换到当前目录的父目录
- 打印当前路径
pwd
- 创建目录
mkdir
mkdir
命令可以创建一个新目录 参数-p 可以递归创建目录
例如:
caicai@caicai-VirtualBox:~/mumu$ mkdir -p cc/mm/love
caicai@caicai-VirtualBox:~/mumu$ tree
├── a.txt
├── caicai
│ └── a.txt
└── cc
└── mm
└── love
- 删除目录
rmdir
rmdir
可以删除目录且目录必须为空-p
参数可以递归删除
caicai@caicai-VirtualBox:~/mumu$ rmdir cc
rmdir: failed to remove 'cc': Directory not empty
- 删除文件
rm
可以删除文件或者目录 要慎重使用rm,rm删除的文件不可恢复,所以可以使用rm -i逐个询问删除,rm -f 强制删除,要谨慎使用 rm -r递归删除
先记到这里吧,明天再接着整理,困==