Xargs and exec command execution efficiency, xargsexec execution efficiency
Xargs and exec are the filters passed by commands. They capture the results of the previous command and pass it to the next command. Simply put:
- Exec must be used in combination with {} \;, and {} indicates the Result \; end character of the previous query. This is a fixed statement.
- Xargs must be combined with |. When processing files in batches, the speed is faster because of buffering (multithreading.
For example, to count the files on the server whose sizes are 1 k, 10 k, and k, list them as follows:
- Compare the file size with KB
[root@linux ~]# time -p find / -size +100k | xargs ls -lart {} \;real 7.29user 1.31sys 6.89[root@nas2ds1 boot]# time -p find / -size +100k -exec ls -lart {} \;real 31.00user 6.06sys 20.88
- Compare the file size with 10
[root@linux ~]# time -p find / -size +10k | xargs ls -lart {} \;real 12.43user 3.96sys 8.99[root@linux ~]# time -p find / -size +10k -exec ls -lart {} \;real 105.14user 20.38sys 67.65
- Comparison of 1 kb File Size
[root@linux ~]# time -p find / -size +1k | xargs ls -lart {} \;real 28.62user 5.72sys 24.01[root@linux ~]# time -p find / -size +1k -exec ls -lart {} \;real 703.89user 129.08sys 456.97
Note:
- When there are few files, the execution efficiency of the two is several times different.
- When there are many files, the execution efficiency of the two is dozens of times different.
In linux commands, the find-mtime + 10 | xargs rm-rf command does not work because there are too many files.
Actually, I don't see any problems... okay, I'm a beginner.
If you want to try this find.-type f-mtime + 10-exec rm-rf {}\
In fact, I don't think it will work if you delete it that way, but try again.
Shell Command 1
Find and xargs Linux file search commands
Conclusion: zhy2111314
From: LinuxSir. Org
Sorting: north, south, and South
Abstract: This article is a detailed description of the find command. It is valuable to give a lot of examples for parameters, which makes it easier for beginners to understand. This article is posted by zhyfly on the forum; I have reviewed this article for your convenience;
Directory
Copyright Notice
About the find command
I. find Command Format
1. The common form of the find command is;
2. Parameters of the find command;
3. find command options;
4. execute shell commands using exec or OK;
2. Example of the find command;
1. Search for all files in the current user's home directory;
2. In order to have the read and write permissions on the file owner in the current directory, and the users in the file group and other users have the read permission on the file owner;
3. In order to find all common files with a length of 0 in the system and list their full paths;
4. Search for Common files that were modified seven days ago in the/var/logs directory and ask them before deletion;
5. To find all the files in the root group in the system;
6. The find command will delete the admin. log file that contains the numeric suffix since the access time in the directory was 7 days.
7. To find and sort all directories in the current file system;
8. To find all the rmt tape devices in the system;
Iii. xargs
4. Parameters of the find command;
1. Use the name Option
2. Use the perm Option
3. Ignore a directory
4. How to avoid a file directory when searching for files using find
5. Use the user and nouser options
6. Use the group and nogroup options
7. Search for files based on the change time or access time
8. Search for new or old files than a file
9. Use the type option
10. Use the size Option
11. Use the depth Option
12. Use the mount Option
V. About this article
Vi. Related Documents
++ ++
Body
++ ++
Copyright Notice
This article is based on a post posted by zhyfly on LinuxSir. Org. If you have any questions about copyright, follow this post. Thank you. The HTML version of this article is organized by the North, South, and South. The full angle of the entire document and the question of each letter and space in the words are modified. The title is numbered for your convenience;
About the find command
Because find has powerful functions, there are many options, and most of them are worth the time to understand. Even if the system contains a Network File System (NFS), the find command is equally valid in the file system, and you only have the corresponding permissions.
When running a find command that consumes a lot of resources, many people tend to put it in the background for execution, because it may take a long time to traverse a large file system (this is a file system with more than 30 GB bytes ).
I. find Command Format
1. The common form of the find command is;
Find pathname-options [-print-exec-OK...]
2. Parameters of the find command;
Pathname: directory path searched by the find command. For example, use "." To represent the current directory, and use "/" to represent the root directory of the system.
-Print: The find command outputs matching files to the standard output.
-Exec: find... the remaining full text>