Linux performs batch operations on files under a folder

Take the decompression operation of multiple .lzma compressed files in a certain folder as an example:

Suppose there are many .lzma compressed files under your folder /home/name/folder/, then you need to use the command to cd /home/name/folder/enter this folder, and then use the following script to compress all the .lzma files under this folder.

for i in *
do
echo unlzma $i
unlzma $i
done 

The above command is equivalent to the following command

for i in *; do echo unlzma $i; unlzma $i; done 

(If the folder contains a file with a non-.lzma suffix, the command will display "File format not recognized" when the command is executed, and then skip the file, so it will not affect.)

For other operations, just apply the above template and corresponding commands.

Guess you like

Origin blog.csdn.net/qq_42194665/article/details/131725685