Whats here:  FIND, GREP, EXEC, TR, SED, AWK, TAR, REGEX

 Useful site to find common linux file extensions: www.lauraliparulo.altervista.org/most-common-linux-file-extensions/


Find passwords

find / -name pass* 2>/dev/null  

Type can be file or directory (f or d)

find / -type f  -name <filename> 2>/dev/null

You can also use wildcards to find files and directories

Case insensitive search

-iname

Specify user

-user

Size flag

-size (use either just number or + - with the number)

with size the following are required:

-c = for bytes

-k = for KiBs

-M = for MiBs

Example: a size of less than 50 bytes :   -50c

Time flags

min = for minutes

time = for days

prefixes:

a = accessed

m = modified

c = changed

Example: to find a file last accessed more than 1 hour ago:   -amin +60

*To specify a file modified within last 24 hours, use the -mtime 0 option


Exec flag

Will execute a new command for you when used with the find.

Example: -exec whoami \;


Translate (TR)

TR = translate

Syntax:

tr [option] [set 1] [set 2]

- The characters in set 1 are translated into character of set 2

Flags:

-c = complements set of characters in set 1

-d = delete characters in set 1 from input

-s = replaces repeated character in set 1

Examples: (with flags)

-c 

file.txt = Welcome to my homepage

convert lower to upper: cat file.txt | tr "[a-z]" "[A-Z]"

==========

-d

echo "hello" | tr -d 'h'   = ello  (h is removed)

==========

-s

echo "hello" | tr -s 'l'  = helo (l is squeesed)


More examples:

echo myfoot | tr o x (replaces o's with x's) = my fxxt

echo my foot | tr mo tx (change m to t, o to x) = ty fxxt

echo leet | tr let 137 (l to 1, e to 3, t to 7)

echo foo-foo | tr - _    (changes to underscores) = foo_foo

echo foo foo | tr "" _    (whitespace replaced with underscores) = foo_foo

echo football | tr [:lower] [:upper]   (replaces lower to upper) = FOOTBALL

echo abc | tr [a-z] x   (replaces any a-z letters with letter x) = xxx

echo fooTBall | tr [a-z] x   (replaces any a-z (lower) with x) = xxxTBxxx


Regular Expressions (REGEX)

Examples:

ls -d D*  - finds any dir starting with upper D

ls -d *s   - finds dirs ending with lower s

ls -d *l*  -finds all dir with letter l in it

ls -l Desktop/*.txt  - go into desktop and find all files ending in .txt

[a-c]at = finds the first letters a,b,c = bat, cat

[0-9][0-9] = 2 digits

grep "c[aeiou]t" - will find words with letter c in it, followed by either AEIOU, ending with t

^ca = car, cattle

ing$ = floating, sailing

^cat$ = cat

egrep "^s" /etc/passwd   - start with letter s

egrep "n$" /etc/passwd   - end with n

Quantifiers:

+ = 1 or more

? = 0 or 1 of a character

* = 0 or more of a chater

{ } = (insert number) a certain no. or range


SED

Example:

sed -e 's/:/---/g' /etc/passwd

sed -e 's/bin/MIKE/g'

sed 's/,/  /g' <filename>