Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

The method of finding, modifying and reading Linux files

Shulou Source: shulou.com Published: 2022-06-02 04:25:53 09月20日 Update

This article introduces the "Linux file search, modification and reading methods" related knowledge, in the actual case of the operation process, many people will encounter such a dilemma, and then let the editor lead you to learn how to deal with these situations! I hope you can read it carefully and be able to achieve something!

1. Find a file that contains keywords

Find the current directory. / and all files in the subdirectory that contain the "192" keyword

Find. / "*. *" | xargs grep-s "192"

two。 Modify system time

Set hardware time

Hwclock-set-date= "09:45 on 10-21-19"

Synchronization system time is hardware time hwclock-w

3. Batch modify files to change 9443 in all suffixes .conf files to 8080sed-I's Unix 9443Accord 8080Accord'* .conf

4. Use awk to count log time script example

Each line of the log 1.log is shaped like A&B&C&D&E&Time=256&F&G&H&K

We need to extract the information in the Time=256 column.

Cat 1.log | awk-F "&"'{print $6}'

The delimiter is & print out the sixth column

Further, the average value is calculated by statistical Time.

Cat 1.log | awk-F "&"'{print $6}'

| | awk-F'='{print $2}'| awk'{print a/NR} 1} END {print a/NR} "

5. Copy some lines of the file sed-n '5997p' 1.txt > > 2.txt

6. Read the contents of the file line by line filename is the file to be read scenario 1, #! / bin/bashcat filename | while read linedoecho $linedone

Option 2. For line in `cat filename`doecho $linedone

Option 3. #! / bin/bashwhile read linedoecho $linedone < filename

This is the end of the content of "methods for finding, modifying and reading Linux files". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: File time content scheme method key keyword log more knowledge hardware system statistics utility achievement next examples information delimiters suffixes Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Shulou Tech Info Linux Redmi Shulou Information