The gMan nixWiki

Because the mind is made of Teflon...

User Tools

Site Tools


general_find

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
general_find [2020/11/17 02:37] – [Find Files by Size] gmangeneral_find [2024/01/19 00:06] (current) gman
Line 1: Line 1:
 ====== Find Stuff in Linux ====== ====== Find Stuff in Linux ======
  
-There are three basic commands to find stuff in Linux: +There are four basic commands to find stuff in Linux: 
   - whereis   - whereis
   - which   - which
Line 64: Line 64:
  
 <code>find /path/to/search/ -name searchTerm 2>/dev/null</code> <code>find /path/to/search/ -name searchTerm 2>/dev/null</code>
 +
 +https://www.cyberithub.com/find-command-in-linux/
 +
 +The -exec flag to find causes find to execute the given command once per file matched, and it will place the name of the file wherever you put the {} placeholder. The command must end with a semicolon, which has to be escaped from the shell, either as \; or as ";".
 +
 +Syntax to be used for find exec multiple commands:
 +
 +<code>find {PATH} [OPTIONS] -exec {COMMAND} {} ;</code>
 +
 +**The first argument** after the find command is the location you wish to search. Although you may specify a specific directory, you can use a metacharacter to serve as a substitute. The three metacharacters that work with this command include:
 +  * Period (.): Specifies the current and all nested folders.
 +  * Forward Slash (/): Specifies the entire filesystem.
 +  * Tilde (~): Specifies the active user's home directory.
 +
 +Find all files (not directories or links) of 1033 bytes in size that are not executable and which can be read (i.e., you can cat the file and read the contents):
 +
 +<code>find . -type f -size 1033c ! -executable -exec cat {} \;</code>
  
 ---- ----
Line 79: Line 96:
  
 ---- ----
- 
  
 ==== Expressions ==== ==== Expressions ====
Line 103: Line 119:
  
 ^  Type  ^ Description  ^ ^  Type  ^ Description  ^
-|   block (buffered) special | +|   regular file |
-|  c  | character (buffered) special |+
 |  d  | directory | |  d  | directory |
 +|  l  | symbolic link |
 +|  c  | character device |
 +|  b  | block device |
 |  p  | named pipe (FIFO) | |  p  | named pipe (FIFO) |
-|  f  | regular file | 
 |  s  | socket | |  s  | socket |
  
Line 157: Line 174:
  
 Use the ''-perm'' expression. There are three ways to specify perm mode:  Use the ''-perm'' expression. There are three ways to specify perm mode: 
-  - No prefix: find exact permissions +  - **No prefix:** find exact permissions 
-  - Prefix of '-': find "at least" permissions (not exact) +  - **Prefix of '-':** find "at least" permissions (not exact) 
-  - Prefix of '/': find permission in either owner, group, OR other+  - **Prefix of '/':** find permission in either owner, group, OR other
  
 **Examples:** **Examples:**
Line 178: Line 195:
 find . -type f -perm -220 find . -type f -perm -220
 # find files writeable by BOTH owner AND group (but no one else) # find files writeable by BOTH owner AND group (but no one else)
 +
 +find / -perm /4000 -type f -exec ls -ld {} \; 2>/dev/null
 +# This will find files with the SUID bit set.
 +# -l long listing format
 +# -d list directory names, not contents
 </code> </code>
  
Line 188: Line 210:
 Three timestamps for **DAYS** (24-hour periods):  Three timestamps for **DAYS** (24-hour periods): 
  
-^ Type  ^ Description + Type  ^ Description 
-| atime | shows when the file was last accessed (e.g., read) | + atime  | shows when the file was last accessed (e.g., read) | 
-| mtime | shows when the file contents were last modified | + mtime  | shows when the file contents were last modified | 
-| ctime | shows when metadata was last changed (including content modification) |+ ctime  | shows when metadata was last changed (including content modification) |
  
 Three timestamps for **MINUTES** (60-second periods) Three timestamps for **MINUTES** (60-second periods)
  
-^ Type  ^ Description + Type  ^ Description 
-| amin | file was last accessed (e.g., read) | + amin  | file was last accessed (e.g., read) | 
-| mmin | file contents were last modified | + mmin  | file contents were last modified | 
-| cmin | file metadata was last changed (including content modification) |+ cmin  | file metadata was last changed (including content modification) |
  
-^ Prefix  ^ Description + Prefix  ^ Description 
-| + | greater than | +  | greater than | 
-| - | less than |+  | less than |
  
 **Note:** Any fractional part of the time period is ignored. Therefore ''-atime +1'' will find files accessed TWO days ago or longer (because files accessed today, or within the last 23.99 hours, can be found with ''atime 0'').  **Note:** Any fractional part of the time period is ignored. Therefore ''-atime +1'' will find files accessed TWO days ago or longer (because files accessed today, or within the last 23.99 hours, can be found with ''atime 0''). 
Line 221: Line 243:
 </code> </code>
  
 +----
  
general_find.1605580641.txt.gz · Last modified: by gman