linux下编辑某个文件,linux下修改以某个字母开头的文件后戳
1、怎么在linux下修改以某一字母开头的文件后戳
源文件内容[root@localhost test]# ls
stu10.txt.php stu3.txt.php stu6.txt.php stu9.txt.php test3.txt
stu1.txt.php stu4.txt.php stu7.txt.php test1.txt test4.txt
stu2.txt.php stu5.txt.php stu8.txt.php test2.txt test5.txt
现在我们将以s开头的所有文件的后戳修改为.html
第一步:先将以s开头的文件找出来[root@localhost test]# find -type f -name "s*"
./stu8.txt.php
./stu7.txt.php
./stu6.txt.php
./stu9.txt.php
./stu3.txt.php
./stu4.txt.php
./stu2.txt.php
./stu5.txt.php
./stu1.txt.php
./stu10.txt.php
第二步:取文件的前半部分[root@localhost test]# find -type f -name "s*"|awk -F"[./]+" '{print $2}'
stu8
stu7
stu6
stu9
stu3
stu4
stu2
stu5
stu1
stu10
第三步:使用拼接的方法来实现文件后戳的修改[root@localhost test]# find -type f -name "s*"|awk -F"[./]+" '{print "mv "$2".txt.php "$2".html"}'
mv stu8.txt.php stu8.html
mv stu7.txt.php stu7.html
mv stu6.txt.php stu6.html
mv stu9.txt.php stu9.html
mv stu3.txt.php stu3.html
mv stu4.txt.php stu4.html
mv stu2.txt.php stu2.html
mv stu5.txt.php stu5.html
mv stu1.txt.php stu1.html
mv stu10.txt.php stu10.html
第四步:将拼接的内容交给bash来处理[root@localhost test]# find -type f -name "s*"|awk -F"[./]+" '{print "mv "$2".txt.php "$2".html"}'|bash
第五步:查看修改后的内容[root@localhost test]# ll
total 0
-rw-r--r--. 1 root root 0 Jul 22 11:47 stu10.html
-rw-r--r--. 1 root root 0 Jul 22 11:47 stu1.html
-rw-r--r--. 1 root root 0 Jul 22 11:47 stu2.html
-rw-r--r--. 1 root root 0 Jul 22 11:47 stu3.html
-rw-r--r--. 1 root root 0 Jul 22 11:47 stu4.html
-rw-r--r--. 1 root root 0 Jul 22 11:47 stu5.html
-rw-r--r--. 1 root root 0 Jul 22 11:47 stu6.html
-rw-r--r--. 1 root root 0 Jul 22 11:47 stu7.html
-rw-r--r--. 1 root root 0 Jul 22 11:47 stu8.html
-rw-r--r--. 1 root root 0 Jul 22 11:47 stu9.html
-rw-r--r--. 1 root root 0 Jul 22 11:41 test1.txt
-rw-r--r--. 1 root root 0 Jul 22 11:41 test2.txt
-rw-r--r--. 1 root root 0 Jul 22 11:41 test3.txt
-rw-r--r--. 1 root root 0 Jul 22 11:41 test4.txt
-rw-r--r--. 1 root root 0 Jul 22 11:41 test5.txt
可以看到已经将所有以s开头的文件名后戳全部修改为.html
2、以上修改文件后戳的方法还可以使用脚本来实现
脚本内容如下#!/bin/bash
workDir=/server/file/test 将目录定义为一个变量
if [ -d $workDir ];then 判断目录是否存在,存在则进入,不存在则推出
cd $workDir
else
exit 1
fi
for i in $(find -type f -name "[s]*") 用for循环来查找以s开头的文件
do
char=`echo $i|awk -F"[/.]+" '{print $2}'` 定义要修改的文件前半部分
mv $i ${char}.html 将文件修改为想要的内容
done
linux下编辑某个文件,linux下修改以某个字母开头的文件后戳相关推荐
- Python语言编程学习:文件路径变量修改,利用os模块固定文件父路径,变换文件子路径实现代码
Python语言编程学习:文件路径变量修改,利用os模块固定文件父路径,变换文件子路径实现代码 目录 文件路径变量修改,利用os模块固定文件父路径,变换文件子路径实现代码
- linux视频编辑软件字幕,Linux下的视频字幕编辑
一.Linux下的字幕编辑软件 常用的有subtitleeditor, gnome-subtitles, gaupol 1.gnome-subtitles:不支持多字幕文件批量处理 2.gaupol: ...
- linux+find参数详解,Linux下find命令详解
[概述] find命令是Linux中一个很强大的查找命令,用于在目录结构中搜索文件并执行指定操作.只要具有相应的权限,即使系统中含有网络文件系统(NFS),find 命令在该文件系统中同样有效.由于f ...
- linux 查找目录或文件,linux 查找目录或文件详解
查找目录:find /(查找范围) -name '查找关键字' -type d 查找文件:find /(查找范围) -name 查找关键字 -print 如果需要更进一步的了解,可以参看Linux的命 ...
- 嵌入式 Linux 入门(二、Linux 文件系统、文件类型及权限管理)
嵌入式 Linux入 门第二课, linux 文件系统.文件类型及权限管理. ...... 矜辰所致 目录 前言 一.Linux 文件属性 1.1 Linux 文件类型 1.2 Linux 文件权限及 ...
- python 获取文件夹所有文件列表_python获取文件夹下所有文件及os模块方法
python获取文件夹下所有文件 方法一:使用os.listdir import os for filename in os.listdir(r'c:\windows'): print filenam ...
- Windows下通过cmd命令获取当前文件夹下所有文件的绝对路径
新建一个findFilesPath.txt 文本 文本里面输入: DIR *.* /S /B >List.txt 将文件后缀名修改为bat 双击findFilesPath.bat文件,会在同级目 ...
- dot-files/directories 点开头的文件或文件夹(windows/linux)
What's so special about directories whose names begin with a dot? 不管是 windows 系统,还是类 linux 系统,以点开头的文 ...
- linux先运行后面指令,Linux基础命令(6)
三十八 cat命令简介 cat命令的用途是连接文件或标准输入并打印.这个命令常用来显示文件内容,或者将几个文件连接起来显示,或者从标准输入读取内容并显示,它常与重定向符号配合使用. 1.命令格式: c ...
最新文章
- 【Qt】QImage、QPixmap、QBitmap和QPicture
- random函数用法_Python函数式编程:从入门到走火入魔
- webpack中跨域请求proxy代理(vue与react脚手架不同设置方法)
- 为什么对gRPC做负载均衡会很棘手?
- 《Python 快速入门》一千个程序员有一千套编码规范
- jQuery 图片裁剪插件 Jcrop
- 实战scrapy-爬取红袖添香前20页小说
- linux之FTP服务器安装 一看就会!!!动手还是会!!!
- apt安装openjdk8
- 关于cknife与burpsuite对java的版本需求的冲突机器解决办法
- 计算机怎么看ping,如何查看自己电脑的PING
- WEEK 7作业 A-TT的魔法猫 B-TT的旅行日记 C-TT的美梦
- 基于深度学习的中文语音识别系统框架搭建
- CSS grid 网格布局
- Windows系统下的部分dos命令
- Oracle 循环插入数据
- 共享3d打印机ppt分享
- k8s教程(Volume篇)-PV详解
- 夜访阿里总部:实拍双11背后神秘的程序员!
- 马云卸任演讲:因为信任,所以简单
热门文章
- leetcode 332. Reconstruct Itinerary | 332. 重新安排行程(Java)
- C# 约瑟夫环 用数组实现
- 响应式关系数据库处理R2DBC
- 看动画学算法之:排序-冒泡排序
- 浅谈装饰模式应用于IO中
- python抖音github_GitHub - eternal-flame-AD/Douyin-Bot: Python 抖音机器人,论如何在抖音上找到漂亮小姐姐?...
- PowerDesigner生成mysql字段comment 注释
- Mysql常用30种SQL查询语句优化方法
- 数据结构(3) -- 栈和队列
- 享元模式在JDK源码中的应用——Java设计模式系列学习笔记