Linux, find and Perl Regular Expression replacement file content, tar decompression, CP replication, RM Deletion

Source: Internet
Author: User
Tags gz file perl regular expression
Document directory
  • Unzip the tar command in Linux
Find-name 'xixi. php' | xargs Perl-pi-E's | Hello | AA | G'


Find-name '*. html' | xargs Perl-pi-E's | AA | Hello | G'


Find-name '*. HTML '| xargs Perl-pi-E's | <SCRIPT src = ". JS ([^>] *)> </SCRIPT> | G' (Note: It seems that only one row can be matched)

 

In Linux, this method is used to replace a large number of files with Trojans (JS files.

 

Search for the ABC. cpp file from the root directory, with no error output
Find/-name ABC. cpp 2>/dev/null

Find the EFG function in all. cpp files in the current directory.
Find-name "*. cpp" | xargs grep 'efg'
Xargs expands the find result and uses it as a grep parameter.

In addition, commands such as rm mv report an error when operating on a large number of files-Bash:/bin/RM: argument list too long
Xargs is also available.
Delete all. cpp files in the current directory
Find-name "*. cpp" | xargs RM

 

 

In Windows, you can use the AFR-Advanced Find and replace Chinese Green official version to support regular expressions to batch Delete webpage Trojans.

 

 

 

 

There are many Swiss Army knives in Linux, and find is one of them. For example, I want to use find to quickly list objects modified in the last period. What should I do?

$ Find-mtime 0 # Find the files modified between the current directory one day ago and now, that is, the files modified in the past 24 hours.

$ Find-mtime-1 # Find the modified files in the current directory less than one day (1*24), that is, the files modified within 24 hours, this is the same as the above result.

$ Find-mtime 1 # Find the modified files whose current directory is equal to one day (1*24), that is, the files modified before 24 hours (including 1 ).

$ Find-mtime + 1 # Find the modified files in the current directory greater than one day (1*24), that is, the files modified at least two days ago. The parameter after mtime can only be an integer, so it must start from 2 if it is greater than 1.

Of course, in addition to mtime, there are also mmin (last modified n minutes ago), ctime (file-like modification time), Cmin (file state modification), atime (access time ), amin (last access time, in minutes). For detailed parameters, see man find.


Certificate ------------------------------------------------------------------------------------------------------------------------------------

 

How to copy folders in Linux

CP command
Format: CP [Option] source file or directory target file or directory
Option Description:-B with the same name.
-F forcibly overwrite files with the same name
-R: retained the original directory structure to copy files recursively.

CP-r/tmp/A/root/
Remember to have spaces

(\ CP-RF/tmp/A/root/A add one \ do not show whether to overwrite)

Slave --------------------------------------------------------------------------------------------------------------------------------

You can simply use RM, but you need to add two parameters-RF: Rm-RF directory name
-R is recursive down. No matter how many levels of directories are there, delete them together.
-F means to delete the file directly without any prompts.

Delete a folder instance:

rm -rf /var/log/httpd/access

The/var/log/httpd/Access Directory and all files and folders under it will be deleted.

Note that you must be extremely careful when using this RM-RF. Linux has no recycle bin.

Of course, RM has more parameters and usage, and man RM can be viewed.

Delete a file instance:rm -f /var/log/httpd/access.log

The file/var/log/httpd/access. log will be forcibly deleted.

 

 

Slave --------------------------------------------------------------------------------------------------------------------------------

 

Unzip the tar command in Linux Tar command

Tar [-cxtzjvfppn] file and directory ....
Parameters:
-C: Create a parameter command for the compressed file );
-X: Unlock the parameter command of a compressed file!
-T: view the files in the tarfile!
Note that C/X/T can only exist under the parameter! Cannot exist at the same time!
Because it is impossible to simultaneously compress and decompress.
-Z: does it have the gzip attribute at the same time? That is, do I need to use gzip for compression?
-J: Does it have Bzip2 attributes at the same time? That is, do I need to use Bzip2 for compression?
-V: The file is displayed during compression! This is common, but it is not recommended to use it in the background execution process!
-F: use the file name. Please note that the file name should be followed immediately after F! Do not add parameters!
For example, using "Tar-zcvfp tfile sfile" is an incorrect method.
"Tar-zcvpf tfile sfile" is correct!
-P: use the original attributes of the original file (the attributes will not be changed based on the user)
-P: absolute paths can be used for compression!
-N: a new date (yyyy/mm/DD) will be packed into the new file!
-- Exclude file: do not pack the file during compression!
Example:
Example 1: package all the files in the/etc directory into/tmp/etc.tar.
[Root @ Linux ~] #
Tar-CVF/tmp/etc.tar/etc <= package only, do not compress!
[Root @ Linux ~] #Tar-zcvf/tmp/etc.tar.gz/etc<= Compressed with gzip After packaging
[Root @ Linux ~] #Tar-jcvf/tmp/etc.tar.bz2/etc<= Compressed with Bzip2 After packaging
# Note that the file name after parameter F is obtained by ourselves. We use. tar for identification.
# If the Z parameter is added, .tar.gz or. tgz is used to represent the tar file ~ compressed by gzip ~
# If you add the J parameter, use .tar.bz2 as the file name ~
# A warning message is displayed when the preceding command is executed:
# "Tar: removing leading '/" from Member names "is a special setting for absolute paths.

Example 2: Check the files in the above/tmp/etc.tar.gz file?
[Root @ Linux ~] #Tar-ztvf/tmp/etc.tar.gz
# When we use gzip to compress the files in the TAR file,
# Add the Z parameter! This is important!

Example 3: Decompress the/tmp/etc.tar.gz file under/usr/local/src.
[Root @ Linux ~] #CD/usr/local/src
[Root @ Linux SRC] #Tar-zxvf/tmp/etc.tar.gz
# By default, We Can uncompress files anywhere! In this example,
# First, I will transform the working directory to the/usr/local/src directory, and unlock/tmp/etc.tar.gz,
# The unlocked directory will be in/usr/local/src/etc! In addition, if you enter/usr/local/src/etc
# The file attributes in this directory may be different from those in/etc!

Example 4: Under/tmp, I only want to unbind the etc/passwd in/tmp/etc.tar.gz.
[Root @ Linux ~] #CD/tmp
[Root @ Linux TMP] #Tar-zxvf/tmp/etc.tar.gz etc/passwd
# I can use tar-ztvf to check the file name in the tarfile. If you only need one file,
# You can issue it in this way! Notice! The root directory in etc.tar.gz/is removed!

Example 5: Back up all the files in/etc/and save their permissions!
[Root @ Linux ~] #Tar-zxvpf/tmp/etc.tar.gz/etc
# This-P attribute is very important, especially when you want to keep the attributes of the original file!

Example 6: only new files in/home are backed up.
[Root @ Linux ~] #Tar-n "2005/06/01"-zcvf home.tar.gz/home

Example 7: I want to back up/home,/etc, but not/home/dmtsai
[Root @ Linux ~] #Tar -- exclude/home/dmtsai-zcvf myfile.tar.gz/home/*/etc

Example 8: package/etc/and unpack it under/tmp without generating a file!
[Root @ Linux ~] #CD/tmp
[Root @ Linux TMP] #Tar-CVF-/etc | tar-xvf-
# This action is a bit like CP-r/etc/tmp ~ It is still useful!
# Note that the output file is changed to-and the input file is changed to-, and there is another file | Yes ~
# This represents standard output, standard input, and pipeline commands respectively!
# This part will be explained again when we mention this command in bash shell!


 

 


Slave --------------------------------------------------------------------------------------------------------------------------------

 

 

 

 

 

Related Article

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.