Find all commands linux

Содержание
  1. How to Find Files in Linux Using the Command Line
  2. Find a File in Linux by Name or Extension
  3. Using Common find Commands and Syntax to Find a File in Linux
  4. Basic Examples
  5. Options and Optimization for find
  6. Find a File in Linux by Modification Time
  7. Use grep to Find a File in Linux Based on Content
  8. How to Find and Process a File in Linux
  9. How to Find and Delete a File in Linux
  10. More Information
  11. 35 Practical Examples of Linux Find Command
  12. 1. Find Files Using Name in Current Directory
  13. 2. Find Files Under Home Directory
  14. 3. Find Files Using Name and Ignoring Case
  15. 4. Find Directories Using Name
  16. 5. Find PHP Files Using Name
  17. 6. Find all PHP Files in the Directory
  18. 7. Find Files With 777 Permissions
  19. 8. Find Files Without 777 Permissions
  20. 9. Find SGID Files with 644 Permissions
  21. 10. Find Sticky Bit Files with 551 Permissions
  22. 11. Find SUID Files
  23. 12. Find SGID Files
  24. 13. Find Read-Only Files
  25. 14. Find Executable Files
  26. 15. Find Files with 777 Permissions and Chmod to 644
  27. 16. Find Directories with 777 Permissions and Chmod to 755
  28. 17. Find and remove single File
  29. 18. Find and remove Multiple File
  30. 19. Find all Empty Files
  31. 20. Find all Empty Directories
  32. 21. File all Hidden Files
  33. 22. Find Single File Based on User
  34. 23. Find all Files Based on User
  35. 24. Find all Files Based on Group
  36. 25. Find Particular Files of User
  37. 26. Find Last 50 Days Modified Files
  38. 27. Find Last 50 Days Accessed Files
  39. 28. Find Last 50-100 Days Modified Files
  40. 29. Find Changed Files in Last 1 Hour
  41. 30. Find Modified Files in Last 1 Hour
  42. 31. Find Accessed Files in Last 1 Hour
  43. 32. Find 50MB Files
  44. 33. Find Size between 50MB – 100MB
  45. 34. Find and Delete 100MB Files
  46. 35. Find Specific Files and Delete
  47. If You Appreciate What We Do Here On TecMint, You Should Consider:
  48. find command in Linux with examples

How to Find Files in Linux Using the Command Line

When you have to find a file in Linux, it’s sometimes not as easy as finding a file in another operating system. This is especially true if you are running Linux without a graphical user interface and need to rely on the command line. This article covers the basics of how to find a file in Linux using the CLI. The find command in Linux is used to find a file (or files) by recursively filtering objects in the file system based on a simple conditional mechanism. You can use the find command to search for a file or directory on your file system. By using the -exec flag ( find -exec ), files can be found and immediately processed within the same command.

Find a File in Linux by Name or Extension

Use find from the command line to locate a specific file by name or extension. The following example searches for *.err files in the /home/username/ directory and all sub-directories:

Using Common find Commands and Syntax to Find a File in Linux

find expressions take the following form:

  • The options attribute will control the find process’s behavior and optimization method.
  • The starting/path attribute will define the top-level directory where find begins filtering.
  • The expression attribute controls the tests that search the directory hierarchy to produce output.

Consider the following example command:

This command enables the maximum optimization level (-O3) and allows find to follow symbolic links ( -L ). find searches the entire directory tree beneath /var/www/ for files that end with .html .

Basic Examples

Command Description
find . -name testfile.txt Find a file called testfile.txt in current and sub-directories.
find /home -name *.jpg Find all .jpg files in the /home and sub-directories.
find . -type f -empty Find an empty file within the current directory.
find /home -user exampleuser -mtime -7 -iname «.db» Find all .db files (ignoring text case) modified in the last 7 days by a user named exampleuser.

Options and Optimization for find

The default configuration for find will ignore symbolic links (shortcut files). If you want find to follow and return symbolic links, you can add the -L option to the command, as shown in the example above.

