IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 系统运维 -> linux文件管理 -> 正文阅读

[系统运维]linux文件管理

1、常用文件命令

touch ——新建文件,修改文件时间(touch -t YYYYMMDDHHMM file) 把文件时间改为指定时间
1、touch file1 file2 file touch一次可以建多个文件
2、stat 查看时间标识

  [root@foundation50 Desktop]# stat file  查看文件时间标识
				  File: file
				  Size: 0         	Blocks: 0          IO Block: 4096   regular empty file
				Device: fd00h/64768d	Inode: 868628592   Links: 1
				Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)   
				Context: unconfined_u:object_r:user_home_t:s0 
				Access: 2021-07-30 10:20:38.005413746 +0800  表示文件最后一次被访问的时间
				Modify: 2021-07-30 10:20:38.005413746 +0800   表示文件内容最后一次被修改的时间
				Change: 2021-07-30 10:20:38.005413746 +0800  标识文件内容或在文件属性被修改的时间
				 Birth: -

mkdir 建立目录
mkidr -p test/redhat/linux -p建立多级目录

rm 删除文件或者目录

gedit 图形的文本编辑器
vim 文本编辑器
vim -o 上下模式打开两个文件用ctrl+w 上|下来转换控制窗口
vin -p 左右打开两个文件 tabn 进入下一个窗口
tabp 进入上一个窗口

cat 显示文件的全部内容

[root@foundation50 Desktop]# cat file
westos

cat -b 显示文件内容并显示行号,但不显示空行号

[root@foundation50 Desktop]# cat -b file

     1	westos
     2	linux
     3	too

cat -n 显示文件内容并显示空行号

[root@foundation50 Desktop]# cat -n file
     1	
     2	westos
     3	linux
     4	too

head -n 查看文件前多少行 , -n 代表数字

[root@foundation50 Desktop]#  cat -n file
     1	
     2	westos
     3	linux
     4	too
[root@foundation50 Desktop]# head -2 file

westos

tail -n 查看文件后多少行

[root@foundation50 Desktop]# cat -n file
     1	
     2	westos
     3	linux
     4	too
[root@foundation50 Desktop]# tail -2 file 查看后两行
linux
too

less 分页浏览,浏览是v进入vim 编辑模式:wq退出vim,q退出less

cp 文件 目的地文件
cp 文件1 文件2 目的地目录(此目录必须先存在)
cp -r 目录1 目录2

mv 移动文件
mv file file1 dir 目的地文件要存在
mv dir dir1 dir 此时目的文件一定要存在
mv file westos 不存在westos 时相当于重新命名的过程
相同设备分区中移动是重新命名的过程,不同分区是建立和删除的过程,可以用ls -i查看文件节点号

file 查看文件真实类型,文件名词不能确定文件类型,确定文集内容的因素是文件内容

[root@foundation50 Desktop]# file westos.mp3  
westos.mp3: empty  是一个空文件

[root@foundation50 Desktop]# cat westos.mp3 
westos
[root@foundation50 Desktop]# file westos.mp3    纯文本文件
westos.mp3: ASCII text

[root@foundation50 Desktop]# cat  westos.mp3    
#!/bin/bash
[root@foundation50 Desktop]# file westos.mp3   shell文件
westos.mp3: Bourne-Again shell script, ASCII text executable

[root@foundation50 Desktop]# cat westos.mp3 
#include<stdio.h>
[root@foundation50 Desktop]# file westos.mp3   c语言文件
westos.mp3: C source, ASCII text

wc 文件容量统计
[root@foundation50 Desktop]# wc westos
1(行数1) 1 (单词数1) 7 westos (子符数7,六个字母+一个换行符)
wc -l 统计文件行数

[root@foundation50 Desktop]# wc -l westos 
1 westos

wc -c 统计文件字节数 英文一个单词代表一个字节,一个汉字代表三个字节

[root@foundation50 Desktop]# wc -c  westos 
7 westos

wc -m 统计文件字符数

[root@foundation50 Desktop]# wc -m  westos 
7 westos

wc -w 统计文件单词数

[root@foundation50 Desktop]# wc -w  westos 
1 westos

2、linux层级结构

