man {command} # shows the manual of the command
pwd # prints in shell the path of the pwd
ls # list contents of pwd
ls -latrh # detailed view of list reverse sorted by modification time
# l(ong): long list format
# a(ll): includes hidden files and directories
# t(ime): sort by modification time
# r(everse): reverse the order of the sort
# h(uman): makes file sizes human readable
ls ../other_directory # lets you inspect other directories
cd {target/directory} # change pwd to target directory
echo 'Hello, World' # prints text
cat file.txt # prints the contents of the file
touch hello.txt # creates file if not exists or update the timestamps if it doesn't
cp hello hello-again # copy a file/directory to target file/directory
mv hello-again goodbye # move a file/directory to target file/directory
rm hello # remove a file
rm -r mydir # remove a directory (needs recursive flag)
ln -s text.txt other_directory/other_text.txt # creates a symbolic link
less book.txt # lets you view less text, in a scrollable manner
grep 'Sinbad' the-count-of-monte-cristo.txt # lets you pattern match against text
Recommendation for a faster grep
: ripgrep
find -name 'node_modules' -type d # lets you find files and directories
Recommendation for an easier find
: fd
cat template.yaml
name: sinbad the sailor
email: REPLACE_EMAIL # target
url: https://example.com
sed 's/REPLACE_EMAIL/[email protected]/' template.yaml # lets you find files and directories
name: sinbad the sailor
email: [email protected] # replaced here
url: https://example.com
It's a programming language for text processing, filtering and extraction. Use it with RegEx.
awk -F'\t' '{print $3 " | " $4}' quotes.tsv
# -F'\t': Sets the field separator to a tab character ('\t'). This tells AWK to split each line of input based on tabs.
# '{print $3 " | " $4}': Specifies the action to perform on each line of input. Here, it prints the contents of the third column, followed by a pipe character ('|'), followed by the contents of the fourth column.
sort data.txt # sorts text contents (default is alphabetic)
sort -k2 -n data.txt # sort by numeric
head data.txt # lets you see the first lines of a file
tail data.txt # lets you see the last lines of a file
tail -f log # -f flag makes so the terminal prints any new lines appended
It loads the directory tree into the fuzzy finder
Generate possible completions for commands. When used on it's own, lists all possible commands from current shell.
compgen -c | less
The standard output of a command can become the standard input of the next command with the pipe | operator.
echo 'Hello, world!' | sed 's/world/universe'
Hello, universe!
Will split the (piped) stdin
and take them as arguments to the next function.
ls | xargs du -sh # command to show the disk usage of each directory in ls
# du: disk usage
# -s: summarizes disk usage of each argument
# -h: human readable
ls | grep 'l' | xargs du -sh # filtering the results of ls by the letter 'l'
You can use commands inside commands, and whole pipelines with this syntax: $(command)
echo "My current directory is: $(pwd)"
My current directory is: /home/user/notes
Direct the stdout
of a command to a file with the >
operator
ls --help > ls-help.txt
Append to the end of the file with >>
You can use the contents of a file as the stdin
of a command with <
operator
tr 'a-z' 'A-Z' < template.yaml
compgen -c | fzf | xargs man
Suggestion - set an alias with
alias fman="compgen -c | fzf | xargs mancompgen "
kubectl get pods -A --no-headers | fzf \awk '{print $2, $1}' | xargs -n 2 sh -c 'kubectl describe pod $0 -n $1'
du -ah . | sort -hr | head -n 10
find . -name 'node_modules' -type d |
xargs du -sh |
sort -hr |
fzf -m --header "Select which ones to delete" --preview 'cat $(dirname {})/package.json' |
xargs -r rm -rf