Method 1:
Copy Code code as follows:
For file in ' ls '; Do MV $file $file. txt; Done
Method 2:
Copy Code code as follows:
Find. -type f |xargs-i mv {} {}.txt
There are some unsuccessful trials, first recorded here.
1. Use the Rename command to modify the suffix name, this is the simplest and easiest way
Copy Code code as follows:
[Root@demo test_rename]# LL
Total 20
-rw-r–r–1 root root 0 09-27 00:57 rename1.log
-rw-r–r–1 root root 0 09-27 00:57 rename2.log
-rw-r–r–1 root root 0 09-27 00:57 rename3.log
-rw-r–r–1 root root 0 09-27 00:57 rename4.log
-rw-r–r–1 root root 0 09-27 00:57 rename5.log
[Root@demo test_rename]# rename log txt *.log #把 *.log to *.txt
[Root@demo test_rename]# LL
Total 20
-rw-r–r–1 root root 0 09-27 00:57 rename1.txt
-rw-r–r–1 root root 0 09-27 00:57 rename2.txt
-rw-r–r–1 root root 0 09-27 00:57 rename3.txt
-rw-r–r–1 root root 0 09-27 00:57 rename4.txt
-rw-r–r–1 root root 0 09-27 00:57 rename5.txt
[Root@demo test_rename]#
2. Modify suffix name with for, SED and MV
Copy Code code as follows:
[Root@demo test_rename]# LL
Total 20
-rw-r–r–1 root root 0 09-27 01:51 rename1.log
-rw-r–r–1 root root 0 09-27 01:21 rename2.log
-rw-r–r–1 root root 0 09-27 01:21 rename3.log
-rw-r–r–1 root root 0 09-27 01:21 rename4.log
-rw-r–r–1 root root 0 09-27 01:21 rename5.log
[Root@demo test_rename]# for I in $ (ls.)
> Do
> MV $i $ (echo $i |sed ' s/\.log/\.txt/')
> Done
[Root@demo test_rename]# LL
Total 20
-rw-r–r–1 root root 0 09-27 01:51 rename1.txt
-rw-r–r–1 root root 0 09-27 01:21 rename2.txt
-rw-r–r–1 root root 0 09-27 01:21 rename3.txt
-rw-r–r–1 root root 0 09-27 01:21 rename4.txt
-rw-r–r–1 root root 0 09-27 01:21 rename5.txt
[Root@demo test_rename]#
3. Add suffix names with Find and Xargs
Copy Code code as follows:
[Root@demo test_rename]# LL
Total 20
-rw-r–r–1 root root 0 09-27 02:20 rename1
-rw-r–r–1 root root 0 09-27 02:20 rename2
-rw-r–r–1 root root 0 09-27 02:20 Rename3
-rw-r–r–1 root root 0 09-27 02:20 rename4
-rw-r–r–1 root root 0 09-27 02:20 rename5
[Root@demo test_rename]# Find. -type f |xargs-i mv {} {}.txt
[Root@demo test_rename]# LL
Total 20
-rw-r–r–1 root root 0 09-27 02:20 rename1.txt
-rw-r–r–1 root root 0 09-27 02:20 rename2.txt
-rw-r–r–1 root root 0 09-27 02:20 rename3.txt
-rw-r–r–1 root root 0 09-27 02:20 rename4.txt
-rw-r–r–1 root root 0 09-27 02:20 rename5.txt
[Root@demo test_rename]#