目录名目录作用
bin系统常规命令
sbin系统管理命令
boot系统启动分区,系统启动时读取的文件,如果boot里面的没了,系统就启动不了了
dev设备文件
etc系统配置文件
home普通用户家目录集合,相当于王子荣耀的泉水,也就是linux刚登陆进取没做任何操作的目录
root超级用户的家目录
lib/lib64系统函数库
media移动设备挂载点
mnt临时挂载点
opt第三方软件安装的位置
proc系统进程目录
run系统正在运行的
srv系统数据常量
var系统数据变量,例如log日志
sys系统识别的驱动,或在系统优化时优化的规则
tmp临时文件,临时目录
usr系统资源目录,仅此于/

lib函数库理解图 :
在这里插入图片描述

3、linux 系统如何识别u盘

下载ntfs安装包就可以识别u盘了

[root@foundation50 pub]# rpm -ivh ntfs-3g-2015.3.14-2.el7.x86_64.rpm 
reboot

4、linux文件寻址命令

pwd 显示当前的工作目录

[root@foundation50 ~]# pwd
/root

cd ~-=cd - 表示目录之前所在目录 (-只能在cd中使用其他命令里面使用不了)

 [root@foundation50 ~]# pwd
/root
[root@foundation50 ~]# cd /mnt
[root@foundation50 mnt]# cd -
/root
[root@foundation50 ~]# cd -
/mnt

5、ls 显示文件信息

命令作用
ls显示当前目录中文件的名称
ls file显示指定文件名称
ls dir显示指定目录中内容的名称
ls -d dir显示目录本身的名称
ls -l file显示文件属性
ls -l dir显示目录中内容的属性
ls -ld dir显示目录本身属性
ls -a dir显示目录中所有文件名称包括隐藏文件案
ls -s显示文件大小
[root@foundation50 Desktop]# ls  显示当前文件名称
file1  file2  RH124  westosdir
[root@foundation50 Desktop]# ls -a   显示目录中所有文件名称包括隐藏文件案
.  ..  file1  file2  RH124  .westos  westosdir
[root@foundation50 Desktop]# ls -s file1   显示文件大小
0 file1
[root@foundation50 Desktop]# vim file1
[root@foundation50 Desktop]# ls -s file1
4 file1
[root@foundation50 Desktop]# ls -l file1  显示文件属性
-rw-r--r--. 1 root root 8 Aug  1 14:28 file1
[root@foundation50 Desktop]# ls -l westosdir/  只能显示目录低下的文件属性
total 0
-rw-r--r--. 1 root root 0 Aug  1 14:19 file1
-rw-r--r--. 1 root root 0 Aug  1 14:19 file2
root@foundation50 Desktop]# ls -ld westosdir/** 显示目录本身属性
drwxr-xr-x. 2 root root 32 Aug  1 14:19 westosdir/
[root@foundation50 Desktop]# ls -R 递归显示文件
.:
file1  file2  RH124  westosdir

./RH124:
'10. Linux系统中的日志管理'                '7. Linux 中的进程管理'
'11. Linux 中的网络配置'                   '8. Linux 中的远程登陆服务'
'13. Linux 下的虚拟化部署'                 '9. Linux 系统中的文件传输'
'14. Linux 中的无人职守安装脚本kickstart'   uint.1
'15. Linux 系统引导过程及引导修复'          unit.2
'16. 系统定时任务和延时任务'                unit.3
'5. Linux系统中的用户管理'                  unit.4
'6. Linux系统中的权限管理'

./westosdir:
file1  file2

4. 文件批量处理

命令作用
*##匹配0~任意字符
?##匹配单个字符
[[:alpha:]]##匹配单个字母
[[:lower:]]##匹配单个小写字母
[[:upper:]]##匹配单个大写字母
[[:digit:]]##匹配单个数字
[[:alnum:]]##匹配单个数字或字母
[[:punct:]]##匹配单个符号
[[:space:]]##匹配单个空格
[root@foundation50 Desktop]# cp /etc/*.conf .   *表示0到任意字符
[root@foundation50 Desktop]# touch file1 file2 file11 file22 file12
[root@foundation50 Desktop]# rm -fr file?    ?表示匹配单个字符
[root@foundation50 Desktop]# ls
file11  file12  file22  
[root@foundation50 Desktop]# rm -fr file??  ??表示删除两个字符以此类推

