ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • How to search file in Linux
    linux 2023. 2. 21. 10:27

    The find command in Linux is used to search for files and directories in a specified location and execute commands on them. The basic syntax of the find command is as follows:

     
    find [path] [expression]
     

    Here, path specifies the starting directory for the search, and expression specifies the criteria for selecting files to operate on. The following are some common options and expressions used with the find command:

    OptionDescription

    -name Searches for files with the specified name.
    -type Searches for files of the specified type (f for regular files, d for directories, l for symbolic links, etc.).
    -size Searches for files of the specified size.
    -mtime Searches for files that were modified within the specified time frame.
    -exec Executes a command on the selected files.

    Here are some examples of how to use the find command:

    • Find all files in the current directory and its subdirectories with the extension .txt:
    find . -name "*.txt"
    • Find all directories in the current directory and its subdirectories:
    find . -type d
     
    • Find all files in the current directory and its subdirectories that are larger than 10MB:
    find . -type f -size +10M
     
    • Find all files in the current directory and its subdirectories that were modified within the last 24 hours:
    find . -type f -mtime -1
     
    • Delete all files in the current directory and its subdirectories with the extension .bak:
    find . -name "*.bak" -type f -delete

    Note: Always be cautious when using the find command with the -exec option, as it can potentially execute commands on a large number of files. Always double-check your command before executing it.

    'linux' 카테고리의 다른 글

    How to add and delete group in Linux  (0) 2023.02.21
    How to add and delete user in Linux  (0) 2023.02.21
    File permissions in Linux  (0) 2023.02.21
    Set default permissions for files and directories in Linux  (0) 2023.02.21
    What is inode  (0) 2023.02.20
Designed by Tistory.