Cheat sheet for command lines I will never remember
find WHERE WHAT
find . -name "*.js" ! -path "./node_modules/*"
find . -regex ".*\\.\\(html\\|js\\)"
Note the backslash before group brackets and alternation operator. Use -regextype posix-extended
to get rid of the backslashes
-maxdepth LEVELS -mindepth LEVELS
-type [fd]
-iname NAME : case insensitive name
-size [+-]SIZE[kMG]
grep SEARCH IN_FILES
grep searchString app/* build/*
-H : file name
-n : line number
-r : recursive
-i : case insensitive
-l : only list files
-v : inverse (filter out)
Extracts the first column of output
awk '{print $1}'
Extracts before last column and append it to a string (needs a white space)
awk '{print "path/" $(NF-1)}'
-F',' : Sets ',' as the field separator
Reverse output (reverse cat) of a file or use a pipe
or tail -r
Runs a command on every line of input
ls -l | xargs -I{} echo {}
Inlines the output of a command (defaults utility to echo)
ls -l | xargs
-I{} : Argument placeholder
-n1 : Executes utility for each (one) argument (ie: -rw-r----- root root 358 Aug 8 15:00 README.md
is 8 arguments)
-P2 : Parallel mode (2 at a time)
-p : Prompts before executing every command
String substitution (global) in file or use a pipe
sed 's/hello/world/' <file>
Create a symbolic link
ln -s /path/to/fileName linkName
Disk usage in a directory
du -shc * | sort -h
while read line; do echo "$line"; done;
for x in {a..z}; do echo "$x"; done
Open result of a command in a buffer
ls | vim -
Pipe current file in a command and send back into vim
:$!sort -u
Search and replace in the whole file
%s/search/replace/
(g flag optional at the end if vim configured with gdefault)
Search and replace the last search
%s//replace/
Delete all occurences of the last search
%s///
convert img.gif -coalesce img_%03d.png
ffmpeg -framerate 6 -i img_%03d.png -pix_fmt yuva420p output.webm