在liunx中可能有几百个命令,最常用的就10多个。
liunx中最常用的命令
ls
功能
查看目录有哪些内容,全称list
使用说明
ls [待查看的目录] [参数]
待查看的目录:非必填的选项,一般情况下都是看当前目录,可省去;非当前目录时,需要指定要查看的目录。
参数:包含是否包含隐藏文件,是否显示文件的权限、大小、修改时间等,常用的有
-a表示包含隐藏文件
-lh表示查看文件的权限、修改时间、大小
案例
- 查看当前目录
host@localhost getting-started % ls
Dockerfile app mkdocs.yml
Jenkinsfile build.sh requirements.txt
LICENSE docker-compose.yml yarn.lock
README.md docs
- 包含隐藏文件
host@localhost getting-started % ls -a
. .gitignore build.sh
.. Dockerfile docker-compose.yml
.DS_Store Jenkinsfile docs
.dockerignore LICENSE mkdocs.yml
.git README.md requirements.txt
.github app yarn.lock
- 显示文件权限、大小、修改时间
host@localhost getting-started % ls -lh
total 88
-rw-r--r-- 1 host staff 1.0K 8 28 2021 Dockerfile
-rw-r--r-- 1 host staff 535B 8 28 2021 Jenkinsfile
-rw-r--r-- 1 host staff 11K 8 28 2021 LICENSE
-rw-r--r-- 1 host staff 1.6K 8 28 2021 README.md
drwxr-xr-x 7 host staff 224B 8 8 22:48 app
-rwxr-xr-x 1 host staff 253B 8 28 2021 build.sh
-rw-r--r-- 1 host staff 167B 8 28 2021 docker-compose.yml
drwxr-xr-x 8 host staff 256B 8 8 22:48 docs
-rw-r--r-- 1 host staff 1.9K 8 28 2021 mkdocs.yml
-rw-r--r-- 1 host staff 105B 8 28 2021 requirements.txt
-rw-r--r-- 1 host staff 86B 8 28 2021 yarn.lockpowershell
- 显示隐藏文件和文献信息
host@localhost getting-started % ls -alh
total 120
drwxr-xr-x 18 host staff 576B 2 6 2022 .
drwxr-xr-x+ 131 host staff 4.1K 8 20 22:49 ..
-rw-r--r--@ 1 host staff 6.0K 8 8 22:48 .DS_Store
-rw-r--r-- 1 host staff 12B 8 28 2021 .dockerignore
drwxr-xr-x 13 host staff 416B 8 28 2021 .git
drwxr-xr-x 3 host staff 96B 8 28 2021 .github
-rw-r--r-- 1 host staff 13B 8 28 2021 .gitignore
-rw-r--r-- 1 host staff 1.0K 8 28 2021 Dockerfile
-rw-r--r-- 1 host staff 535B 8 28 2021 Jenkinsfile
-rw-r--r-- 1 host staff 11K 8 28 2021 LICENSE
-rw-r--r-- 1 host staff 1.6K 8 28 2021 README.md
drwxr-xr-x 7 host staff 224B 8 8 22:48 app
-rwxr-xr-x 1 host staff 253B 8 28 2021 build.sh
-rw-r--r-- 1 host staff 167B 8 28 2021 docker-compose.yml
drwxr-xr-x 8 host staff 256B 8 8 22:48 docs
-rw-r--r-- 1 host staff 1.9K 8 28 2021 mkdocs.yml
-rw-r--r-- 1 host staff 105B 8 28 2021 requirements.txt
-rw-r--r-- 1 host staff 86B 8 28 2021 yarn.lock
pwd
功能
查看当前目录的结构,全称print work directory
使用说明
pwd
案例
- 查看当前的目录结构
host@localhost getting-started % pwd
/Users/host/getting-started
cd
功能
切换文件夹,全称change directory
使用说明
cd 待进入的目录
案例
host@localhost getting-started % pwd
/Users/host/getting-started
host@localhost getting-started % ls
Dockerfile app mkdocs.yml
Jenkinsfile build.sh requirements.txt
LICENSE docker-compose.yml yarn.lock
README.md docs
host@localhost getting-started % cd app
host@localhost app % pwd
/Users/host/getting-started/app
host@localhost app % ls
package.json spec src yarn.lock
mkdir
功能
创建目录
使用说明
mkdir [-p] dirName
-p 表示可迭代创建目录,确保目录名称存在,不存在的就建一个。对于创建多层目录,使用-p可一层层的判断目录是否存在,若不存在就创建。
dirName表示待创建的目录名称
案例
host@localhost app % ls
package.json spec src yarn.lock
host@localhost app %