


Introduction to the difference between find and grep and common commands under Linux
find
Function: Search for files in the directory structure and perform the specified operation. This command provides quite a lot of search conditions and is very powerful.
Syntax: find search location matching file name
Description: The find command starts from the specified starting directory, recursively searches its subdirectories, finds files that meet the search conditions and takes relevant operations.
grep
The full name of grep is Global Regular Expression Print.
A powerful text search tool that can use regular expressions to search text and print out matching lines.
Syntax: grep matches StringFile name
When using Linux, you often need to search for files. The main search commands include find and grep. There is a difference between the two commands.
Difference:
(1) The find command searches based on the attributes of the file, such as the file Name, file size, owner, group to which it belongs, whether it is empty, access time, modification time, etc.
(2) GREP is searched according to the content of the file. Each line of the file will be matched according to the given mode (Patter).
1.find command
Basic format: find path expression
1. Search by file name
(1)find / -name httpd.conf #Find the file httpd.conf in the root directory, which means searching the entire hard disk
iety through`` -name httpd.conf conf #The file httpd.conf
in the /etc directory (3)find /etc -name '*srm*' #Use the wildcard character * (0 or any number). Indicates that the file name contains string 'srm' in the /etc directory The file that is the string 'srm' Files (access time)
(2)find/-atime -2 #Find the files accessed in the last 48 hours in the system
(3)find/-empty #Find the files accessed in the system in the last 48 hours Empty files or folders (4)find / -group cat Files modified in the last 5 minutes in the system (modify time)
(6)find / -mtime -1 #Find files modified in the last 24 hours in the system
(7 )find / -user fred #Find files belonging to the user fred in the system
(8)find / -size +10000c #Find files larger than 10000000 bytes (c: byte, w: double Words, k:KB, M:MB, G:GB)
(9)find / -size -1000k #Find files less than 1000KB
3. Use mixed search method to find files
The parameters are: ! ,-and(-a),-or(-o).
(1)find /tmp -size +10000c -and -mtime +2 #Find files in the /tmp directory that are larger than 10000 bytes and modified within the last 2 minutes
(2 )find / -user fred -or -user george #Find files in the / directory where the user is fred or george (3)find /tmp ! -user panda #Find all files that are not in the /tmp directory Files belonging to the panda user
2. grep command Basic format: find expression
[options]Main parameters: -c: Only output the count of matching lines. PatternRegular expression Main parameters: \: Ignore the original meaning of the special characters in the regular expression. 2. Example (1)grep 'test' d* #Display all lines containing test in files starting with d ( 2) grep 'test' aa bb cc #Display the lines containing test in the aa, bb, cc files (3) grep '[a-z]\{5\}' aa #Display all lines containing each line Lines whose strings have at least 5 consecutive lowercase characters (4)grep magic /usr/src #Display the lines containing magic in the files in the /usr/src directory (excluding subdirectories) (5)grep -r magic /usr/src #Display the lines containing magic in the files in the /usr/src directory (including subdirectories) (6)grep -w pattern files: Only match the entire word, not part of the string (such as matching 'magic', not 'magical'),
-i: Case-insensitive
-h: File names are not displayed when querying multiple files.
-l: When querying multiple files, only the file names containing matching characters will be output.
-n: Display matching lines and line numbers.
-s: Do not display error messages that do not exist or have no matching text.
-v: Display all lines that do not contain matching text.
^: Matches the starting line of the regular expression.
$: Matches the end line of the regular expression.
\<: start from the line matching regular expression.> \>: To the end of the line matching the regular expression.
[ ]: A single character, such as [A] means A meets the requirements.
[-]: Range, such as [A-Z], that is, A, B, C to Z all meet the requirements.
.: All single characters.
*: There are characters, and the length can be 0.
The above is the detailed content of Introduction to the difference between find and grep and common commands under Linux. For more information, please follow other related articles on the PHP Chinese website!

Maintenance mode is a special operating level entered in Linux systems through single-user mode or rescue mode, and is used for system maintenance and repair. 1. Enter maintenance mode and use the command "sudosystemctlisolaterscue.target". 2. In maintenance mode, you can check and repair the file system and use the command "fsck/dev/sda1". 3. Advanced usage includes resetting the root user password, mounting the file system in read and write mode and editing the password file.

Maintenance mode is used for system maintenance and repair, allowing administrators to work in a simplified environment. 1. System Repair: Repair corrupt file system and boot loader. 2. Password reset: reset the root user password. 3. Package management: Install, update or delete software packages. By modifying the GRUB configuration or entering maintenance mode with specific keys, you can safely exit after performing maintenance tasks.

Linux network configuration can be completed through the following steps: 1. Configure the network interface, use the ip command to temporarily set or edit the configuration file persistence settings. 2. Set up a static IP, suitable for devices that require a fixed IP. 3. Manage the firewall and use the iptables or firewalld tools to control network traffic.

Maintenance mode plays a key role in Linux system management, helping to repair, upgrade and configuration changes. 1. Enter maintenance mode. You can select it through the GRUB menu or use the command "sudosystemctlisolaterscue.target". 2. In maintenance mode, you can perform file system repair and system update operations. 3. Advanced usage includes tasks such as resetting the root password. 4. Common errors such as not being able to enter maintenance mode or mount the file system, can be fixed by checking the GRUB configuration and using the fsck command.

The timing and reasons for using Linux maintenance mode: 1) When the system starts up, 2) When performing major system updates or upgrades, 3) When performing file system maintenance. Maintenance mode provides a safe and controlled environment, ensuring operational safety and efficiency, reducing impact on users, and enhancing system security.

Indispensable commands in Linux include: 1.ls: list directory contents; 2.cd: change working directory; 3.mkdir: create a new directory; 4.rm: delete file or directory; 5.cp: copy file or directory; 6.mv: move or rename file or directory. These commands help users manage files and systems efficiently by interacting with the kernel.

In Linux, file and directory management uses ls, cd, mkdir, rm, cp, mv commands, and permission management uses chmod, chown, and chgrp commands. 1. File and directory management commands such as ls-l list detailed information, mkdir-p recursively create directories. 2. Permission management commands such as chmod755file set file permissions, chownuserfile changes file owner, and chgrpgroupfile changes file group. These commands are based on file system structure and user and group systems, and operate and control through system calls and metadata.

MaintenanceModeinLinuxisaspecialbootenvironmentforcriticalsystemmaintenancetasks.Itallowsadministratorstoperformtaskslikeresettingpasswords,repairingfilesystems,andrecoveringfrombootfailuresinaminimalenvironment.ToenterMaintenanceMode,interrupttheboo


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Zend Studio 13.0.1
Powerful PHP integrated development environment

Atom editor mac version download
The most popular open source editor

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