[root@westoslinux Desktop]# touch wes1tos wesAtos wesatos wes@tos wes" "tos 
[root@westoslinux Desktop]# rm -fr wes?tos
[root@westoslinux Desktop]# touch wes1tos wesAtos wesatos wes@tos wes" "tos
[root@westoslinux Desktop]# rm -fr wes[[:alpha:]]tos
[root@westoslinux Desktop]# touch wes1tos wesAtos wesatos wes@tos wes" "tos
[root@westoslinux Desktop]# rm -fr wes[[:lower:]]tos
[root@westoslinux Desktop]# touch wes1tos wesAtos wesatos wes@tos wes" "tos
[root@westoslinux Desktop]# rm -fr wes[[:upper:]]tos
[root@westoslinux Desktop]# touch wes1tos wesAtos wesatos wes@tos wes" "tos
[root@westoslinux Desktop]# rm -fr wes[[:digit:]]tos
[root@westoslinux Desktop]# touch wes1tos wesAtos wesatos wes@tos wes" "tos
[root@westoslinux Desktop]# rm -fr wes[[:slnum:]]tos
[root@westoslinux Desktop]# rm -fr wes[[:alnum:]]tos
[root@westoslinux Desktop]# touch wes1tos wesAtos wesatos wes@tos wes" "tos
[root@westoslinux Desktop]# rm -fr wes[[:punct:]]tos
[root@westoslinux Desktop]# touch wes1tos wesAtos wesatos wes@tos wes" "tos
[root@westoslinux Desktop]# rm -fr wes[[:space:]]tos
[root@westoslinux Desktop]# touch wes1tos wesAtos wesatos wes@tos wes" "tos
[root@westoslinux Desktop]# rm -fr wes[![:space:]]tos
[root@westoslinux Desktop]# touch wes1tos wesAtos wesatos wes@tos wes" "tos
[root@westoslinux Desktop]# rm -fr wes[![:space:][:digit:]]tos
[root@westoslinux Desktop]# touch wes1tos wesAtos wesatos wes@tos wes" "tos
[root@westoslinux Desktop]# rm -fr wes[[:space:][:digit:]]tos

5、 字符集合表示方法

[] 条件是或者关系模糊匹配,[1-10] 1到10 [!d-f]|[^d-f] 除了d-f以外
若在操作时没有该文件会自动跳过不会报错
{} 精确指定集合中的每一个元素 {1…10} 1-10 {a…c} a-c {1,3,5}表示1、3、5三个
若在操作时没有该文件会报错

[root@westoslinux Desktop]# touch westos{1..5}{a..f}
[root@westoslinux Desktop]# rm -fr westos[3-5]?
[root@westoslinux Desktop]# touch westos{1..5}{a..f}
[root@westoslinux Desktop]# rm -fr westos[^3-5]?
[root@westoslinux Desktop]# touch westos{1..5}{a..f}
[root@westoslinux Desktop]# rm -fr westos[^35]?     
[root@foundation50 Desktop]# touch westos{1..5}{a..f}
[root@foundation50 Desktop]# rm -fr westos[1-3]*
[root@foundation50 Desktop]# touch westos{1..5}{a..f}
[root@foundation50 Desktop]# rm -fr westos[13]*
[root@foundation50 Desktop]# touch westos{1..5}{a..f}
[root@foundation50 Desktop]# rm -fr westos[1,3]*
[root@foundation50 Desktop]# touch westos{1..5}{a..f}
[root@foundation50 Desktop]# rm -fr westos{1..3}*
[root@foundation50 Desktop]# touch westos{1..5}{a..f}
[root@foundation50 Desktop]# rm -fr westos[!1,3]*
[root@foundation50 Desktop]# touch westos{1,5}{a..f}
[root@foundation50 Desktop]# touch westos{1,5}{a..f}
[root@foundation50 Desktop]# touch westos{1..5}{a..f}
[root@foundation50 Desktop]# rm -fr westos{1,3}*

     cd ..              当前目录的上级目录
    ~              默认代表当前用户家目录
    ~username      指定用户家目录
    ~+  =  .       当前目录
[root@foundation50 ~]# cd ~westos
[root@foundation50 westos]# pwd
/home/westos
[root@foundation50 westos]# cd ~+
[root@foundation50 westos]# pwd
/home/westos
[root@foundation50 westos]# cd -
/home/westos
[root@foundation50 westos]# cd /mnt
[root@foundation50 mnt]# cd -
/home/westos
[root@foundation50 westos]# pwd
/home/westos
[root@foundation50 westos]# cd ..
[root@foundation50 home]# pwd
/home

