首页 > 系统相关 >linux rename的实现

linux rename的实现

时间:2023-08-03 11:12:48浏览次数:33  
标签:rename search string 实现 replace file linux echo

linux rename可以批量重命名文件。
rename expression replacement files

可以用bash实现:
遍历文件file,用sed等替换file中的字符串,mv $file echo $file | sed -i 's/expression/replacement/'
也可以用bash内置的parameter expansion替换。
代码如下:

#!/bin/bash

# Prompt the user for the search and replace strings
echo "Enter the string to search for: "
read search_string
echo "Enter the string to replace it with: "
read replace_string

# Loop through all files in the current directory
for file in *; do
    # Check if the file name contains the search string
    if echo "$file" | grep -q "$search_string"; then
        # Rename the file, replacing the search string with the replace string
        mv "$file" "${file/$search_string/$replace_string}"
        echo "Renamed $file to ${file/$search_string/$replace_string}"
    fi
done

标签:rename,search,string,实现,replace,file,linux,echo
From: https://www.cnblogs.com/simpleminds/p/17602751.html

相关文章

  • Linux Reserved Memory
    linux内存子系统-保留内存-知乎(zhihu.com)[内存管理]LinuxReservedMemory预留内存_memory-region_老农民哇哈哈的博客-CSDN博客 ......
  • 国产GOWIN实现低成本实现CSI MIPI转换DVP
     CSIMIPI转换DVP,要么就是通用IC操作,如龙讯芯片和索尼芯片,但是复杂的寄存器控制器实在开发太累。对于FPGA操作,大部分都是用xilinx的方案,xilinx方案成本太高,IP复杂。    而用国产GOWIN已经实现了直接mipicsi解码,而且支持非连续的clk时钟功能。   由于MIPICSI......
  • Linux 下如何修改密码有效期?
    有时我们连接远程服务器的时候,提示密码过期,需要修改密码才能登录,这时可以用chage命令来调整下用户密码的有效期,使用户可以继续使用。chage命令chage命令用于查看以及修改用户密码的有效期信息,它是changeage的缩写。当需要用户在指定时间内登录或者需要及时修改密码的时......
  • kratos项目中使用kafka实现延迟队列
    项目地址https://gitee.com/huoyingwhw/kratos_kafkaB站视频地址B站视频地址——kratos项目中使用kafka实现延迟队列......
  • linux mqtt 安装配置
    安装sudoaptinstallmosquitto配置密码用户sudomkdir-p/etc/mosquitto/configsudotouch/etc/mosquitto/config/pwfile.confsudomosquitto_passwd-b/etc/mosquitto/config/pwfile.confqq123456配置文件qtimes@AIBox-01-01-m:~$cat/etc/mosquitto/mosquitto.......
  • Linux:user is not in the sudoers file. This incident will be reported 解决方法
    学习自:userisnotinthesudoersfile.Thisincidentwillbereported解决方法_一路奔跑94的博客-CSDN博客1、原因没有在权限文件中说明该用户具有sudo权限2、解决步骤1)以root身份去/etc/sudoers文件中,编辑vi/etc/sudoers2)在rootALL=(ALL)ALL之下添加一行xxxALL......
  • L5,L6 系统调用的实现
    系统调用:进入系统的手段DPL:目标内存段的特权级CPL:当前内存段的特权级0:属于内核的特权级3:属于用户的特权级区分用户态和内核态:一种处理器的硬件设计PC:由CS和IP合在一起int指令将使CS中的CPL改成0,“进入内核”系统调用的核心用户程序中包含一段包含int指令的代码操作系统......
  • linux根据地址添加出站策略--脚本
    文件名称:add_policy.sh内容:#!/bin/bashmain(){num=1echo"<?xmlversion="1.0"encoding="utf-8"?><direct></direct>">direct.xml#read-p"请输入文件全路径名称:"ip_addrwhilereadlinedo......
  • [转]Linux下系统防火墙的发展历程和怎样学好防火墙(iptalbes和firewalld)
    原文地址:Linux下系统防火墙的发展历程和怎样学好防火墙(iptalbes和firewalld)-Repetition_Maximum-博客园有关firewalld和iptables详细使用的文章iptables详解firewalld详解=====================================华丽的分割线===================================== 1.......
  • linux环境部署nginx
    Linux环境下Nginx的离线安装与在线安装详细步骤参考地址:Nginx安装步骤——离线安装与在线安装详解_nginx依赖包_Olrookie的博客-CSDN博客CentOS7使用firewall-cmd打开关闭防火墙与端口以开放8080端口为例_firewall-cmd--add-port=8080/tcp--permanent_克豪的博客-CSDN博客一、......