Ten good habits to use are:
1. Create a directory tree in a single command.2. Change the path. Do not move the archive.3. Combine commands with control operators.4. Exercise caution when referencing variables.5. Use escape sequences to manage long input.6. Group commands in the list.7. Use xargs outside of find.8. Know When grep should execute count -- When should bypass.9. match some fields in the output, not just the rows.10. Stop using pipelines fo
Source: Wu Qin (Tyler)Link: cnblogs.com/skynet/archive/2010/12/25/1916873.html
Working under Linux, some commands can greatly improve efficiency. This article to introduce you to find, grep command, his brother can be regarded as a mandatory Linux command, I almost every day to use them. The structure of this article is as follows: Find command
General form of Find commandCommon options and examples for Find commandsFind and Xargs grep command
General
Xargs is a filter that passes parameters to the command, and is also a tool for combining multiple commands. It divides a data stream into small enough chunks to facilitate the processing of filters and commands. Typically, Xargs reads data from a pipe or stdin, but it can also read data from the output of a file. The default command for Xargs is echo, which mean
three digits, so the suffix of the corresponding file must not exceed 999. Create several admin accounts first. to use the following command $ find. -Name "Admin. log [0-9] [0-9] [0-9] "-atime-7-OK RM {}\;
? N
? N
? N
? N
7. To find and sort all the directories in the current file system,
$ find. -type D | sort
8. To find all the RMT tape devices in the system,
$ find/dev/RMT-print
3
In Linux, some commands can greatly improve the efficiency. This article will introduce the find and grep commands. The two of them can be a must-have linux Command and I will use them almost every day.
Shell programming in Linux-awk Programming
Shell programming in Linux -- basic usage of sed command
Shell programming in Linux -- basic use of the grep command
Shell programming in Linux-basics and extensions of Regular Expressions
The structure of this article is as follows:
Find command
command can be used in the-EXEC option. In the example above we use the grep command. The find command first matches all files named "passwd*", such as passwd, Passwd.old, Passwd.bak, and then executes the grep command to see if there is a root user in these files.Example 5: Find files to move to the specified directoryCommand: Find.-name "*.log"-exec mv {}.. \;Example 6: Executing the CP command with the EXEC optionCommand: Find. -name "*.log"-exec cp {} test3 \;Output:[[email protected] test]
all the directories in the current file system. You can use:
$ Find.-type d-print-local-mount | sort
Find all the rmt tape devices in the system. You can use:
$ Find/dev/rmt-print
Ii. xargs
Xargs-build and execute command lines from standard input
When you use the-exec option of the find command to process matched files, the find command passes all matching files to exec for execution. However, some syst
find command will delete the admin. log file that was accessed in the/logs directory seven days ago and contains a digital suffix. This command only checks three digits, so the suffix of the corresponding log file should not exceed 999.
$ Find/logs-name 'admin. log [0-9] [0-9] '[-0a-t9i] me + 7-exec rm {}\;
Search and sort all the directories in the current file system. you can use:
$ Find.-type d-print-local-mount | sort
Find all the rmt tape devices in the system. you can use:
$ Find/dev/rmt-
This article presents 10 UNIX command line habits that are worth using mdash; to help you overcome many common usage quirks and improve the working efficiency of the command line. These 10 good habits are listed below, and a more detailed description is given later. The ten good habits to use are: create a directory tree in a single command. Change the path. This article introduces 10 UNIX command line habits that are worth using-this helps you overcome many common usage quirks and improve the
overflow ". This is the use of the xargs command, especially used with the find command. The find command passes the matching file to the xargs command, while the xargs command only obtains part of the file, not all, at a time, unlike the-exec option. In this way, it can first process the first part of the obtained files, then the next batch, and continue like t
form of ' command ' {} \;, note the space between {} and \;Find./-size 0-exec rm {} \; Delete files with a file size of zero (you can also do this: Rm-i ' find./-size 0 ' or find./-size 0 | Xargs Rm-f )In order to list the matching files with the Ls-l command, you can place the Ls-l command in the-exec option of the Find command: Find. -type f-exec ls-l {} \;In the/logs directory, look for files that change time before 5th and delete them: Find/logs-
)-mmin/-amin/-cmin: (Number of minutes)"+ N" N days/minute ago"-N" N days/minute or less-empty finding a file size of 0 or an empty directory-mount file system that does not cross mount when looking up the file system-follow if the find command encounters a symbolic link file, the source file to which the link file points is traced-A and-O or! Non --ok reminds you if you want to execute the following command
(1)-nameFind/test below all files ending in. txt # find/test-name "*.txt" find/tes
Find command
General form of the Find command
Common options and examples for the Find command
Find and Xargs
grep command
General form of the grep command
grep regular Expression meta-character set (base set)
Common options and examples of GREP commands
1. Find commandThe Find command is a ubiquitous command and is one of the most useful commands in Linux. The Find command is used to
, so the suffix of the corresponding file should not exceed 999. Create several admin. log * files before you can use the following command:$ Find.-name "admin. log [0-9] [0-9] [0-9]"-atime-7-OKRm {};? N? N? N? N7. To find and sort all directories in the current file system;
$ Find.-type d | sort8. To find all the rmt tape devices in the system;
$ Find/dev/rmt-printIii. xargs
Xargs-build and execute command
suffix since the access time in the directory was 7 days.This command only checks three digits, so the suffix of the corresponding file should not exceed 999. Create several Admin. log * files before you can use the following command:
$ find . -name "admin.log[0-9][0-9][0-9]" -atime -7 -okrm { } /;
7. To find and sort all directories in the current file system;$ find . -type d | sort
8. To find all the RMT tape devices in the system;$ find /dev/rmt -print
Iii. xargsXargs-build and execute c
This article presents 10 UNIX Command Line habits worth using-a good habit of helping you overcome many common usage quirks and improve the efficiency of command line work in this process. These 10 good habits are listed below, and a more detailed description is given later.Use 10 good habitsTen good habits to use are:Create a directory tree in a single command.Change the path. Do not move the archive.Combines commands with control operators.Exercise caution when referencing variables.Use escape
] [path ...] [Expression]In fact [-h] [-l] [-p] [-D debugopts] [-olevel] These options are not commonly used (at least in my daily work, not used), the above the common form of the Find command can be simplified to:find [path ...] [Expression]the directory path that the Path:find command looks for. For example, use. To represent the current directory, and/to represent the system root directoryexpression:expression can be divided into--"-options [-print-exec-ok ...]"-options, specify common optio
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.