linux基本指令(上)

简介: 关于linux的一部分基本指令

@TOC

1.whomai指令

[root@VM-8-8-centos ~]# whoami
root

用于查询当前用户名

若此时只有root现,说明当前只有一个超级权限用户root

2. pwd指令

显示当前所处的目录

[root@VM-8-8-centos 9.9]# pwd
/root/9.9

此时说明 我在 根目录root下的9.9目录

3. ls 指令

1. ls指令

用来显示当前命令下的所有文件(只会显示一般文件的文件名/目录)

[root@VM-8-8-centos 9.9]# ls
666.txt  lesson2

在 根目录root下的9.9目录中,有一个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

这里需要注意的是,以r开头 的就为一般文件,以d开头的就为目录

sep为日期

显示  666.txt的文件在 27日的9点48分被创建 ,

显示lesson2的目录在26日的 19点3分被创建

3.ls -la指令

这里是在 ls-l指令的基础上 ,会显示出隐藏文件

[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

相比于ls-l指令的显示,我们不难发现 多出了二行 .和 . .

这两个东西 很多时候跟cd指令一起使用

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

cd .前后目录没有变化,依旧在根目录下的9.9目录上

所以 cd .的作用是 进入当前目录

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

此时我们发现,使用cd .. 后 从根目录下的9.9目录 返回到了 根目录 root

所以 cd  . .的作用是 返回上一级目录

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

首先 ,处于根目录 root下的 9.9目录下的  lesson2目录

通过  ls - la指令, 了解到 lesson2目录下有一个 dir目录

再通过 ls -ld指令 ,找到dir目录本身,当再次pwd时,发现目录依旧处于lesson2

说明使用 ls -ld指令不是真正进入

5. ls -i指令

该指令主要能够寻找到文件所对应的inode编号

[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-x 2 root root 4096 Sep 27 14:55 dir

此时在 前面显的 数字 如 657683、657678、657694 都是文件的inode编号

linux一切皆文件

1. windows 与linux标识文件之间的区别

windows: 用文件名 +后缀来标识文件

linux使用inode编号来标识文件

4. cd指令

1.cd 指令

一般的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

刚开始在 /root/9.9/lesson2的目录下

通过 cd dir ,目录变成 /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

使用 cd ~ 后 ,使目录 从 /root/9.9/lesson2/dir 到 /root根目录中

3.cd -指令

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

原目录处于 /root/9.9/lesson2中

通过 cd ~ 处于 /root目录中

在 通过 cd - 回到 /root/9.9/lesson2 中

5. touch 指令

1.创建文件

touch +文件名 即可创建一个文件

[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

观察即可发现 使用touch bin.c后,下面多了个 bin.c的文件

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: -

使用 stat 打开 bin.c文件时,发现 共有三个  

Access (读取) 、Modify((对内容的修改时间) 、Change(对属性的修改时间)

在解答这三个 之前 想几个问题

1.创建一个大小为0的文件时,会在硬盘中占据空间么?

会的

在这里插入图片描述 虽然此时文件中没有内容,但是此时文件的名字 、大小 、日期会占据空间

2.文件的名字 、大小、    修改日期等属于文件的内容?

不是

文件的名字 、大小、日期属于 属性

所以  文件 =内容 +属性

3.属性(名字 、大小、日期)是数据么?

是的

4.文件(内容+属性)会被保留么?

是的

[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: -

我们不难发现 ,上面为空的file.txt文件 与 下面有内容的file.txt文件三个的时间发生改变

读取了两次,所以时间不相同

此时因为内容改变 ,并且字节大小改变,所以内容和属性都改变,所以后两者时间都改变了。

目录
相关文章
|
22天前
|
Linux Windows
Linux之基本指令操作
Linux之基本指令操作
|
2天前
|
安全 Linux
Linux基本指令(下)——“Linux”
Linux基本指令(下)——“Linux”
|
3天前
|
人工智能 Unix Linux
Linux基本指令
Linux基本指令
|
7天前
|
Linux Windows
|
7天前
|
Linux
Linux 指令|date|cal|find|grep|热键
Linux 指令|date|cal|find|grep|热键
|
7天前
|
Linux
Linux简单指令|cd|touch|mkdir|rmdir|rm
Linux简单指令|cd|touch|mkdir|rmdir|rm
|
7天前
|
存储 安全 Unix
Linux基本指令汇总
Linux基本指令汇总
39 2
|
25天前
|
Unix Linux Windows
Linux的基本指令讲解
Linux的基本指令讲解
40 3
|
缓存 安全 Unix
【Linux】Linux基本指令(下)
【Linux】Linux基本指令(下)
|
1月前
|
存储 人工智能 Unix
【linux】Linux基本指令(上)
【linux】Linux基本指令(上)