Differences

This shows you the differences between two versions of the page.

Link to this comparison view

linuxfind [2011/09/03 22:12]
bpienig created
linuxfind [2019/07/18 04:36]
Line 1: Line 1:
-====== Linux Find Command ====== 
  
- 
-===== Find empty directories ===== 
-<file bash>​find $HOME -depth -type d -empty</​file>​ 
-This will find empty directories in your home directory. 
- 
-===== Find empty files =====  
-<file bash>​find $HOME -depth -type f -empty</​file>​ 
-This will finde empty common files in your home directory. 
- 
-===== Find a file with a specific name =====  
-<file bash>​find $HOME -name [name_of_file]</​file>​ 
-This will find files with a given name in any child directory of your home. 
- 
-===== Find a file with a specific extension ===== 
-<file bash>​find $HOME -name "​*.[given_extension]"</​file>​ 
-This find files wit the given extension all along your home, an example to find jpg files is: 
-<file bash>​find $HOME -name '​*.jpg'</​file>​ 
- 
-===== Find files with specific permissions ===== 
-<file bash>​find $HOME -perm [permission bits]</​file>​ 
-This will find files with the given permission bits in your home, as an example we can look for .txt files that can have 644 bits on. 
-<file bash>​find $HOME -name '​*.txt'​ -perm 644</​file>​ 
- 
-===== Find files with some given permissions and no matter the rest ===== 
-<file bash>​find $HOME -perm -[permision_bits]</​file>​ 
-This will find files in your home that have match with the given permissions but that can also have some others, as an example: 
-<file bash>​find $HOME -name '​*.txt'​ -perm -644</​file>​ 
-This will find the files with 644 but also some with 664 or 777 or anything "​greater"​ than 644.  
- 
-Output comparison Let's see some output comparison for this to be better understood. 
- 
-<file bash> 
-find $HOME -name '​*.txt'​ -perm 644 -exec ls -l {} \; 
--rw-r--r-- 1 root root 181 2007-10-09 23:27 /​home/​benp/​a.txt 
--rw-r--r-- 1 benp benp 2757 2007-08-29 23:52 /​home/​benp/​b.txt 
--rw-r--r-- 1 benp benp 77431 2007-09-05 23:11 /​home/​benp/​c.txt 
-</​file>​ 
- 
-<file bash> 
-find $HOME -name '​*.txt'​ -perm -644 -exec ls -l {} \; 
--rw-r--r-- 1 root root 181 2007-10-09 23:27 /​home/​benp/​a.txt 
--rw-r--r-- 1 benp benp 2757 2007-08-29 23:52 /​home/​benp/​b.txt 
--rw-r--r-- 1 benp benp 77431 2007-09-05 23:11 /​home/​benp/​c.txt 
--rw-rw-r-- 1 benp benp 464 2007-09-06 01:23 /​home/​benp/​d.txt 
-</​file>​ 
- 
-As you may see in the first example we do not see the file <file bash>​d.txt</​file>​ as it has 664 permissions. 
- 
-But, on the second output, it is listed as it has "​greater"​ permissions than 644. 
- 
-===== Find files of given sizes =====  
-<file bash>​find -size n[cwbkMG]</​file>​ 
-This will output the files of a given block size, as an example we can see: 
- 
-<file bash>​find $HOME -name '​*.txt'​ -size 4k -exec ls -l {} \;</​file>​ 
-And the output is: 
- 
-<file bash> 
--rw-r--r-- 1 benpbenp 3707 2007-07-25 15:48 /​home/​benp/​README.txt 
--rw-r--r-- 1 benpbenp 4043 2007-01-22 15:44 /​home/​benp/​Desktop/​front/​README.txt 
--rw-r--r-- 1 benp benp 3112 2007-09-23 15:39 /​home/​benp/​Desktop/​adsense/​README.txt 
--rw-r--r-- 1 benp benp 3707 2007-09-23 15:39 /​home/​benp/​Desktop/​akismet/​README.txt 
--rw-r--r-- 1 benp benp 3616 2007-09-23 15:39 /​home/​benp/​Desktop/​show-to-install.txt 
-</​file>​ 
- 
-Now let's see this other: 
- 
-<file bash>​find $HOME -name '​*.txt'​ -size 5k -exec ls -l {} \;</​file>​ 
-And the output is: 
- 
-<file bash> 
--rw-r--r-- 1 benp benp 4496 2007-09-23 15:39 /​home/​benp/​captcha.txt 
-</​file>​ 
- 
-Now if you divide each file size by 1024 (1k) you will see that the first output is always lower than 4096 (4k) and upper 3072 (3k), 
-on the second output you have it between 4096 (4k) and 5120 (5k). 
- 
-===== Find files with a give name and any extension =====  
-<file bash>​find -name '​[given_name].*'</​file>​ 
-This will output the files of any given name but with any extension 
- 
-===== Find files modified in the latest blocks of 24 hours ===== 
-<file bash>​find -mtime n</​file>​ 
-Where n is: 0 for the last 24 hours 1 for the last 48 hours 2 for the last 72 hours and so on. 
- 
-===== Find files that was accessed in the latests blocks of 24 hours ===== 
-<file bash>​find -atime n</​file>​ 
-Where n is: 0 for the last 24 hours 1 for the last 48 hours 2 for the last 72 hours and so on. 
 
 linuxfind.txt ยท Last modified: 2019/07/18 04:36 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
Recent changes RSS feed Driven by DokuWiki