Linux misc.

Tmpfs

mount -t tmpfs -o size=20G,exec tmpfs /media

Folder sizes (sorted)

du -h -d 1 ./ | sort -h

Where ./ is the directory and -d 1 is the recursive depth

Copying lots of small files over ssh

files -> tar -> ssh -> tar -> files

ssh [email protected] 'tar -czpf - /home/foo/bar' | tar -xzpf -

Find

Find all .yaml files and replace namespace: test -> namespace: sadbooth

find . -iname '*.yaml' -exec sed -i '' "s/namespace: test/namespace: sadbooth/g" {} \;
# Case insensitive
find <path> -iname '*something*'`
# Using 'or'
find <path> ( -name '*something*' -o -iname '*else*' )
# File or directory
-type f
-type d
# Last modified - last 7 days
-mtime -7
# Size - over 1gigabyte
-size +1G
# Owner
-owner james

Grep

Regex

grep -E "[0-9]*" <file>
# match lines with numbers
# (aka egrep)

Search recursively

grep -rn 'term' <path>
# -r -> Recursive
# -n -> Show the line number
# -w -> Whole word regex match
# -i -> Case-insensitive
# -v -> inVerse - Find lines that _dont_ match
# Show context (Lines either side)
# -A <num> -> After
# -B <num> -> Before
# -C <num> -> Context (before & after)
# Or, only show the files names...
# -l -> Files with matches
# -L -> Files without matches

Highlight part of text but show all

grep --color=always -e "^" -e "hello" testfile

Sed

Replace all occurrences in files

sed -i s/old/new/g <path>
# -i -> in-place

Mount an SMB share

apt install smbclient cifs-utils
mount -t cifs //srv01/c$ ~/mnt/srv01_c/ -ouser="james",pass='xyz',dom="abc.local"