linux基本指令(上)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux基本指令(上)相关的知识,希望对你有一定的参考价值。
(文章目录)
1.whomai指令
[root@VM-8-8-centos ~]# whoami
root
2. pwd指令
[root@VM-8-8-centos 9.9]# pwd
/root/9.9
3. ls 指令
1. ls指令
[root@VM-8-8-centos 9.9]# ls
666.txt lesson2
2. ls -l指令
[root@VM-8-8-centos 9.9]# ls -l
total 4
-rw-r--r-- 1 root root 0 Sep 27 09:48 666.txt
drwxr-xr-x 2 root root 4096 Sep 26 19:03 lesson2
3.ls -la指令
[root@VM-8-8-centos 9.9]# ls -la
total 12
drwxr-xr-x 3 root root 4096 Sep 27 09:48 .
dr-xr-x---. 8 root root 4096 Sep 26 17:52 ..
-rw-r--r-- 1 root root 0 Sep 27 09:48 666.txt
drwxr-xr-x 2 root root 4096 Sep 26 19:03 lesson2
1. cd .
[root@VM-8-8-centos 9.9]# pwd
/root/9.9
[root@VM-8-8-centos 9.9]# cd .
[root@VM-8-8-centos 9.9]# pwd
/root/9.9
2. cd . .
[root@VM-8-8-centos 9.9]# pwd
/root/9.9
[root@VM-8-8-centos 9.9]# cd ..
[root@VM-8-8-centos ~]# pwd
/root
4. ls -ld指令
[root@VM-8-8-centos lesson2]# pwd
/root/9.9/lesson2
[root@VM-8-8-centos lesson2]# ls -la
total 12
drwxr-xr-x 3 root root 4096 Sep 27 14:56 .
drwxr-xr-x 3 root root 4096 Sep 27 09:48 ..
drwxr-xr-x 2 root root 4096 Sep 27 14:55 dir
[root@VM-8-8-centos lesson2]# ls -ld dir
drwxr-xr-x 2 root root 4096 Sep 27 14:55 dir
[root@VM-8-8-centos lesson2]# pwd
/root/9.9/lesson2
5. ls -i指令
[root@VM-8-8-centos lesson2]# pwd
/root/9.9/lesson2
[root@VM-8-8-centos lesson2]# ls -la -i
total 12
657683 drwxr-xr-x 3 root root 4096 Sep 27 14:56 .
657678 drwxr-xr-x 3 root root 4096 Sep 27 09:48 ..
657694 drwxr-xr- 2 root root 4096 Sep 27 14:55 dir
1. windows 与linux标识文件之间的区别
6. ls -R指令
[root@VM-8-8-centos 9.9]# pwd
/root/9.9
[root@VM-8-8-centos 9.9]# ls -R
.:
666.txt lesson2 touch
./lesson2:
dir test.c
4. cd指令
1.cd 指令
[root@VM-8-8-centos lesson2]# pwd
/root/9.9/lesson2[root@VM-8-8-centos lesson2]# ls -l
total 12
drwxr-xr-x 2 root root 4096 Sep 27 14:55 dir
-rw-r--r-- 1 root root 13 Sep 27 15:29 test.c
-rw-r--r-- 1 root root 15 Sep 27 15:29 touch
[root@VM-8-8-centos lesson2]# cd dir
[root@VM-8-8-centos dir]# pwd
/root/9.9/lesson2/dir
2. cd ~ 指令
[root@VM-8-8-centos dir]# pwd
/root/9.9/lesson2/dir
[root@VM-8-8-centos dir]# cd ~
[root@VM-8-8-centos ~]# pwd
/root
3.cd -指令
[root@VM-8-8-centos lesson2]# pwd
/root/9.9/lesson2
[root@VM-8-8-centos lesson2]# cd ~
[root@VM-8-8-centos ~]# pwd
/root
[root@VM-8-8-centos ~]# cd -
/root/9.9/lesson2
5. 根目录
[root@VM-8-8-centos 9.9]# pwd
/root/9.9
[root@VM-8-8-centos 9.9]# ls -la
total 16
drwxr-xr-x 3 root root 4096 Sep 27 16:38 .
dr-xr-x---. 8 root root 4096 Sep 27 17:58 ..
-rw-r--r-- 1 root root 0 Sep 27 09:48 666.txt
drwxr-xr-x 3 root root 4096 Sep 28 07:24 lesson2
-rw-r--r-- 1 root root 13 Sep 27 16:36 touch
[root@VM-8-8-centos 9.9]# cd ..
[root@VM-8-8-centos ~]# pwd
/root
[root@VM-8-8-centos ~]# cd ..
[root@VM-8-8-centos /]# pwd
/
[root@VM-8-8-centos /]# cd ..
[root@VM-8-8-centos /]# pwd
/
1.绝对路径
[root@VM-8-8-centos dir]# pwd
/root/9.9/lesson1/dir
[root@VM-8-8-centos dir]# ls -ld /root/9.9/lesson2
drwxr-xr-x 2 root root 4096 Sep 28 08:13 /root/9.9/lesson2
2.相对路径
[root@VM-8-8-centos dir]# pwd
/root/9.9/lesson1/dir
[root@VM-8-8-centos dir]# ls -ld ../../lesson2
drwxr-xr-x 2 root root 4096 Sep 28 08:13 ../../lesson2
判断相对路径是否唯一
[root@VM-8-8-centos lesson1]# pwd
/root/9.9/lesson1
[root@VM-8-8-centos lesson1]# cd ./dir
[root@VM-8-8-centos dir]# pwd
/root/9.9/lesson1/dir
[root@VM-8-8-centos lesson1]# pwd
/root/9.9/lesson1
[root@VM-8-8-centos lesson1]# cd ../lesson1/dir
[root@VM-8-8-centos dir]# pwd
/root/9.9/lesson1/dir
[root@VM-8-8-centos dir]# pwd
/root/9.9/lesson1/dir
[root@VM-8-8-centos dir]# cd ../../../9.9/lesson1/dir
[root@VM-8-8-centos dir]# pwd
/root/9.9/lesson1/dir
6. touch 指令
1.创建文件
[root@VM-8-8-centos 9.9]# ls -l
total 4
-rw-r--r-- 1 root root 0 Sep 27 09:48 666.txt
drwxr-xr-x 3 root root 4096 Sep 27 15:31 lesson2
[root@VM-8-8-centos 9.9]# touch bin.c
[root@VM-8-8-centos 9.9]# ls -l
total 4
-rw-r--r-- 1 root root 0 Sep 27 09:48 666.txt
-rw-r--r-- 1 root root 0 Sep 27 15:50 bin.c
drwxr-xr-x 3 root root 4096 Sep 27 15:31 lesson2
2. 修改文件的时间信息
[root@VM-8-8-centos 9.9]# stat bin.c
File: ‘bin.c’
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd01h/64769d Inode: 657954 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2022-09-27 15:50:13.648196751 +0800
Modify: 2022-09-27 15:50:13.648196751 +0800
Change: 2022-09-27 15:50:13.648196751 +0800
Birth: -
[root@VM-8-8-centos 9.9]# stat file.txt
File: ‘file.txt’
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd01h/64769d Inode: 657693 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2022-09-27 16:16:54.301985090 +0800
Modify: 2022-09-27 16:16:54.301985090 +0800
Change: 2022-09-27 16:16:54.301985090 +0800
Birth: -
[root@VM-8-8-centos 9.9]#
[root@VM-8-8-centos 9.9]# nano touch file.txt
[root@VM-8-8-centos 9.9]# stat file.txt
File: ‘file.txt’
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd01h/64769d Inode: 657693 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2022-09-27 16:17:12.902075733 +0800
Modify: 2022-09-27 16:17:31.310165425 +0800
Change: 2022-09-27 16:17:31.310165425 +0800
Birth: -
7.mkidr 指令
1.创建目录
[root@VM-8-8-centos lesson1]# mkdir lesson1
[root@VM-8-8-centos lesson1]# ls -la
total 16
drwxr-xr-x 3 root root 4096 Sep 30 15:39 .
drwxr-xr-x 6 root root 4096 Sep 30 14:49 ..
-rw-r--r-- 1 root root 12 Sep 30 13:49 file.c
drwxr-xr-x 2 root root 4096 Sep 30 15:39 lesson1
2.创建一串路径
[root@VM-8-8-centos lesson1]# mkdir -p dir1/dir2/dir3/dir4
[root@VM-8-8-centos lesson1]# ls
dir1 file.c
[root@VM-8-8-centos lesson1]# ls dir1
dir2
[root@VM-8-8-centos lesson1]# ls dir1/dir2
dir3
[root@VM-8-8-centos lesson1]# ls dir1/dir2/dir3
dir4
3. tree
1. 安装
[root@VM-8-8-centos lesson1]# yum -y install tree
[root@VM-8-8-centos lesson1]# tree dir1
dir1
`-- dir2
`-- dir3
`-- dir4
3 directories, 0 files
2. tree .
[root@VM-8-8-centos lesson1]# ls
dir1 file.c
[root@VM-8-8-centos lesson1]# tree .
.
|-- dir1
| `-- dir2
| `-- dir3
| `-- dir4
`-- file.c
4 directories, 1 file
8.rm指令
1.rmdir指令
[root@VM-8-8-centos lesson1]# ls
dir1 file.c touch
[root@VM-8-8-centos lesson1]# rmdir touch
[root@VM-8-8-centos lesson1]# ls
dir1 file.c
2. rm指令
[root@VM-8-8-centos lesson1]# ls
file.c
[root@VM-8-8-centos lesson1]# rm file.c
3. rm-r指令
[root@VM-8-8-centos lesson1]# rm -r dir1
rm: descend into directory ‘dir1’? y
rm: descend into directory ‘dir1/dir2’? y
rm: descend into directory ‘dir1/dir2/dir3’? y
rm: remove directory ‘dir1/dir2/dir3/dir4’? y
rm: remove directory ‘dir1/dir2/dir3’? y
rm: remove directory ‘dir1/dir2’? y
rm: remove directory ‘dir1’? y
4. rm -rf指令
以上是关于linux基本指令(上)的主要内容,如果未能解决你的问题,请参考以下文章