find optimizes its filtering strategy to increase performance. Three user-selectable optimization levels are specified as -O1 , -O2 , and -O3 . The -O1 optimization is the default and forces find to filter based on filename before running all other tests.

Optimization at the -O2 level prioritizes file name filters, as in -O1 , and then runs all file-type filtering before proceeding with other more resource-intensive conditions. Level -O3 optimization allows find to perform the most severe optimization and reorders all tests based on their relative expense and the likelihood of their success.

Command Description
-O1 (Default) filter based on file name first.
-O2 File name first, then file type.
-O3 Allow find to automatically re-order the search based on efficient use of resources and likelihood of success.
-maxdepth X Search current directory as well as all sub-directories X levels deep.
-iname Search without regard for text case.
-not Return only results that do not match the test case.
-type f Search for files.
-type d Search for directories.

Find a File in Linux by Modification Time

The find command contains the ability to filter a directory hierarchy based on when the file was last modified:

The first command returns a list of all files in the entire file system that end with the characters conf and modified in the last seven days. The second command filters exampleuser user’s home directory for files with names that end with the characters conf and modified in the previous three days.

Use grep to Find a File in Linux Based on Content

The find command can only filter the directory hierarchy based on a file’s name and metadata. If you need to search based on the file’s content, use a tool like grep . Consider the following example:

This searches every object in the current directory hierarchy ( . ) that is a file ( -type f ) and then runs the command grep «example» for every file that satisfies the conditions. The files that match are printed on the screen ( -print ). The curly braces ( <> ) are a placeholder for the find match results. The <> are enclosed in single quotes ( ‘ ) to avoid handing grep a malformed file name. The -exec command is terminated with a semicolon ( ; ), which should be escaped ( \; ) to avoid interpretation by the shell.

How to Find and Process a File in Linux

The -exec option runs commands against every object that matches the find expression. Consider the following example:

This filters every object in the current hierarchy ( . ) for files named rc.conf and runs the chmod o+r command to modify the find results’ file permissions.

The commands run with the -exec are executed in the find process’s root directory. Use -execdir to perform the specified command in the directory where the match resides. This may alleviate security concerns and produce a more desirable performance for some operations.

The -exec or -execdir options run without further prompts. If you prefer to be prompted before action is taken, replace -exec with -ok or -execdir with -okdir .

How to Find and Delete a File in Linux

To delete the files that end up matching your search, you can add -delete at the end of the expression. Do this only when you are positive the results will only match the files you wish to delete.

In the following example, find locates all files in the hierarchy starting at the current directory and fully recursing into the directory tree. In this example, find will delete all files that end with the characters .err :

More Information

You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.

This page was originally published on Monday, October 25, 2010.

Источник

35 Practical Examples of Linux Find Command

The Linux find command is one of the most important and frequently used command command-line utility in Unix-like operating systems. The find command is used to search and locate the list of files and directories based on conditions you specify for files that match the arguments.

find command can be used in a variety of conditions like you can find files by permissions, users, groups, file types, date, size, and other possible criteria.

Through this article, we are sharing our day-to-day Linux find command experience and its usage in the form of examples.

In this article, we will show you the most used 35 Find Commands Examples in Linux. We have divided the section into Five parts from basic to advance usage of the find command.

  • Part I: Basic Find Commands for Finding Files with Names
  • Part II: Find Files Based on their Permissions
  • Part III: Search Files Based On Owners and Groups
  • Part IV: Find Files and Directories Based on Date and Time
  • Part V: Find Files and Directories Based on Size
  • Part VI: Find Multiple Filenames in Linux

1. Find Files Using Name in Current Directory

Find all the files whose name is tecmint.txt in a current working directory.

2. Find Files Under Home Directory

Find all the files under /home directory with the name tecmint.txt.

3. Find Files Using Name and Ignoring Case

Find all the files whose name is tecmint.txt and contains both capital and small letters in /home directory.

4. Find Directories Using Name

Find all directories whose name is Tecmint in / directory.

