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

Summary of clipboard.js usage

Table of contents (1) Introduction: (2) The ways ...

A detailed introduction to the Linux directory structure

When you first start learning Linux, you first ne...

Detailed explanation of JavaScript state container Redux

Table of contents 1. Why Redux 2. Redux Data flow...

JavaScript implements simple calculator function

This article shares the specific code of JavaScri...

How to add file prefixes in batches in Linux

You need to add "gt_" in front of the f...

How to add and delete unique indexes for fields in MySQL

1. Add PRIMARY KEY (primary key index) mysql>A...

How to reset the initial value of the auto-increment column in the MySQL table

How to reset the initial value of the auto-increm...

Detailed explanation of real-time backup knowledge points of MySQL database

Preface The need for real-time database backup is...

How to Easily Remove Source Installed Packages in Linux

Step 1: Install Stow In this example, we are usin...

Detailed explanation of the difference between var, let and const in JavaScript

Table of contents As a global variable Variable H...

Paragraph layout and line breaks in HTML web pages

The appearance of a web page depends largely on i...

What is ZFS? Reasons to use ZFS and its features

History of ZFS The Z File System (ZFS) was develo...