How to add file prefixes in batches in Linux

How to add file prefixes in batches in Linux

You need to add "gt_" in front of the file names of all txt files in the folder;

That is, the original file "xxx.txt" becomes "gt_xxx.txt":

The script I searched online is as follows:

for i in `ls`;
do mv -f $i 'echo "gt_"$i`;
done

1. First, switch the Linux command line to the directory where you need to modify the file name:

cd destination directory

2. Create a new sh file in this directory:

touch xxx.sh

3. Open the xxx.sh file:

vim xxx.sh

3. Copy the script content just now to the sh file, save and exit

Edit sh file: Shift+I

Save and exit after pasting: Ctrl+Alt +D to exit the editing state, then enter :wq! to exit

Execute sh file: ./xxx.sh

I have never come across Linux commands before, and now I need to use some of them. I am taking this note as a reminder~~~

ps: Batch change file prefix command under linux

for f in * ; do mv -- "$f" "PRE_$f" ; done

Summarize

The above is the operation method of adding file prefixes in batches in Linux introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • How to use shell script to batch add watermarks to pictures in a specified folder under Linux

<<:  Vue uses v-model to encapsulate the entire process of el-pagination components

>>:  Detailed graphic tutorial on installing and uninstalling Tomcat8 on Linux

Recommend

A brief discussion on the implementation principle of Webpack4 plugins

Table of contents Preface know Practice makes per...

Native JS to achieve drag photo wall

This article shares with you a draggable photo wa...

Use shell script to install python3.8 environment in CentOS7 (recommended)

One-click execution To install Python 3.8 in a vi...

Vue.js Textbox with Dropdown component

A Textbox with Dropdown allows users to select an...

A brief discussion on React Component life cycle functions

What are the lifecycle functions of React compone...

Rounding operation of datetime field in MySQL

Table of contents Preface 1. Background 2. Simula...

How to change the root password in MySQL 5.7

Starting from MySQL 5.7, many security updates ha...

How to build a SOLO personal blog from scratch using Docker

Table of contents 1. Environmental Preparation 2....

How to create a virtual environment using virtualenv under Windows (two ways)

Operating system: windowns10_x64 Python version: ...

Teach you how to implement a react from html

What is React React is a simple javascript UI lib...

Causes and solutions for cross-domain issues in Ajax requests

Table of contents 1. How is cross-domain formed? ...

HTTP and HTTP Collaboration Web Server Access Flow Diagram

A web server can build multiple web sites with in...

SQL insert into statement writing method explanation

Method 1: INSERT INTO t1(field1,field2) VALUE(v00...

Detailed example of using useState in react

useState useState adds some internal state to a c...