Linux目录和文件高级操作详述

一、Linux目录结构

Linux目录结构采用树形目录结构,包含根目录和子目录。

Linux目录和文件高级操作详述

1、根目录

所有分区、目录、文件等的位置起点,整个树形目录结构中,使用独立的一个“/”表示。

2、子目录

常见的子目录如/root、/bin、/boot、/dev、/etc、/home、/var、/usr、/sbin。

3、子目录的作用

Linux目录和文件高级操作详述

二、Linux查看文件内容基础命令 1、cat——查看文件内容

cat用于一次性显示文件全部内容。基本语法格式如下:

应用举例:

[root@CentOS01 ~]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 [root@centos01 ~]# cat /etc/sysconfig/network # Created by anaconda [root@centos01 ~]# cat /etc/sysconfig/network /etc/hosts # Created by anaconda 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 2、more——查看文件内容

more用于全屏模式分页显示文件内容。基本语法格式如下:

交互操作方法:

按Enter键向下逐行滚动;

按空格键向下翻一屏;

按q键退出;

应用举例:

[root@centos01 ~]# more /etc/httpd/conf/httpd.conf # # This is the main Apache HTTP server configuration file. It contains the # configuration directives that give the server its instructions. # See <URL:> for detailed information. # In particular, see # <URL:> --More--(2%) 3、less——查看文件内容

less命令的作用与more命令相同,但扩展功能更多。基本语法格式如下:

Linux目录和文件高级操作详述

交互操作方法:

Page Up键:向上翻页;

Page Down键:向下翻页;

“/”键:查找关键内容;

“n”:查找下一个关键内容;

“N”:查找上一个关键内容;

其他功能与more命令基本类似;

4、head、tail——查看文件内容

head、tail命令的基本语法格式如下:

Linux目录和文件高级操作详述

Linux目录和文件高级操作详述

head:查看文件开头的一部分内容(默认为10行);

tail:查看文件结尾的一部分内容(默认为10行);

应用举例:

[root@centos01 ~]# head -2 /var/log/messages <!--显示文件的开始2行内容--> Jan 10 20:20:01 centos01 systemd: Started Session 9 of user root. Jan 10 20:20:01 centos01 systemd: Starting Session 9 of user root. [root@centos01 ~]# [root@centos01 ~]# tail -3 /var/log/messages <!--显示文件的最后3行内容--> Jan 10 23:10:01 centos01 systemd: Starting Session 30 of user root. Jan 10 23:20:01 centos01 systemd: Started Session 31 of user root. Jan 10 23:20:01 centos01 systemd: Starting Session 31 of user root. [root@centos01 ~]# [root@centos01 ~]# tail -f /var/log/messages <!--动态跟踪文件尾部内容,便于实时监控文件内容的变化 (按Ctrl+c组合键终止)--> Jan 10 23:01:01 centos01 systemd: Starting Session 29 of user root. Jan 10 23:03:19 centos01 yum[11583]: Installed: httpd-tools-2.4.6-67.el7.centos.x86_64 Jan 10 23:03:19 centos01 yum[11583]: Installed: mailcap-2.1.41-2.el7.noarch Jan 10 23:03:20 centos01 systemd: Reloading. Jan 10 23:03:20 centos01 yum[11583]: Installed: httpd-2.4.6-67.el7.centos.x86_64 Jan 10 23:03:20 centos01 journal: g_dbus_interface_skeleton_unexport: assertion 'interface_->priv->connections != NULL' failed Jan 10 23:10:01 centos01 systemd: Started Session 30 of user root. Jan 10 23:10:01 centos01 systemd: Starting Session 30 of user root. Jan 10 23:20:01 centos01 systemd: Started Session 31 of user root. Jan 10 23:20:01 centos01 systemd: Starting Session 31 of user root. 5、wc——统计文件内容

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/11553.html