栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

linux基础

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

linux基础

Linux目录结构:

/        根目录:所有的数据都是放在此目录下(linux系统的起点)
/dev     存放设备相关的数据
/boot    存放系统启动文件,包括内核、引导配置等
/root    管理员root的家目录
/etc      存放系统中各种配置文件
/usr      存放共用的,只读的用户数据
/bin、/sbin  存放基本命令、管理工具
/home    存放各普通用户的家目录

查看文件 ls:

ls -a 查看文件包括隐藏文件(以 . 开头的文件为隐藏文件)

[root@localhost log]# ls -a
.         boot.log       cron-20220227  lastlog           messages-20220227  spooler           wpa_supplicant.log
..        btmp           dmesg          maillog           ppp                spooler-20220227  wtmp
anaconda  btmp-20220301  iptraf-ng      maillog-20220227  secure             tallylog          yum.log
audit     cron           kadmind.log    messages          secure-20220227    tuned

ls -l 查看文件及其详细属性,可简写为 ll

[root@localhost log]# ll
总用量 440
drwxr-xr-x. 2 root root   4096 2月  24 17:56 anaconda
drwxr-x---. 2 root root     22 2月  24 17:56 audit
-rw-r--r--. 1 root root   8775 2月  24 17:56 boot.log
-rw-------. 1 root utmp    384 3月   2 11:43 btmp
-rw-------. 1 root utmp   3456 2月  28 14:31 btmp-20220301
-rw-------. 1 root root  40631 3月   2 11:01 cron
-rw-------. 1 root root  30168 2月  27 03:18 cron-20220227
-rw-r--r--. 1 root root  94729 2月  24 17:56 dmesg
drwxr-xr-x. 2 root root      6 10月 31 2018 iptraf-ng
-rw-r--r--. 1 root root 291416 3月   2 11:44 lastlog
-rw-------. 1 root root      0 2月  27 03:18 maillog
-rw-------. 1 root root    198 2月  24 17:57 maillog-20220227
-rw-------. 1 root root  33745 3月   2 11:44 messages
-rw-------. 1 root root 143130 2月  27 03:18 messages-20220227
drwx------. 2 root root      6 6月  10 2014 ppp
-rw-------. 1 root root   6720 3月   2 11:44 secure
-rw-------. 1 root root   6034 2月  25 17:07 secure-20220227
-rw-------. 1 root root      0 2月  27 03:18 spooler
-rw-------. 1 root root      0 2月  24 17:49 spooler-20220227
-rw-------. 1 root root      0 2月  24 17:49 tallylog
drwxr-xr-x. 2 root root     22 2月  24 17:57 tuned
-rw-r--r--. 1 root root     40 2月  24 17:56 wpa_supplicant.log
-rw-rw-r--. 1 root utmp  13056 3月   2 11:44 wtmp
-rw-------. 1 root root   5784 3月   1 15:11 yum.log

ll 中第1列为文件的权限,第3、4列分别为文件的属主、属组、第5列为文件大小

ll -h 自动识别文件大小,加单位