练习题:
1.用命令和正则表达式按照要求建立文件
*)用一条命令建立12个文件WESTOS_classX_linuxY(X的数值范围为1-2,Y的数值范围为1-6)
*)这些文件都包含在root用户桌面的study目录中
*)用一条命令建立8个文件redhat_versionX(x的范围为1-8)
*)redhat_virsionX这些文件都包含在/mnt目录中的VERSION中
2.管理刚才信建立的文件要求如下
*)用一条命令把redhat_versionX中的带有奇数的文件复制到桌面的SINGLE中
*)用一条命令把redhat_versionX中的带偶数数的文件复制到/DOUBLE中
*)用一条命令把WESTOS_classX_linuxY中class1的文件一动到当前用户桌面的CLASS1中
*)用一条命令把WESTOS_classX_linuxY中class2的文件一动到当前用户桌面的CLASS2中

[root@westoslinux Desktop]# mkdir study SINGLE CLASS{1,2} /mnt/VERSION /DOUBLE
[root@westoslinux Desktop]# ls -d study SINGLE CLASS{1,2} /mnt/VERSION /DOUBLE
CLASS1  CLASS2  /DOUBLE  /mnt/VERSION  SINGLE  study
[root@westoslinux Desktop]# touch study/WESTOS_class{1,2}_Linux{1..6} /mnt/VERSION/redhat_version{1..8} 
[root@westoslinux Desktop]# ls study/WESTOS_class{1,2}_Linux{1..6} /mnt/VERSION/redhat_version{1..8} 
/mnt/VERSION/redhat_version1  study/WESTOS_class1_Linux3
/mnt/VERSION/redhat_version2  study/WESTOS_class1_Linux4
/mnt/VERSION/redhat_version3  study/WESTOS_class1_Linux5
/mnt/VERSION/redhat_version4  study/WESTOS_class1_Linux6
/mnt/VERSION/redhat_version5  study/WESTOS_class2_Linux1
/mnt/VERSION/redhat_version6  study/WESTOS_class2_Linux2
/mnt/VERSION/redhat_version7  study/WESTOS_class2_Linux3
/mnt/VERSION/redhat_version8  study/WESTOS_class2_Linux4
study/WESTOS_class1_Linux1    study/WESTOS_class2_Linux5
study/WESTOS_class1_Linux2    study/WESTOS_class2_Linux6
[root@westoslinux Desktop]# cp /mnt/VERSION/redhat_version{1,3,5,7} SINGLE/
[root@westoslinux Desktop]# ls SINGLE/
redhat_version1  redhat_version3  redhat_version5  redhat_version7
[root@westoslinux Desktop]# cp /mnt/VERSION/redhat_version[2468] /DOUBLE/
[root@westoslinux Desktop]# ls /DOUBLE/
redhat_version2  redhat_version4  redhat_version6  redhat_version8
[root@westoslinux Desktop]# mv study/*class1* CLASS1/
[root@westoslinux Desktop]# mv study/*class2* CLASS2/
[root@westoslinux Desktop]# ls CLASS1/
WESTOS_class1_Linux1  WESTOS_class1_Linux3  WESTOS_class1_Linux5
WESTOS_class1_Linux2  WESTOS_class1_Linux4  WESTOS_class1_Linux6
[root@westoslinux Desktop]# ls CLASS2/
WESTOS_class2_Linux1  WESTOS_class2_Linux3  WESTOS_class2_Linux5
WESTOS_class2_Linux2  WESTOS_class2_Linux4  WESTOS_class2_Linux6
  系统运维 最新文章
配置小型公司网络WLAN基本业务(AC通过三层
如何在交付运维过程中建立风险底线意识,提
快速传输大文件,怎么通过网络传大文件给对
从游戏服务端角度分析移动同步(状态同步)
MySQL使用MyCat实现分库分表
如何用DWDM射频光纤技术实现200公里外的站点
国内顺畅下载k8s.gcr.io的镜像
自动化测试appium
ctfshow ssrf
Linux操作系统学习之实用指令(Centos7/8均
上一篇文章      下一篇文章      查看所有文章
加:2021-08-04 11:37:16  更:2021-08-04 11:39:49 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/10 15:56:24-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码