Linux finds multiple similar but different names of files and renames

Source: Internet
Author: User

This topic is said to be Baidu side of the face of the question, Linux problem: Find to core.1,core.2 .... Format the file name, and then change the file names to Bak. CORE.1,BAK.CORE.2, ...

    1. You should first find these files and use Find. -name "core. [0-9] "-print, can be found;
How to use Find:

1. Command format:

Find Pathname-options [-print-exec-ok ...]

2. Command function:

Used to locate files in the file tree and to make corresponding processing

3. Command parameters:

The directory path that the Pathname:find command looks for. For example, use. To represent the current directory, and/to represent the system root directory.

The-print:find command outputs the matched file to standard output.

The-exec:find command executes the shell command given by the parameter to the matching file. The corresponding command is in the form of ' command ' {} \;, note the space between {} and \;

-ok: The same as-exec, except that the shell command given by the parameter is executed in a more secure mode, prompting the user to determine whether to execute before executing each command.

4. Command options:

-name finds files by file name.

-perm to find files according to file permissions.

-prune Use this option to have the Find command not be found in the currently specified directory, and if you use the-depth option at the same time,-prune will be ignored by the Find command.

-user Search for files according to the owner of the file.

-group finds files according to the group to which the files belong.

-mtime-n +n The file changes time to find the file,-n means that the file change time is now less than n days, + n means that the file change time is now N days ago. The Find command also has the-atime and-ctime options, but they both and the-m time option.

-nogroup finds a file that does not have a valid owning group, that is, the group to which the file belongs does not exist in/etc/groups.

-nouser finds a file without a valid owner, that is, the owner of the file does not exist in the/etc/passwd.

-newer file1! File2 look for a file that changes time than the file File1 new but older than the file file2.

-type find a file of a certain type, such as:

B-block device files.

D-Directory.

C-character device file.

P-Pipeline file.

L-Symbolic link file.

F-Normal file.

-size N:[c] finds files with a file length of n blocks, with C indicating the length of the file in bytes. -depth: When looking for a file, first find the file in the current directory, and then look in its subdirectories.

-fstype: Find files located in a file system of a certain type, these file system types can usually be found in the configuration file/etc/fstab, which contains information about the file system in this system.

-mount: Does not cross the file system mount point when locating files.

For more information, refer to: http://www.jb51.net/os/RedHat/1307.html2. The files found by find have path names,How to search for a file with the Find statement, displaying only its filename, not the path namefind.-name "core. [0-9] "-exec basename {} \;

Must be added after \;, or it will go wrong.  BaseName refers to the file name, {} refers to all the files found by the previous find; 3. At the end of the line, you'll rename it; Xargs-i mv {} bak. {}

Xargs Use ConstructionParameter list andRun command . GrammarXargs [-P] [-t] [-e[eofstring] [-eeofstring] [-i[replacestring]] [-ireplacestring] [-l [number]] [-l NUMBER] [-N number [-X]] [-s Size] [Command [Argument]] Note: Do not place spaces between lowercase flags and parameters. DescriptionThe resulting command line length is the sum of the size (in bytes) of the Argument (including the empty byte terminator of each string) that is treated as a string. The Xargs command limits the length of the command line. When the command line is constructed, the combined Argument and environment list cannot exceed Arg_max bytes. Under this constraint, if the-N or-s flag is not specified, the default command line length is at least the value specified by Line_max.

Option explanation

-0 when a sdtin contains special characters, it is treated as a general character, like /' space ' , etc.

For example:[email Protected]:~/test#echo "//" |xargs Echo

[Email Protected]:~/test#echo "//" |xargs-0 Echo

/

-a file  read from file as sdtin ,

-e flag   note that sometimes it may be -e , flag must be a space-delimited flag when xargs The is stopped when it analyzes this flag that contains flag .

- P Ask the user once every time a argument is executed.

- N Num The number of argument that is used at the time of the execution of the command, by default, is used for all.

-t  indicates that the command is printed before execution.

-i  or -i , which depends on linux supported, will xargs for each item name, typically one line is assigned to {} , you can use {} instead.

- R no-run-if-empty Stop xargswhen the input of Xargs is empty, no more execution.

- s Num The best number of characters for the command line, which is the maximum number of command-line characters for that command after Xargs .

- L num use for most max-lines nonblank input lines per command line.-s contains spaces.

- L Same- l

- D Delim delimiter, the default xargs delimiter is carriage return, the delimiter ofargument is a space, here the Xargs delimiter is modified

-x exit -s use.

- P Modify the maximum number of processes, the default is 1, for the 0 time as many as it can , this example I did not think, should normally not be used.

For more details please refer to the blog: http://blog.csdn.net/zhangfn2011/article/details/6776925 So, the final command should be: Find. -name "core. [0-9] "-exec basename {} \; | Xargs-i mv {} bak. {}


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.