Command Line

I use iTerm with ZSH and Oh My Zsh. My dotfiles are available on Github.

Make Directory #

mkdir directory_name

Move File #

mv myfile.txt new_location/myfile.txt

# Use move to rename a file in place
mv old_name.txt new_name.txt

View Contents of File #

cat myfile.txt

Write or Append to File #

# Overwrite existing contents
echo "Some content" > myfile.txt

# Append to content
echo "Some content" >> myfile.txt

Diff Two Files #

`diff file1.txt file2.txt`

# open in VSCode
`diff file1.txt file2.txt | code -`

# open in Sublime Text
`diff file1.txt file2.txt | sublime -n`

Batch Image Resize #

Using sips (scriptable image processing system):

$ sips -Z 640 *.jpg

Invert Image Colours #

for FILE in *; do convert $FILE -channel RGB -negate $FILE; done

QuickLook a File #

qlmanage -p myfile.txt

Output to Variable #

VARIABLE=$(pwd)

Show Calendar #

$ cal
$ cal -y 2021

Variable is null #

if [ -z "$VAR" ]; then
echo "VAR is null"
exit
fi

Output file list #

for file in ./dir/*; do
echo "${file##*/}"
done