search
HomeOperation and MaintenanceLinux Operation and MaintenanceWhat are the commands to find files in Linux?

What are the commands to find files in Linux?

May 08, 2021 pm 02:10 PM
linuxFind files

Linux commands to find files: 1. The find command can find any desired file; 2. The locate command cannot find the latest changed files; 3. The whereis command only searches binary files and man files. Description files and source code files; 4. which command; 5. type command.

What are the commands to find files in Linux?

#The operating environment of this tutorial: Red Hat Enterprise Linux 6.1 system, Dell G3 computer.

When using a computer, you often need to find files. In Linux, there are many ways to do this. Here are five commands summarized for you.

1. find

find is the most common and powerful search command. You can use it to find any file you want to find. .

The usage format of find is as follows:

$ find <指定目录> <指定条件> <指定动作>

 - : The directory to be searched and all its subdirectories. Defaults to the current directory.

 - : Characteristics of the files to be searched.

 -: Perform specific processing on the search results.

If no parameters are added, find will search the current directory and its subdirectories by default, and will not filter any results (that is, return all files) and display them all on the screen.

Usage examples of find:

  $ find . -name &#39;my*&#39;

Search for all files in the current directory (including subdirectories, the same below) whose file names begin with my.

  $ find . -name &#39;my*&#39; -ls

Search for all files in the current directory whose file names begin with my and display their detailed information.

  $ find . -type f -mmin -10

Search in the current directory for all ordinary files that have been updated in the past 10 minutes. If the -type f parameter is not added, ordinary files and special files directories are searched.

2. locate

The locate command is actually another way of writing "find -name", but it is much faster than the latter. , the reason is that it does not search a specific directory, but a database (/var/lib/locatedb), which contains all local file information. The Linux system automatically creates this database and automatically updates it once a day, so the latest changed files cannot be found using the locate command. To avoid this situation, you can use the updatedb command to manually update the database before using locate.

Usage examples of the locate command:

  $ locate /etc/sh

Search for all files starting with sh in the etc directory.

  $ locate ~/m

Search for all files starting with m in the user's home directory.

  $ locate -i ~/m

Search for all files starting with m in the user's home directory, ignoring case.

3. whereis

The whereis command can only be used to search for program names, and only searches for binary files (parameter -b), man Description files (parameter -m) and source code files (parameter -s). If parameters are omitted, all information is returned.

Usage examples of whereis command:

  $ whereis grep

4. which

which command is used to In the path specified by the PATH variable, search for the location of a system command and return the first search result. In other words, using the which command, you can see whether a certain system command exists and where the command is executed. Examples of using the

which command:

  $ which grep

5. The type

type command is not actually a search command, it is Used to distinguish whether a command comes with the shell or is provided by an independent binary file outside the shell. If a command is an external command, then using the -p parameter will display the path of the command, which is equivalent to the which command.

Usage examples of type command:

  $ type cd

The system will prompt that cd is the shell’s built-in command (build-in).

  $ type grep

The system will prompt that grep is an external command and display the path of the command.

  $ type -p grep

After adding the -p parameter, it is equivalent to the which command.

Related recommendations: "Linux Video Tutorial"

The above is the detailed content of What are the commands to find files in Linux?. For more information, please follow other related articles on the PHP Chinese website!

Statement
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
Linux Maintenance Mode: Understanding the PurposeLinux Maintenance Mode: Understanding the PurposeApr 28, 2025 am 12:01 AM

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 Operations: Networking and Network ConfigurationLinux Operations: Networking and Network ConfigurationApr 27, 2025 am 12:09 AM

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 in Linux: A System Administrator's GuideMaintenance Mode in Linux: A System Administrator's GuideApr 26, 2025 am 12:20 AM

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.

Maintenance Mode in Linux: When and Why to Use ItMaintenance Mode in Linux: When and Why to Use ItApr 25, 2025 am 12:15 AM

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.

Linux: Essential Commands and OperationsLinux: Essential Commands and OperationsApr 24, 2025 am 12:20 AM

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.

Linux Operations: Managing Files, Directories, and PermissionsLinux Operations: Managing Files, Directories, and PermissionsApr 23, 2025 am 12:19 AM

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.

What is Maintenance Mode in Linux? ExplainedWhat is Maintenance Mode in Linux? ExplainedApr 22, 2025 am 12:06 AM

MaintenanceModeinLinuxisaspecialbootenvironmentforcriticalsystemmaintenancetasks.Itallowsadministratorstoperformtaskslikeresettingpasswords,repairingfilesystems,andrecoveringfrombootfailuresinaminimalenvironment.ToenterMaintenanceMode,interrupttheboo

Linux: A Deep Dive into Its Fundamental PartsLinux: A Deep Dive into Its Fundamental PartsApr 21, 2025 am 12:03 AM

The core components of Linux include kernel, file system, shell, user and kernel space, device drivers, and performance optimization and best practices. 1) The kernel is the core of the system, managing hardware, memory and processes. 2) The file system organizes data and supports multiple types such as ext4, Btrfs and XFS. 3) Shell is the command center for users to interact with the system and supports scripting. 4) Separate user space from kernel space to ensure system stability. 5) The device driver connects the hardware to the operating system. 6) Performance optimization includes tuning system configuration and following best practices.

See all articles

Hot AI Tools

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.

Undress AI Tool

Undress AI Tool

Undress images for free

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

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.