-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathFind.html
126 lines (124 loc) · 10.5 KB
/
Find.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<!DOCTYPE html>
<html>
<head>
<title>Find Command</title>
</head>
<body>
<!--
html5up.net |
Free for personal and commercial use under the CCA 3.0 license (html5up.net/license)
-->
<p style="text-align: center;"><u><strong><span style="font-size: 24px;">Whats here: <span style="color: rgb(97, 189, 109);">FIND</span>, <span style="color: rgb(61, 142, 185);">GREP</span>, <span style="color: rgb(251, 160, 38);">EXEC</span>, <span style="color: rgb(44, 130, 201);">TR</span>, <span style="color: rgb(147, 101, 184);">SED</span>, <span style="color: rgb(184, 49, 47);">AWK</span>, TAR, <span style="color: rgb(243, 121, 52);">REGEX</span></span></strong></u></p>
<p><span style="font-size: 24px; color: rgb(0, 0, 0);"> <strong><u><span style="text-shadow: 3px 3px 2px rgba(217, 28, 28, 0.8);">Useful site to find common linux file extensions:</span></u></strong> www.lauraliparulo.altervista.org/most-common-linux-file-extensions/</span></p>
<p><br></p>
<p><span style="font-size: 24px; color: rgb(65, 168, 95);"><strong><u>Find passwords</u></strong></span></p>
<p><span style="font-size: 24px; color: rgb(0, 0, 0);">find / -name pass* 2>/dev/null </span></p>
<p><span style="font-size: 24px; color: rgb(0, 0, 0);"><strong><u><span style="text-shadow: 3px 3px 2px rgba(54, 221, 135, 0.8);">Type can be file or directory (f or d)</span></u></strong></span></p>
<p><span style="font-size: 24px; color: rgb(0, 0, 0);">find / -type f -name <filename> 2>/dev/null</span></p>
<p><span style="font-size: 24px; color: rgb(0, 0, 0);">You can also use wildcards to find files and directories</span></p>
<p><span style="font-size: 24px; color: rgb(0, 0, 0);"><strong><u><span style="text-shadow: 3px 3px 2px rgba(54, 221, 135, 0.8);">Case insensitive search</span></u></strong></span></p>
<p><span style="font-size: 24px; color: rgb(0, 0, 0);">-iname</span></p>
<p><span style="font-size: 24px;"><strong><u><span style="text-shadow: 3px 3px 2px rgba(54, 221, 135, 0.8);">Specify user</span></u></strong></span></p>
<p><span style="font-size: 24px;">-user</span></p>
<p><strong><span style="font-size: 24px;"><u><span style="text-shadow: 3px 3px 2px rgba(54, 221, 135, 0.8);">Size flag</span></u></span></strong></p>
<p><span style="font-size: 24px;">-size (use either just number or + - with the number)</span></p>
<p><span style="font-size: 24px;">with size the following are required:</span></p>
<p><span style="font-size: 24px;"><strong>-c</strong> = for bytes</span></p>
<p><span style="font-size: 24px;"><strong>-k</strong> = for KiBs</span></p>
<p><span style="font-size: 24px;"><strong>-M</strong> = for MiBs</span></p>
<p><span style="font-size: 24px;">Example: a size of less than 50 bytes :<strong> -50c</strong></span></p>
<p><span style="font-size: 24px;"><strong><u><span style="text-shadow: 3px 3px 2px rgba(54, 221, 135, 0.8);">Time flags</span></u></strong></span></p>
<p><span style="font-size: 24px;"><strong>min</strong> = for minutes</span></p>
<p><span style="font-size: 24px;"><strong>time</strong> = for days</span></p>
<p><span style="font-size: 24px;"><strong>prefixes:</strong></span></p>
<p><span style="font-size: 24px;"><strong>a</strong> = accessed</span></p>
<p><span style="font-size: 24px;"><strong>m</strong> = modified</span></p>
<p><span style="font-size: 24px;"><strong>c</strong> = changed</span></p>
<p><span style="font-size: 24px;">Example: to find a file last accessed more than 1 hour ago: <strong> -amin +60</strong></span></p>
<p><span style="font-size: 24px;">*To specify a file modified within last 24 hours, use the<strong> -mtime 0</strong> option</span></p>
<p><br></p>
<p><strong><u><span style="font-size: 24px; color: rgb(251, 160, 38);">Exec flag</span></u></strong></p>
<p><span style="font-size: 24px;">Will execute a new command for you when used with the find.</span></p>
<p><span style="font-size: 24px;">Example: </span><strong><span style="font-size: 24px;">-exec whoami \;</span></strong></p>
<p><br></p>
<p><span style="font-size: 24px;"><strong><u><span style="color: rgb(41, 105, 176);">Translate (TR)</span></u></strong></span></p>
<p><span style="font-size: 24px;"><span style="color: rgb(0, 0, 0);">TR = translate</span></span></p>
<ul>
<li><span style="font-size: 24px;"><span style="color: rgb(0, 0, 0);">Can delete or translate characters</span></span></li>
<li><span style="font-size: 24px;"><span style="color: rgb(0, 0, 0);">upper to lower, squeese repeating, deleting specific character, basic find and replace</span></span></li>
<li><span style="font-size: 24px;"><span style="color: rgb(0, 0, 0);">can be used with pipe to support more complex transactiosn</span></span></li>
</ul>
<p><span style="font-size: 24px;"><span style="color: rgb(0, 0, 0); text-shadow: rgba(72, 136, 203, 0.8) 3px 3px 2px;"><strong><u>Syntax:</u></strong></span></span></p>
<p><span style="font-size: 24px;"><span style="color: rgb(0, 0, 0);">tr [option] [set 1] [set 2]</span></span></p>
<p><span style="font-size: 24px;"><span style="color: rgb(0, 0, 0);">- The characters in set 1 are translated into character of set 2</span></span></p>
<p><span style="font-size: 24px; text-shadow: rgba(72, 136, 203, 0.8) 3px 3px 2px;">Flags:</span></p>
<p><span style="font-size: 24px;">-c = complements set of characters in set 1</span></p>
<p><span style="font-size: 24px;">-d = delete characters in set 1 from input</span></p>
<p><span style="font-size: 24px;">-s = replaces repeated character in set 1</span></p>
<p><span style="font-size: 24px; text-shadow: rgba(72, 136, 203, 0.8) 3px 3px 2px;">Examples: (with flags)</span></p>
<p><span style="font-size: 24px;">-c </span></p>
<p><span style="font-size: 24px;">file.txt = Welcome to my homepage</span></p>
<p><span style="font-size: 24px;">convert lower to upper: cat file.txt | tr "[a-z]" "[A-Z]"</span></p>
<p><span style="font-size: 24px;">==========</span></p>
<p><span style="font-size: 24px;">-d</span></p>
<p><span style="font-size: 24px;">echo "hello" | tr -d 'h' = ello (h is removed)</span></p>
<p><span style="font-size: 24px;">==========</span></p>
<p><span style="font-size: 24px;">-s</span></p>
<p><span style="font-size: 24px;">echo "hello" | tr -s 'l' = helo (l is squeesed)</span></p>
<p><br></p>
<p><span style="font-size: 24px; text-shadow: rgba(72, 136, 203, 0.8) 3px 3px 2px;">More examples:</span></p>
<p><span style="font-size: 24px;">echo myfoot | tr o x (replaces o's with x's) = my fxxt</span></p>
<p><span style="font-size: 24px;">echo my foot | tr mo tx (change m to t, o to x) = ty fxxt</span></p>
<p><span style="font-size: 24px;">echo leet | tr let 137 (l to 1, e to 3, t to 7)</span></p>
<p><span style="font-size: 24px;">echo foo-foo | tr - _ (changes to underscores) = foo_foo</span></p>
<p><span style="font-size: 24px;">echo foo foo | tr "" _ (whitespace replaced with underscores) = foo_foo</span></p>
<p><span style="font-size: 24px;">echo football | tr [:lower] [:upper] (replaces lower to upper) = FOOTBALL</span></p>
<p><span style="font-size: 24px;">echo abc | tr [a-z] x (replaces any a-z letters with letter x) = xxx</span></p>
<p><span style="font-size: 24px;">echo fooTBall | tr [a-z] x (replaces any a-z (lower) with x) = xxxTBxxx</span></p>
<p><br></p>
<p><span style="font-size: 24px; color: rgb(243, 121, 52);"><strong><u>Regular Expressions (REGEX)</u></strong></span></p>
<ul>
<li><span style="font-size: 24px;">2 forms of grep - GREP and EGREP</span></li>
</ul>
<p><span style="font-size: 24px;">Examples:</span></p>
<p><span style="font-size: 24px;">ls -d D* - finds any dir starting with upper D</span></p>
<p><span style="font-size: 24px;">ls -d *s - finds dirs ending with lower s</span></p>
<p><span style="font-size: 24px;">ls -d *l* -finds all dir with letter l in it</span></p>
<p><span style="font-size: 24px;">ls -l Desktop/*.txt - go into desktop and find all files ending in .txt</span></p>
<p><span style="font-size: 24px;">[a-c]at = finds the first letters a,b,c = bat, cat</span></p>
<p><span style="font-size: 24px;">[0-9][0-9] = 2 digits</span></p>
<p><span style="font-size: 24px;">grep "c[aeiou]t" - will find words with letter c in it, followed by either AEIOU, ending with t</span></p>
<p><span style="font-size: 24px;">^ca = car, cattle</span></p>
<p><span style="font-size: 24px;">ing$ = floating, sailing</span></p>
<p><span style="font-size: 24px;">^cat$ = cat</span></p>
<p><span style="font-size: 24px;">egrep "^s" /etc/passwd - start with letter s</span></p>
<p><span style="font-size: 24px;">egrep "n$" /etc/passwd - end with n</span></p>
<p><span style="font-size: 24px;"><span style="text-shadow: 3px 3px 2px rgba(211, 105, 34, 0.8);">Quantifiers:</span></span></p>
<p><span style="font-size: 24px;">+ = 1 or more</span></p>
<p><span style="font-size: 24px;">? = 0 or 1 of a character</span></p>
<p><span style="font-size: 24px;">* = 0 or more of a chater</span></p>
<p><span style="font-size: 24px;">{ } = (insert number) a certain no. or range</span></p>
<p><br></p>
<p><span style="font-size: 24px;"><strong><u><span style="color: rgb(147, 101, 184);">SED</span></u></strong></span></p>
<ul>
<li style="text-align: justify;"><span style="font-size: 24px;">Use SED ot take stream of data & match against pattern and modify that info that matches that pattern in someway.</span></li>
</ul>
<p><span style="font-size: 24px; text-shadow: rgba(140, 34, 211, 0.8) 3px 3px 2px;">Example:</span></p>
<p><span style="font-size: 24px;">sed -e 's/:/---/g' /etc/passwd</span></p>
<ul>
<li><span style="font-size: 24px;">Removes colons fromthat file, so sed wil find colon and replace with --- ( g stands for global)</span></li>
</ul>
<p><span style="font-size: 24px;">sed -e 's/bin/MIKE/g'</span></p>
<ul>
<li><span style="font-size: 24px;">This replace all instances of bin with MIKE</span></li>
</ul>
<p><span style="font-size: 24px;">sed 's/,/ /g' <filename> </span></p>
<ul>
<li><span style="font-size: 24px;">replaces commas with whitespace</span></li>
<li><span style="font-size: 24px;">can use -i flag to make a permanen</span><span style="font-size: 24px;">t change to the document</span></li>
</ul>
<p><span style="font-size: 24px;"><br></span></p>
<p><span style="font-size: 24px;"><br></span></p>
<p><br></p>
</body>
</html>