Modify a file post-stamp that starts with a letter under Linux

Source: Internet
Author: User

1. How to modify the post-stamp of a file starting with a letter under Linux

Source file Contents

[Email protected] test]# lsstu10.txt.php stu3.txt.php stu6.txt.php stu9.txt.php test3.txtstu1.txt.php stu4.txt.php stu7.txt.php test1.txt test4.txtstu2.txt.php stu5.txt.php stu8.txt.php test2.txt test5.txt

Now we'll modify the post-stamp of all files starting with S to. html

First step: Find the file that starts with S

[Email protected] test]# find-type f-name "s*"./stu8.txt.php./stu7.txt.php./stu6.txt.php./stu9.txt.php./ stu3.txt.php./stu4.txt.php./stu2.txt.php./stu5.txt.php./stu1.txt.php./stu10.txt.php


Step two: Take the first half of the file

[[email protected] test]# find-type f-name "s*" |awk-f "[./]+" ' {print $} ' Stu8stu7stu6stu9stu3stu4stu2stu5stu1stu10

Step three: Use the Stitching method to implement file post-stamp modification

[[email protected] test]# find-type f-name "s*" |awk-f "[./]+" ' {print "MV" $ ". Txt.php" $ ". html"} ' MV stu8.txt.php stu8. HTMLMV stu7.txt.php stu7.htmlmv stu6.txt.php stu6.htmlmv stu9.txt.php stu9.htmlmv stu3.txt.php stu3.htmlmv stu4.txt.php STU4.HTMLMV stu2.txt.php stu2.htmlmv stu5.txt.php stu5.htmlmv stu1.txt.php stu1.htmlmv stu10.txt.php stu10.html

Fourth step: Send the contents of the stitching to bash for processing

[Email protected]ost test]# find-type f-name "s*" |awk-f "[./]+" ' {print "MV" $ ". Txt.php" $ ". html"} ' |bash

Fifth step: View the Modified content

[[Email protected] test]# lltotal 0-rw-r--r--.  1 root root 0 jul  22 11:47 stu10.html-rw-r--r--.  1 root root 0 jul 22 11:47  stu1.html-rw-r--r--.  1 root root 0 Jul 22 11:47  Stu2.html-rw-r--r--.  1 root root 0 jul 22 11:47 stu3.html-rw-r--r--.  1 root root 0 jul 22 11:47 stu4.html-rw-r--r--.  1 root  root 0 jul 22 11:47 stu5.html-rw-r--r--.  1 root root 0  jul 22 11:47 stu6.html-rw-r--r--.  1 root root 0 jul 22  11:47 stu7.html-rw-r--r--.  1 root root 0 Jul 22 11:47  Stu8.html-rw-r--r--.  1 root root 0 jul 22 11:47 stu9.html-rw-r--r--.  1 root root 0 jul 22&nBsp;11:41 test1.txt-rw-r--r--.  1 root root 0 Jul 22 11:41  Test2.txt-rw-r--r--.  1 root root 0 jul 22 11:41 test3.txt-rw-r--r--.  1 root root 0 jul 22 11:41 test4.txt-rw-r--r--.  1 root  root 0 jul 22 11:41 test5.txt

You can see that all filenames that begin with s have been modified to. html




2, the above method of modifying file post-stamp can also use script to implement

The script content is as follows

#!/bin/bashworkdir=/server/file/test defines a directory as a variable if [-D $workDir];then to determine if the directory exists, exists then enters, does not exist and then launches the CD $workDire LSE Exit 1FIFOR I in $ (find-type f-name "[s]*") use for loop to find files starting with S do char= ' echo $i |awk-f ' [/.] + "' {print $} ' defines the first half of the file to be modified MV $i ${char}.html to modify the file to the desired content done

This article is from the "one small step per day" blog, so be sure to keep this source http://fenyuer.blog.51cto.com/11265169/1950044

Modify file post-stamp with a letter starting with Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.