linux运维命令日志管理,Linux运维实战第二天:Linux基础命令之文件处理命令
这次博客的主要内容是基础命令,虽然普通的命令没技术含量,但是有技术含量的都是以普通的命令为基础。千里之行始于足下,Let's Go!
Linux中的命令分为内部命令和外部命令两种:
内部命令:是shell程序自身附带的命令 ,随每次启动的SHELL装入并常驻内存;(类似DOS系统的内部命令,是随每次启动的COMMAND.COM装入并常驻内存)
外部命令:在某目录有一个与命令同名的可执行文件
下面总结与文件与目录处理相关的命令的用法及用途:
1、文件处理命令:ls
命令名称:ls
命令英文原意:list
命令所在路径:/bin/ls
执行权限:所有用户
功能描述:显示目录文件
语法:ls [选项] [文件或目录]
-a: 显示所有文件,包括隐藏文件
-l : 以长格式显示文件的详细属性 ,一共17个位置,大家都可以自己数下。
从左到右各个字段的含义如下:
第1位表示文件类型,主要的文件类型如下:
-:一般文件
d:目录文件
b:块设备文件
c:字符设备文件
l:链接文件
p:人工管道
234位代表文件属主权限,即文件所有者的权限
567位代表文件属组权限,即文件所属组的权限
8910位代表其他用户的权限
第11位表示文件被硬链接的次数
知识点:
硬连接就像一个文件有多个文件名,
软连接就是产生一个新文件,这个文件指向另一个文件的位置,
硬连接必须在同一文件系统中,而软连接可以跨文件系统
第12位表示文件的所属用户
第13位表示文件的所属组
第14位表示文件的大小:
如果是目录,则表示目录自身的大小,目录里的内容是不显示的
一般是以“块”为单位,一个块约等于1K
第15、16位表示文件最近一次被修改的时间:
知识点:
每个文件有三个时间,被称为文件的时间戳
最近一次被访问
最近一次被修改:修改的是文件的内容
最近一次被改变:改变的是文件的属性
第17位表示文件名(目录名)
-A:跟-a相同,但不显示.和..
-n:类似于-l,但是以用户及组的id号排序
-h:与-l一起使用,文件大小会自动进行单位换算
-r:文件名逆序显示
-R:递归显示
2、文件处理命令:cd
命令名称:cd
命令英文原意:change directory
命令所在路径:shell内置命令
执行权限:所有用户
语法:cd [目录]
功能描述:切换目录
范例:
回用户的家目录:
$ cd ~
$ cd
$ cd ~USERNAME :切换至USERNAME的家目录 (注:必须要有相应的权限)
提示权限不够哈!用管理员账号操作:
$ cd - 在两个目录间来回切换
"!$" 把上个命令最后的参数作为输入:
[root@rhel5 jjx]# ls
ab ad bin include kerberos lib sudo test
[root@rhel5 jjx]# ls test
ab ad cb cd exe sudo
[root@rhel5 jjx]# cd !$
cd test
[root@rhel5 test]#
3、文件处理命令:pwd
命令名称:pwd
命令英文原意:print working directory
命令所在路径:/bin/pwd
执行权限:所有用户
语法:pwd
功能描述:显示当前所在的工作目录
范例:
[jjx@rhel5 ~]$ pwd
[jjx@rhel5 ~]$ pwd
/home/jjx
[jjx@rhel5 ~]$ ls
ab ad bin include kerberos lib sudo test
[jjx@rhel5 ~]$ cd test
[jjx@rhel5 test]$ pwd
/home/jjx/test
4、文件处理命令:mkdir
命令名称:mkdir
命令英文原意:make directories
命令所在路径:/bin/mkdir
执行权限:所有用户
语法:mkdir [选项] [目录名]
功能描述:创建新目录
常用的选项:
-p:如果目录不存在默认创建
-v:显示创建过程
范例:
bash支持命令行展开:{}
5、文件处理命令:touch
命令名称:touch
命令所在路径:/bin/touch
执行权限:所有用户
语法:touch [文件名]
功能描述:修改文件时间戳,如果文件不存在则创建空文件
范例:
相关的命令:用stat命令查看文件的属性:
stat :查看文件的属性
access:访问
modify:修改
change:改变
范例:
6、文件处理命令:cp
命令名称:cp
命令英文原意:copy
命令所在路径:/bin/cp
执行权限:所有用户
语法:cp 选项 [源文件或目录] [目的目录]
常用选项:
-r:递归复制
-a:全递归复制,尽可能将档案状态、权限等资料都照原状予以复制,其作用等于dpR选项的组合
-i:交互式(覆盖前提醒确认)
-v:显示命令执行过程
功能描述:复制文件或目录
范例:
[jjx@rhel5 ~]$ ls
a_c a_d b_c b_d bin include kerberos lib sudo
[jjx@rhel5 ~]$ mkdir -pv test
mkdir: 已创建目录 “test”
[jjx@rhel5 ~]$ ls
a_c a_d b_c b_d bin include kerberos lib sudo test
[jjx@rhel5 ~]$ cp -rv a_c/ ./test/
“a_c/” -> “./test/a_c”
[jjx@rhel5 ~]$ ls ./test/a_c
7、文件处理命令:mv
命令名称:mv
命令英文原意:move
命令所在路径:/bin/mv
执行权限:所有用户
功能描述:移动文件、更名
语法:mv 选项 [源文件或目录] [目的目录]
常用选项:
-i:交互式(覆盖前提醒确认)
-v:显示命令执行过程
范例:
[jjx@rhel5 ~]$ ls
a_d b_c b_d bin file01.txt include kerberos lib sudo test
[jjx@rhel5 ~]$ cp -v file01.txt test/
“file01.txt” -> “test/file01.txt”
[jjx@rhel5 ~]$ mv -iv file01.txt test/
mv:是否覆盖“test/file01.txt”? y
“file01.txt” -> “test/file01.txt”
8、文件处理命令:rm
命令名称:rm
命令英文原意:remove
命令所在路径:/bin/rm
执行权限:所有用户
功能描述:删除文件
语法:rm 选项 [文件或目录]
常用选项:
-i:交互式(删除前提醒确认)
-f:强行删除
-r:递归删除目录及其内部的所有文件
范例:
[jjx@rhel5 ~]$ ls
a_d b_c b_d bin include kerberos lib sudo
[jjx@rhel5 ~]$ rm -rf a_d
[jjx@rhel5 ~]$ ls
b_c b_d bin include kerberos lib sudo
[jjx@rhel5 ~]$
[jjx@rhel5 ~]$ ls
b_c b_d bin include kerberos lib sudo
[jjx@rhel5 ~]$ rm -ir b_c
rm:是否删除 目录 “b_c”? y
[jjx@rhel5 ~]$ ls
b_d bin include kerberos lib sudo
[jjx@rhel5 ~]$
注意:使用#rm -rf 命令时要特别小心,操作是不可逆的,使用过程中也没有任何消息提示!
9、文件处理命令:cat(tac)
命令名称:cat(tac)
命令英文原意:concatenate and display files
命令所在路径:/bin/cat
执行权限:所有用户
功能描述:显示文件内容
语法:cat [文件名]
范例:
[jjx@rhel5 ~]$ ls
b_d bin file01.txt include kerberos lib sudo
[jjx@rhel5 ~]$ cat bin/
cat: bin/: 是一个目录
[jjx@rhel5 ~]$ cat file01.txt
This is a test file!
Hello World!
Today is Sunday!
[jjx@rhel5 ~]$ tac file01.txt
Today is Sunday!
Hello World!
This is a test file!
[jjx@rhel5 ~]$
10、文件处理命令:more
命令名称:more
命令所在路径:/bin/more
执行权限:所有用户
功能描述:分页显示文件内容
语法:more [文件名]
基本操作:
空格键:向后翻一屏
b:向前翻一屏
enter:向后翻一行
ctrl+d:向后翻半屏
ctrl+u:向前翻半屏
q或Q:退出
范例:
[jjx@rhel5 ~]$ more /etc/fstab
/dev/VolGroup00/LogVol00 / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
devpts /dev/pts devpts gid=5,mode=620 0 0
tmpfs /dev/shm tmpfs defaults 0 0
proc /proc proc defaults 0 0
sysfs /sys sysfs defaults 0 0
/dev/VolGroup00/LogVol01 swap swap defaults 0 0
[jjx@rhel5 ~]$
[jjx@rhel5 ~]$ more /etc/services
# /etc/services:
# $Id: services,v 1.42 2006/02/23 13:09:23 pknirsch Exp $
#
# Network services, Internet style
#
# Note that it is presently the policy of IANA to assign a single well-known
# port number for both TCP and UDP; hence, most entries here have two entries
# even if the protocol doesn't support UDP operations.
# Updated from RFC 1700, ``Assigned Numbers'' (October 1994). Not all ports
# are included, only the more common ones.
#
# The latest IANA port assignments can be gotten from
# http://www.iana.org/assignments/port-numbers
# The Well Known Ports are those from 0 through 1023.
# The Registered Ports are those from 1024 through 49151
# The Dynamic and/or Private Ports are those from 49152 through 65535
#
# Each line describes one service, and is of the form:
#
# service-name port/protocol [aliases ...] [# comment]
tcpmux 1/tcp # TCP port service multiplexer
tcpmux 1/udp # TCP port service multiplexer
rje 5/tcp # Remote Job Entry
rje 5/udp # Remote Job Entry
echo 7/tcp
echo 7/udp
discard 9/tcp sink null
discard 9/udp sink null
systat 11/tcp users
--More--(0%)
11、文件处理命令:less
命令名称:less
命令所在路径:/bin/less
执行权限:所有用户
功能描述:类似于more命令,但使用 less 可以随意浏览文件
语法:less [文件名]
基本操作:
1、搜索
当使用命令 less file-name 打开一个文件后,可以使用下面的方式在文件中搜索。搜索时整个文本中匹配的部分会被高亮显示。
向前搜索
/ - 使用一个模式进行搜索,并定位到下一个匹配的文本
n - 向前查找下一个匹配的文本
N - 向后查找前一个匹配的文本
向后搜索
? - 使用模式进行搜索,并定位到前一个匹配的文本
n - 向后查找下一个匹配的文本
N - 向前查找前一个匹配的文本
2、全屏导航
ctrl + F - 向前移动一屏
ctrl + B - 向后移动一屏
ctrl + D - 向前移动半屏
ctrl + U - 向后移动半屏
3、单行导航
j - 向前移动一行
k - 向后移动一行
4、 其它导航
G -移动到最后一行
g -移动到第一行
q 或Q-退出 less 命令
范例:
敲入G,转到文件尾部:
12、文件处理命令:head
命令名称:head
命令所在路径:/bin/head
执行权限:所有用户
功能描述:查看文件的前几行,默认查看前10行
语法:head -num [文件名]
-num 显示文件的前num行
范例:
[jjx@rhel5 ~]$ head /etc/services
# /etc/services:
# $Id: services,v 1.42 2006/02/23 13:09:23 pknirsch Exp $
#
# Network services, Internet style
#
# Note that it is presently the policy of IANA to assign a single well-known
# port number for both TCP and UDP; hence, most entries here have two entries
# even if the protocol doesn't support UDP operations.
# Updated from RFC 1700, ``Assigned Numbers'' (October 1994). Not all ports
# are included, only the more common ones.
[jjx@rhel5 ~]$ head -20 /etc/services
# /etc/services:
# $Id: services,v 1.42 2006/02/23 13:09:23 pknirsch Exp $
#
# Network services, Internet style
#
# Note that it is presently the policy of IANA to assign a single well-known
# port number for both TCP and UDP; hence, most entries here have two entries
# even if the protocol doesn't support UDP operations.
# Updated from RFC 1700, ``Assigned Numbers'' (October 1994). Not all ports
# are included, only the more common ones.
#
# The latest IANA port assignments can be gotten from
# http://www.iana.org/assignments/port-numbers
# The Well Known Ports are those from 0 through 1023.
# The Registered Ports are those from 1024 through 49151
# The Dynamic and/or Private Ports are those from 49152 through 65535
#
# Each line describes one service, and is of the form:
#
# service-name port/protocol [aliases ...] [# comment]
[jjx@rhel5 ~]$
13、文件处理命令:tail
命令名称:tail
命令所在路径:/bin/tail
执行权限:所有用户
功能描述:查看文件的后几行,默认查看后10行
语法:tail 选项 [文件名]
常用选项:
-num:显示文件的后num行
-f :动态显示文件内容
范例:
[jjx@rhel5 ~]$ tail /etc/services
nimspooler 48001/udp # Nimbus Spooler
nimhub 48002/tcp # Nimbus Hub
nimhub 48002/udp # Nimbus Hub
nimgtw 48003/tcp # Nimbus Gateway
nimgtw 48003/udp # Nimbus Gateway
com-bardac-dw 48556/tcp # com-bardac-dw
com-bardac-dw 48556/udp # com-bardac-dw
iqobject 48619/tcp # iqobject
iqobject 48619/udp # iqobject
# Local services
[jjx@rhel5 ~]$ tail -20 /etc/services
dbbrowse 47557/udp # Databeam Corporation
directplaysrvr 47624/tcp # Direct Play Server
directplaysrvr 47624/udp # Direct Play Server
ap 47806/tcp # ALC Protocol
ap 47806/udp # ALC Protocol
bacnet 47808/tcp # Building Automation and Control Networks
bacnet 47808/udp # Building Automation and Control Networks
nimcontroller 48000/tcp # Nimbus Controller
nimcontroller 48000/udp # Nimbus Controller
nimspooler 48001/tcp # Nimbus Spooler
nimspooler 48001/udp # Nimbus Spooler
nimhub 48002/tcp # Nimbus Hub
nimhub 48002/udp # Nimbus Hub
nimgtw 48003/tcp # Nimbus Gateway
nimgtw 48003/udp # Nimbus Gateway
com-bardac-dw 48556/tcp # com-bardac-dw
com-bardac-dw 48556/udp # com-bardac-dw
iqobject 48619/tcp # iqobject
iqobject 48619/udp # iqobject
# Local services
[jjx@rhel5 ~]$
14、文件处理命令:nano
nano:简单的文本编辑器
命令名称:nano
执行权限:所有用户
功能描述:用文本编辑器打开一个文件进行编辑,若文件不存在则创建新文件
语法:nano [文件名]
范例:
[jjx@rhel5 ~]$ ls
b_d bin file01.txt include kerberos lib sudo
[jjx@rhel5 ~]$ nano file02.txt
[jjx@rhel5 ~]$ ls
b_d bin file01.txt file02.txt include kerberos lib sudo
[jjx@rhel5 ~]$ cat file02.txt
This is a nano test file!
[jjx@rhel5 ~]$
与文件及目录相关的常用命令大体就是如上面所述,下面介绍下与文件处理命令相关的知识。用过DOS的地球人都知道通配符的概念,Linux的SHELL当然也支持通配符并且比DOS更为强大:
bash支持的文件通配符:
*:表示任意长度的任意字符;
?:表示任意单个字符
[]:指定范围内的任意单个字符:
[a-z]:所有的小写字母
[A-Z]:所有的大写字母
[0-9a-zA-Z]:所有的数字和字母
字符集合:
[:digit:]:所有数字,相当于0-9 如:[[:digit:]]
[:lower:]:所有小写字母
[:upper:]:所有大写字母
[:alpha:]:所有的字母
[:alnum:]:相当于[0-9a-zA-Z]
[:space:]:空白字符
[:punct:]:所有标点符号
[^]:脱字符,取反,指定范围外的任意单个字符,如:[^0-9]
范例:
将/etc/目录下以i开头的所有文件复制到./test/目录下:
[jjx@rhel5 ~]$ ls
b_d bin file01.txt file02.txt include kerberos lib sudo test
[jjx@rhel5 ~]$ cp /etc/i* test/
cp: 略过目录 “/etc/init.d”
cp: 略过目录 “/etc/iproute2”
cp: 略过目录 “/etc/isdn”
[jjx@rhel5 ~]$ lstest
idmapd.conf initlog.conf inittab inputrc issue issue.net
[jjx@rhel5 ~]$
复制/etc/目录下以p开头,中间跟了4个任意字符,并以d结尾的文件至./tmp/a目录中;如果a不存在,先创建出来;
[jjx@rhel5 ~]$ ls
b_d bin file01.txt file02.txt include kerberos lib sudo test tmp
[jjx@rhel5 ~]$ ls tmp
[jjx@rhel5 ~]$ mkdir tmp/a;cp -r /etc/p????d tmp/a
[jjx@rhel5 ~]$ ls tmp/a
passwd
[jjx@rhel5 ~]$
列出./test/下所有以数字和非数字结尾的文件:
[jjx@rhel5 test]$ ls ./test
ls: ./test: 没有那个文件或目录
[jjx@rhel5 test]$ ls
idmapd.conf initlog.conf inittab inputrc issue issue.net
[jjx@rhel5 test]$ ls *[0-9]
ls: *[0-9]: 没有那个文件或目录
[jjx@rhel5 test]$ ls *[^0-9]
idmapd.conf initlog.conf inittab inputrc issue issue.net
[jjx@rhel5 test]$ ls *[^[:digit:]]
idmapd.conf initlog.conf inittab inputrc issue issue.net
[jjx@rhel5 test]$ ls *[[:alpha:]]
idmapd.conf initlog.conf inittab inputrc issue issue.net
[jjx@rhel5 test]$
命令与shell的关系(关于shell的几点说明):
bash允许一次执行多个命令,命令之间用”;"隔开;
理解命令的程序是bash;因此,可以在bash提示符下执行命令;
shell脚本是命令的堆砌,但还有额外的流程控制机制;
命令操作技巧:
在打命令和目录的时候,我们一定要用TAB键来补全,这样比较轻松,也能检查命令是否正确。如果不能补全就证明我们敲入的命令有问题
用命令补全,TAB,他会自动加上最后那个/符号,证明这是个目录,如果后面没有/的话,这个可能是目录,也可能是文件
linux运维命令日志管理,Linux运维实战第二天:Linux基础命令之文件处理命令相关推荐
- linux系统中的日志管理
Linux系统中的日志管理 1 实验环境 2 journald日志服务 2.1 journalctl命令的用法 2.2 用journald服务永久存放日志 3 rsyslog日志服务 3.1 自定义日 ...
- 10、Linux系统中的日志管理及时间设定
Linux系统中的日志管理 实验环境 一.journald 1.journalctl命令的用法 2.永久存放日志 二.rsyslog 1.自定义日志采集路径 2.日志的远程同步 3.更改日志采集格式 ...
- Linux计划任务与日志管理
计划任务-at-cron-计划任务使用方法 日志的种类和记录方式-自定义ssh服务日志类型和存储位置 实战-日志切割-搭建远程日志收集服务器 实战-配置公司内网服务器每天定时自动开关机 1.计划任务- ...
- Linux学习-66-系统日志管理
15 Linux系统日志管理 系统日志详细地记录了在什么时间,哪台服务器.哪个程序或服务出现了什么情况.不管是哪种操作系统,都详细地记录了重要程序和服务的日志,只是我们很少养成查看日志的习惯. 日志是 ...
- Linux系统自带日志管理工具rsyslog简单介绍
1,可以已查看本机的rsyslog服务状态 sudo systemctl status rsyslog 2,可以查看服务的包的版本及配置所在目录 2.1,可以看出这个 /etc/logrotate.d ...
- 2.3 Linux系统中的日志管理
journald(systemd-journald.service) RHEL8加入了一个日志工具journald 默认日志存放地址/run/log/journal/22992d92cf33452b8 ...
- Docker技术入门与实战 第二版-学习笔记-9-Docker Compose 项目-2-Compose 命令说明
Compose 命令说明 1)命令对象与格式 对于 Compose 来说,大部分命令的对象既可以是项目本身,也可以指定为项目中 的服务或者容器.如果没有特别的说明,命令对象将是项目,这意味着项目中所有 ...
- MATLAB学习第二天(基础语法、变量、命令以及新建自己文件)
目录 一.MATLAB基本语法 执行MATLAB命令 MATLAB实践 MATLAB常用的运算符和特殊字符 MATLAB常用的运算符使用示例 MATLAB特殊变量和常量 MATLAB命名 ...
- Linux系统中的日志管理 ---systemd-journald日志(journalctl命令的用法)和 rsyslog 日志(自定义日志采集路径、更改日志采集格式和日志的远程同步)
一.实验环境 Horizon_carry: 172.25.254.10 carry: 172.25.254.20 Horizon_carry & carry: systemctl stop f ...
最新文章
- Qt Creator快捷键
- face_recognition快速入门
- Django的APP,视图,url和模板
- Java JFrame 和 Frame 的区别
- 17.深度学习练习:Character level language model - Dinosaurus land
- 小鹏汽车自动驾驶内推(社招+校招)
- “滤镜景点”太坑遭吐槽!小红书致歉:将推出景区踩坑榜
- JSP+Servlet--简易的博客功能开发
- Python+OpenCV:二维直方图(2D Histograms)
- 68. 超越 Gzip 压缩
- 最新版计算机知识超全题库,超全的计算机基础知识题库.doc
- 当电子工程师十余年,感慨万千
- UG NX重用库汉化版本
- vue中获取本地IP地址
- pip 查看某个包有哪些版本
- 如何使用IOS自动化测试工具UIAutomation
- 如何理解递归的原理?
- 在ROS下控制dobot(magician)机械手的吸盘
- 菜鸟炒美股(一) (转)
- 安装my sql数据库安装详细教程
热门文章
- 计算机应用与技术大赛,关于举办2017年燕山大学第一届计算机应用技术与程序设计大赛的通知...
- php csrf攻击教程,HTTP路由实例教程(三)—— CSRF攻击原理及其防护
- rocketmq java实战_RocketMQ实战与原理解析 杨开元著 PDF下载
- 算法提高 超级玛丽(java)
- extjs 方法执行顺序_百战程序员:方法论
- 将下图的nfa确定化为dfa_想要确定一个宝石矿物种,必须要确定这两大因素
- android 如何 查看内存使用详情,android 查看内存使用情况
- python生成一圈数包裹一圈数的数组
- 简历javaweb项目描述怎么写_硬件工程师简历-项目经验怎么写【范文】
- AOP之proceedingjoinpoint和joinpoint区别(获取各对象备忘)、动态代理机制及获取原理代理对象、获取Mybatis Mapper接口原始对象...