[root@localhost log]# ll -h
总用量 444K
drwxr-xr-x. 2 root root 4.0K 2月  24 17:56 anaconda
drwxr-x---. 2 root root   22 2月  24 17:56 audit
-rw-r--r--. 1 root root 8.6K 2月  24 17:56 boot.log
-rw-------. 1 root utmp  384 3月   2 11:43 btmp
-rw-------. 1 root utmp 3.4K 2月  28 14:31 btmp-20220301
-rw-------. 1 root root  40K 3月   2 11:01 cron
-rw-------. 1 root root  30K 2月  27 03:18 cron-20220227
-rw-r--r--. 1 root root  93K 2月  24 17:56 dmesg
drwxr-xr-x. 2 root root    6 10月 31 2018 iptraf-ng
-rw-------. 1 root root  117 3月   2 11:45 kadmind.log
-rw-r--r--. 1 root root 285K 3月   2 11:44 lastlog
-rw-------. 1 root root    0 2月  27 03:18 maillog
-rw-------. 1 root root  198 2月  24 17:57 maillog-20220227
-rw-------. 1 root root  33K 3月   2 11:44 messages
-rw-------. 1 root root 140K 2月  27 03:18 messages-20220227
drwx------. 2 root root    6 6月  10 2014 ppp
-rw-------. 1 root root 6.6K 3月   2 11:44 secure
-rw-------. 1 root root 5.9K 2月  25 17:07 secure-20220227
-rw-------. 1 root root    0 2月  27 03:18 spooler
-rw-------. 1 root root    0 2月  24 17:49 spooler-20220227
-rw-------. 1 root root    0 2月  24 17:49 tallylog
drwxr-xr-x. 2 root root   22 2月  24 17:57 tuned
-rw-r--r--. 1 root root   40 2月  24 17:56 wpa_supplicant.log
-rw-rw-r--. 1 root utmp  13K 3月   2 11:44 wtmp
-rw-------. 1 root root 5.7K 3月   1 15:11 yum.log

查看当前路径 pwd:

[root@localhost ~]# cd /var/log/
[root@localhost log]# pwd
/var/log

管道符 | :

| 表示将前边命令的输出结果传递给后边的命令执行

查看文件或日志:

cat   查看文件
more    查看文件前几行,默认10行,也可以使用cat *.log | more -10
less   分页查看文件,可以使用 [pageup] [pagedown] 等按键的功能来往前往后翻看文件
tail   查看最后几行,默认10行,也可以使用cat *.log | tail -10 (-f 为动态查看最后几行,也可简写为 tailf)

编辑文件:vi / vim 编辑器

三种工作模式
①、命令模式:
打开文件首先进入命令模式,是使用vim编辑器的入口。
在命令模式下,通过使用命令对文件进行常规的编辑操作,例如:复制(yy)、粘贴(p)、删除(del按键或x)、定位、翻页 等等。

②、末行模式:
在末行模式下,执行 退出文件、保存并退出文件 等操作。
末行模式是vim编辑器的出口,要退出vim,必须要在末行模式下。
:wq 保存并退出         :q 退出不保存     :wq!和:q!表示强制
s 替换字符串 ,/ 从上往下查找字符串,? 从下往上查找字符串,

③、编辑模式:
正常的编辑文字模式。通过“i、a、o” 进入编辑模式(i 当前光标出插入,a 当前光标后插入,o 当前光标的下一行插入)

查找文件 find:

将当前目录及其子目录下所有文件后缀为 .c 的文件列出来:
# find . -name "*.c"
(. 表示当前目录     .. 表示上级目录)
(-name name, -iname name : 文件名称符合 name 的文件。iname 会忽略大小写)

将当前目录及其子目录中的所有文件列出:
# find . -type f
(-type f 文件类型为一般文件, f 表示文件,d 表示目录)

将当前目录及其子目录下所有最近 20 天内修改过的文件列出:
# find . -mtime -20
(mtime 文件内容上次修改时间,atime 文件被读取或访问的时间,ctime 文件状态变化时间)

查找 /var/log 目录中更改时间在 7 日以前的普通文件,并在删除之前询问它们:
# find /var/log -type f -mtime +7 -exec rm {} ;

查找当前目录中文件属主具有读、写权限,并且文件所属组的用户和其他用户具有读权限的文件:
# find . -type f -perm 644 -exec ls -l {} ;
(-exec 将find命令找出的文件传递给后边的命令,-perm 查找644权限的文件)

查找系统中所有文件长度为 0 的普通文件,并列出它们的完整路径:
# find / -type f -size 0 -exec ls -l {} ;
(-size n : 文件大小 是 n 单位,b 代表 512 位元组的区块,c 表示字元数,k 表示 kilo bytes,w 是二个位元组。)
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/751080.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号