亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Home Operation and Maintenance Linux Operation and Maintenance How to use the Find command to find files in Linux

How to use the Find command to find files in Linux

Mar 15, 2019 pm 04:25 PM
find linux Find files

Linux Find command is one of the most powerful tools in the Linux system administrator tool library. It allows us to search for files and directories in the directory hierarchy based on an expression given by the user, applying the user to each matching file. specified operation. The following article will show you how to use the Find command. I hope it will be helpful to you.

How to use the Find command to find files in Linux

Linux Find command

Use the find command to determine the file permissions, type, date, ownership, size Wait to search for files. It can also be used in conjunction with other tools, such as grep or sed to perform operations on these files

Before discussing how to use the find command, let's first understand the basic syntax:

find [options] [path...] [expression]

Description:

● Options attribute: Controls the processing of symbolic links, debugging options and optimization methods.

● Path... attribute: Defines the starting directory where find will search for files.

● Expression attribute: consists of "options", "search mode" and "operations separated by operators".

Let’s take a look at the following example:

find  -L /home/projects/ -name "*.js" -exec chmod 644 {} \;

Description: This command contains a parameter -L (options), which allows the find command to follow symbolic links and search /home/projects/ (path ...), find all files ending with .js(expression) and set the permissions of all matching files to 644.

How to find files by type?

To specify the file type to be found, you need to use the -type parameter.

You can use the following descriptors to specify file types:

● f: Regular file

● d: Directory

● l: Symbolic link

●●c: Role device

●b: Block device

●p: Named pipe (FIFO)

● s: Socket

Example:

If you want to find all directories in the current working directory, you can use:

find . -type d

If you want to list all character devices on the system type:

find / -type c

How to find files by name?

Finding files by name is probably the most common use of the find command. To find files by name, pass the -name option along with the name of the file you want to search for.

Example:

To search for a file named document.pdf in the /home/linuxize directory, you can use the following command:

sudo find /home/linuxize -type f -name document.pdf

If To run a case-insensitive search, you can change the -name option using the -iname command:

sudo find /home/linuxize -type f -iname document.pdf

Description: The above command will match Document.pdf, DOCUMENT.pdf..etc.

How to find files by extension?

Searching for files by extension is the same as searching for files by name.

For example:

If you want to find all files ending with .log.gzinside /var/log/nginx directory, you can use:

find /var/log/nginx -type f -name '*.log.gz'

If you want to find all files that do not match the regular expression *.log.gz you can use the -not parameter. For example, to find all files that do not end with *.log.gz, use:

find /var/log/nginx -type f -not -name '*.log.gz'

How to find files by size?

To find files based on their size, you need to pass the -size parameter along with the size condition. File sizes can be specified using the following suffixes:

● b: 512-byte blocks (default)

● c: Bytes

● w: Double-byte words

● k:Kilobytes

● M:Megabytes

● G:Gigabytes

For example:

To be in / To find all files in the tmp directory that are exactly 1024 bytes, you can run the following command:

find /tmp -type f -size 1024c

The find command also allows us to search for files larger or smaller than the specified size. For example:

We can search all files smaller than 1MB in the current working directory, this requires adding a minus sign before the size value:

find . -type f -size -1M

If you want to search files larger than 1MB, you need Use the plus sign:

find . -type f -size +1M

to search even files within a size range. For example, the following command will find all files between 1 and 2 MB:

find . -type f -size +1M -size 21M

How to find files by modification date?

The find command can also search for files based on when they were last modified, accessed, or changed.

Same as when searching by size, you can use the plus and minus signs to specify greater or less than.

For example:

You modified a dovecot configuration file a few days ago, but you forgot the file name. We can easily filter all files in the /etc/dovecot/conf.d/ directory ending in .conf that have been modified in the past 5 days:

find /etc/dovecot/conf.d -name "*.conf" -mtime 5

We can also list 30 days Or all files in the /home directory that were modified more recently:

find /home -mtime +30 -daystart

How to find files by permissions?

To filter files based on file permissions, you need to use the -perm option.

For example:

要在/var/www/html目錄中查找權(quán)限為775的所有文件:

find /var/www/html -perm 644

還可以使用減號(hào)-或斜杠/為數(shù)字模式添加前綴。

當(dāng)斜杠/用作前綴時(shí),至少一個(gè)類別(用戶,組或其他類別)必須至少為文件匹配設(shè)置相應(yīng)的位。

find . -perm /444

說明:搜索對(duì)用戶,組或其他人設(shè)置了讀權(quán)限的所有文件。

如果使用減號(hào)-作為前綴,則必須至少設(shè)置要匹配的文件。

find . -perm -664

說明:搜索對(duì)所有者和組具有讀寫權(quán)限的文件,并且其他用戶可以讀取。

如何按所有者查找文件?

要查找特定用戶或組擁有的文件,可以使用-user和-group選項(xiàng)。

例如,要搜索用戶擁有的所有文件和目錄linuxize,可以運(yùn)行:

find / -user linuxize

這是更高級(jí)的示例,假設(shè)是希望查找用戶www-data擁有的所有文件,并將匹配文件的所有權(quán)從www-data更改為nginx:

find / -user www-data -type f  -exec chown nginx {} \;

相關(guān)視頻教程推薦:《linux教程

以上就是本篇文章的全部?jī)?nèi)容,希望能對(duì)大家的學(xué)習(xí)有所幫助。更多精彩內(nèi)容大家可以關(guān)注php中文網(wǎng)相關(guān)教程欄目!?。?/p>