5. Find PHP Files Using Name

Find all php files whose name is tecmint.php in a current working directory.

6. Find all PHP Files in the Directory

Find all php files in a directory.

7. Find Files With 777 Permissions

Find all the files whose permissions are 777.

8. Find Files Without 777 Permissions

Find all the files without permission 777.

9. Find SGID Files with 644 Permissions

Find all the SGID bit files whose permissions are set to 644.

10. Find Sticky Bit Files with 551 Permissions

Find all the Sticky Bit set files whose permission is 551.

11. Find SUID Files

Find all SUID set files.

12. Find SGID Files

Find all SGID set files.

13. Find Read-Only Files

Find all Read-Only files.

14. Find Executable Files

Find all Executable files.

15. Find Files with 777 Permissions and Chmod to 644

Find all 777 permission files and use the chmod command to set permissions to 644.

16. Find Directories with 777 Permissions and Chmod to 755

Find all 777 permission directories and use the chmod command to set permissions to 755.

17. Find and remove single File

To find a single file called tecmint.txt and remove it.

18. Find and remove Multiple File

To find and remove multiple files such as .mp3 or .txt, then use.

19. Find all Empty Files

To find all empty files under a certain path.

20. Find all Empty Directories

To file all empty directories under a certain path.

21. File all Hidden Files

To find all hidden files, use the below command.

22. Find Single File Based on User

To find all or single files called tecmint.txt under / root directory of owner root.

23. Find all Files Based on User

To find all files that belong to user Tecmint under /home directory.

24. Find all Files Based on Group

To find all files that belong to the group Developer under /home directory.

25. Find Particular Files of User

To find all .txt files of user Tecmint under /home directory.

26. Find Last 50 Days Modified Files

To find all the files which are modified 50 days back.

27. Find Last 50 Days Accessed Files

To find all the files which are accessed 50 days back.

28. Find Last 50-100 Days Modified Files

To find all the files which are modified more than 50 days back and less than 100 days.

29. Find Changed Files in Last 1 Hour

To find all the files which are changed in the last 1 hour.

30. Find Modified Files in Last 1 Hour

To find all the files which are modified in the last 1 hour.

31. Find Accessed Files in Last 1 Hour

To find all the files which are accessed in the last 1 hour.

32. Find 50MB Files

To find all 50MB files, use.

33. Find Size between 50MB – 100MB

To find all the files which are greater than 50MB and less than 100MB.

34. Find and Delete 100MB Files

To find all 100MB files and delete them using one single command.

35. Find Specific Files and Delete

Find all .mp3 files with more than 10MB and delete them using one single command.

That’s it, We are ending this post here, In our next article, we will discuss more other Linux commands in-depth with practical examples. Let us know your opinions on this article using our comment section.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

We are thankful for your never ending support.

Источник

find command in Linux with examples

The find command in UNIX is a command line utility for walking a file hierarchy. It can be used to find files and directories and perform subsequent operations on them. It supports searching by file, folder, name, creation date, modification date, owner and permissions. By using the ‘-exec’ other UNIX commands can be executed on files or folders found.

Syntax :

Options :

  • -exec CMD: The file being searched which meets the above criteria and returns 0 for as its exit status for successful command execution.
  • -ok CMD : It works same as -exec except the user is prompted first.
  • -inum N : Search for files with inode number ‘N’.
  • -links N : Search for files with ‘N’ links.
  • -name demo : Search for files that are specified by ‘demo’.
  • -newer file : Search for files that were modified/created after ‘file’.
  • -perm octal : Search for the file if permission is ‘octal’.
  • -print : Display the path name of the files found by using the rest of the criteria.
  • -empty : Search for empty files and directories.
  • -size +N/-N : Search for files of ‘N’ blocks; ‘N’ followed by ‘c’can be used to measure size in characters; ‘+N’ means size > ‘N’ blocks and ‘-N’ means size My Personal Notes arrow_drop_up

Источник

Читайте также:  Linux переключение между tty
Оцените статью