|
15 | 15 | - [Petición parámetros](#petición-parámetros)
|
16 | 16 | - [case](#case)
|
17 | 17 |
|
18 |
| -- [Diff](#diff) |
| 18 | +- [diff](#diff) |
| 19 | + |
| 20 | +- [grep](#grep) |
| 21 | + |
| 22 | +- [sort & uniq](#sort-&-uniq) |
| 23 | + |
| 24 | +- [sed](#sed) |
| 25 | + |
| 26 | +- [awk](#awk) |
| 27 | + |
19 | 28 |
|
20 | 29 | ***
|
21 | 30 |
|
@@ -175,6 +184,165 @@ Las líneas con contenido "ntp clock-period" son ignoradas.
|
175 | 184 |
|
176 | 185 | ***
|
177 | 186 |
|
| 187 | +# Find |
| 188 | + |
| 189 | +## Find searches a directory for files |
| 190 | + |
| 191 | + find /tmp -type d -print |
| 192 | + |
| 193 | +## Find a filename |
| 194 | + |
| 195 | + find / -name '*.txt' |
| 196 | + |
| 197 | +## Find type |
| 198 | + |
| 199 | + find -type [TYPE] |
| 200 | + f: regular file |
| 201 | + d: directory |
| 202 | + l: symlink |
| 203 | + p: named pipe |
| 204 | + s: socket |
| 205 | + |
| 206 | + find /tmp -type d,l |
| 207 | + |
| 208 | +## Find path and ipath |
| 209 | + |
| 210 | +Search the full path, and ipath (case insensitive) |
| 211 | + |
| 212 | + find / -path '*tmp*/*' |
| 213 | + |
| 214 | +## Find maxdepth |
| 215 | + |
| 216 | +Only descend NUM levels when searching a directory. |
| 217 | + |
| 218 | + find / -path '*tmp*/*' -maxdepth 2 |
| 219 | + |
| 220 | +## Find -mtime |
| 221 | + |
| 222 | +Files that were modified at most NUM days in the past. |
| 223 | + |
| 224 | + find / -name '*.py' -mtime 2 |
| 225 | + |
| 226 | +## Find -print |
| 227 | + |
| 228 | +Action: print filename of files found. |
| 229 | + |
| 230 | + find . -name '*.py' -mtime 0 -print |
| 231 | + ./test.py |
| 232 | + ./test3.py |
| 233 | + ./test2.py |
| 234 | + |
| 235 | + find . -name '*.py' -mtime 0 -print0 |
| 236 | + ./test.py./test3.py./test2.py |
| 237 | + |
| 238 | + find . -name '*.py' -mtime 0 -print0 | xargs -0 |
| 239 | + ./test.py ./test3.py ./test2.py |
| 240 | + |
| 241 | +## Find -exec |
| 242 | + |
| 243 | +Action: run COMMAND on every file found. |
| 244 | + |
| 245 | + find . -name '*.py' -mtime 0 -exec ls -l '{}' \; |
| 246 | + find . -name '*.py' -mtime 0 -exec cat '{}' \; |
| 247 | + |
| 248 | +## Find -delete |
| 249 | + |
| 250 | +Action: delete all files found |
| 251 | + |
| 252 | + find . -name '*.py' -mtime 0 -delete |
| 253 | + |
| 254 | +## Locate and updatedb |
| 255 | + |
| 256 | +The `locate` command searches a adatabase of eery file on your system. Faster than find, but cant get out of date. |
| 257 | + |
| 258 | +Updates the database: |
| 259 | + |
| 260 | + $ sudo updatedb |
| 261 | + |
| 262 | +*** |
| 263 | + |
| 264 | +# grep |
| 265 | + |
| 266 | +`grep` lets you search fiels for text |
| 267 | + |
| 268 | +# grep -i |
| 269 | + |
| 270 | +Case insensitive. |
| 271 | + |
| 272 | + $ grep -i Apple foo.txt |
| 273 | + apple |
| 274 | + |
| 275 | +# grep -e or egrep |
| 276 | + |
| 277 | +Search regular expressions. |
| 278 | + |
| 279 | + $ grep -e '^....$' foo.txt |
| 280 | + kiwi |
| 281 | + |
| 282 | +# grep -v |
| 283 | + |
| 284 | +Invert match, find all lines that don't match. |
| 285 | + |
| 286 | + $ grep -ve '^....$' foo.txt |
| 287 | + apple |
| 288 | + banana |
| 289 | + orange |
| 290 | + |
| 291 | +# grep -l |
| 292 | + |
| 293 | +Only show the filenames of the files that matched. |
| 294 | + |
| 295 | + $ grep -le '^....$' *.txt |
| 296 | + foo.txt |
| 297 | + |
| 298 | +# grep -o |
| 299 | + |
| 300 | +Only print the matching part of the line (not the whole line). |
| 301 | + |
| 302 | + $ grep 'kiwi' foo.txt |
| 303 | + kiwi |
| 304 | + kiwi with orange |
| 305 | + |
| 306 | + $ grep -o 'kiwi' foo.txt |
| 307 | + kiwi |
| 308 | + kiwi |
| 309 | + |
| 310 | +# grep -A -B -C |
| 311 | + |
| 312 | +Show `context` for your search. |
| 313 | + |
| 314 | +Will show 1 line of context `a`fter a match, `b`efore a match, `c`ontext. |
| 315 | + |
| 316 | + $ grep -A 1 'banana' foo.txt |
| 317 | + banana |
| 318 | + orange |
| 319 | + |
| 320 | + $ grep -B 1 'banana' foo.txt |
| 321 | + apple |
| 322 | + banana |
| 323 | + |
| 324 | + $ grep -C 1 'banana' foo.txt |
| 325 | + apple |
| 326 | + banana |
| 327 | + orange |
| 328 | + |
| 329 | +# grep -F |
| 330 | + |
| 331 | +Don't treat the match string as a regex. |
| 332 | + |
| 333 | +# grep -r |
| 334 | + |
| 335 | +Recursive. Search all the files in a directory. |
| 336 | + |
| 337 | +# grep -a |
| 338 | + |
| 339 | +Search binaries: threat binary data like it's text instead of ignoring it. |
| 340 | + |
| 341 | +*** |
| 342 | + |
| 343 | +*** |
| 344 | + |
178 | 345 | ## URLs Referencia:
|
179 | 346 |
|
180 | 347 | - <https://www.computerhope.com/unix/udiff.htm>
|
| 348 | +- <https://twitter.com/b0rk> |
0 commit comments