The above is the detailed content of How to use the Find command to find files in Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1488
72
How does resource usage (CPU, memory) differ between Linux and Windows? How does resource usage (CPU, memory) differ between Linux and Windows? Jun 05, 2025 am 12:13 AM

Linux and Windows have their own advantages and disadvantages in CPU and memory usage: 1) Linux uses time slice-based scheduling algorithms to ensure fairness and efficiency; Windows uses priority scheduling, which may cause low-priority processes to wait. 2) Linux manages memory through paging and switching mechanisms to reduce fragmentation; Windows tends to pre-allocate and dynamic adjustment, and efficiency may fluctuate.

How does the cost of ownership differ between Linux and Windows? How does the cost of ownership differ between Linux and Windows? Jun 09, 2025 am 12:17 AM

Linux's cost of ownership is usually lower than Windows. 1) Linux does not require license fees, saving a lot of costs, while Windows requires purchasing a license. 2) Linux has low hardware requirements and can extend the service life of the device. 3) The Linux community provides free support to reduce maintenance costs. 4) Linux is highly secure and reduces productivity losses. 5) The Linux learning curve is steep, but Windows is easier to use. The choice should be based on specific needs and budget.

How does the performance of I/O operations differ between Linux and Windows? How does the performance of I/O operations differ between Linux and Windows? Jun 07, 2025 am 12:06 AM

LinuxoftenoutperformsWindowsinI/Operformanceduetoitscustomizablekernelandfilesystems,whileWindowsoffersmoreuniformperformanceacrosshardware.1)LinuxexcelswithcustomizableI/OschedulerslikeCFQandDeadline,enhancingperformanceinhigh-throughputapplications

How to install Linux alongside Windows (dual boot)? How to install Linux alongside Windows (dual boot)? Jun 18, 2025 am 12:19 AM

The key to installing dual systems in Linux and Windows is partitioning and boot settings. 1. Preparation includes backing up data and compressing existing partitions to make space; 2. Use Ventoy or Rufus to make Linux boot USB disk, recommend Ubuntu; 3. Select "Coexist with other systems" or manually partition during installation (/at least 20GB, /home remaining space, swap optional); 4. Check the installation of third-party drivers to avoid hardware problems; 5. If you do not enter the Grub boot menu after installation, you can use boot-repair to repair the boot or adjust the BIOS startup sequence. As long as the steps are clear and the operation is done properly, the whole process is not complicated.

How to enable the EPEL (Extra Packages for Enterprise Linux) repository? How to enable the EPEL (Extra Packages for Enterprise Linux) repository? Jun 17, 2025 am 09:15 AM

The key to enabling EPEL repository is to select the correct installation method according to the system version. First, confirm the system type and version, and use the command cat/etc/os-release to obtain information; second, enable EPEL through dnfinstallepel-release on CentOS/RockyLinux, and the 8 and 9 version commands are the same; third, you need to manually download the corresponding version of the .repo file and install it on RHEL; fourth, you can re-import the GPG key when encountering problems. Note that the old version may not be supported, and you can also consider enabling epel-next to obtain the test package. After completing the above steps, use dnfrepolist to verify that the EPEL repository is successfully added.

How does Linux perform compared to Windows for web server workloads? How does Linux perform compared to Windows for web server workloads? Jun 08, 2025 am 12:18 AM

Linux usually performs better in web server performance, mainly due to its advantages in kernel optimization, resource management and open source ecosystem. 1) After years of optimization of the Linux kernel, mechanisms such as epoll and kqueue make it more efficient in handling high concurrent requests. 2) Linux provides fine-grained resource management tools such as cgroups. 3) The open source community continuously optimizes Linux performance, and many high-performance web servers such as Nginx are developed on Linux. By contrast, Windows performs well when handling ASP.NET applications and provides better development tools and commercial support.

How to choose a Linux distro for a beginner? How to choose a Linux distro for a beginner? Jun 19, 2025 am 12:09 AM

Newbie users should first clarify their usage requirements when choosing a Linux distribution. 1. Choose Ubuntu or LinuxMint for daily use; programming and development are suitable for Manjaro or Fedora; use Lubuntu and other lightweight systems for old devices; recommend CentOSStream or Debian to learn the underlying principles. 2. Stability is preferred for UbuntuLTS or Debian; you can choose Arch or Manjaro to pursue new features. 3. In terms of community support, Ubuntu and LinuxMint are rich in resources, and Arch documents are technically oriented. 4. In terms of installation difficulty, Ubuntu and LinuxMint are relatively simple, and Arch is suitable for those with basic needs. It is recommended to try it first and then decide.

How to add a new disk to Linux How to add a new disk to Linux Jun 27, 2025 am 12:15 AM

The steps to add a new hard disk to the Linux system are as follows: 1. Confirm that the hard disk is recognized and use lsblk or fdisk-l to check; 2. Use fdisk or parted partitions, such as fdisk/dev/sdb and create and save; 3. Format the partition to a file system, such as mkfs.ext4/dev/sdb1; 4. Use the mount command for temporary mounts, such as mount/dev/sdb1/mnt/data; 5. Modify /etc/fstab to achieve automatic mount on the computer, and test the mount first to ensure correctness. Be sure to confirm data security before operation to avoid hardware connection problems.

See all articles