Commands

Thank you Nadieh Bremer for putting together this incredibly helpful cheatsheet of Commands!

One page to easily find all my main commands for the terminal and other programming languages. Clicking on a cell in any of the a “command” columns copies the content to your clipboard!

Terminal

command functionality
cd [dir] Change directory
ls -Al List all the files and hidden files in the directory
mkdir [dir] Create a new directory within the current directory
`du -sh * sort -n`

This Bash scripting cheatsheet might come in handy at some point

Git

Git is a free and open source distributed version control system. Below are the commands for usage in the Git Bash terminal when doing more complex steps.

command functionality
git clone [url] Clone the Git repository found at the url to the current directory
git status Show the status of any changed/removed/new files
git add [file] Add the file to your next commit
git add . Add all changed files to your next commit
git mv [old name] [new name] Move/rename a folder or file without Git thinking it’s a new file
git commit -m "[message]" Commit all the stages files, creating a new “snapshot”
git commit -a -m "[message]" Stage and commit all the changed files
git push Push all the commits to the online repository
git push origin master Push all the commits of the brach master specifically to the origin
git pull Pull and merge any commits from the online repository
git push origin master Pull all the commits of the brach master specifically from the remote origin
git diff See a difference of everything that is changed but not yet staged
git diff --staged See a difference of everything that is staged but not yet committed
git log Prints out the history of commits

Other Git commands that I haven’t used, but that could become useful in the future

command functionality
git remote add origin [SSH URL] Add a remote connection, called origin of a repo that’s on your local
git remote set-url origin [new URL] Reset the URL of the remote called origin
git remote -v View remote connections
git branch List all the branches of the repository
git switch [branch-name] Switch to the named branch
git checkout [branch-name] Switch to the named branch
git merge [branch-name] While on another branch, merge the named branch back in
git mergetool Run one of several merge utilities to resolve merge conflicts
git branch -m [new-name] Rename the current brach
git branch -d [branch-name] Delete the named branch
git push origin --delete [branch-name] Delete the named branch on the remote origin
git fetch --dry-run See changes to the remote before you pull in
git init Initialize the current directory as a Git repository
git reset [file] Undo uncommited changes to the file
git reset Undo uncommited changes to all changed files
git revert Undo a commit
git submodule Keep a Git repository as a subdirectory of the current Git repository
git stash Save modified and staged changes
git stash pop Write working from top of stash stack
git stash drop Discard the changes from top of stash stack

Here is a pretty good Git Cheatsheet PDF with even more commands, and this Git tutorial shows how to use several commands. The Git-it tutorial was really useful to get some experience with the more difficult parts of Git. If something goes wrong and you don’t know how to fix it, you might find the solution in Dangit, Git!?!.

ffmpeg

A handy command-line tool to convert video files; changing video format, making smaller sizes, cropping, trimming, and a lot more.

command functionality
ffmpeg -i input.mp4 Get the details of the (video) file
ffmpeg -i input.mp4 -vf scale=1280:-1 output.mp4 Scale the video (down) to 1280 pixels in width and keep the same aspect ratio
ffmpeg -i input.mp4 -ss 00:00:04.00 -t 5 -c copy output.mp4 The output video is from the 4th second and lasts for 5 seconds, while the video is not re-encoded
ffmpeg -i input.mp4 -vcodec libx264 -crf 28 -vf scale=1280:-1 output.mp4 Convert to the H.264 codec, use a quality of 28, and scale it to 1280 pixels in width
ffmpeg -i input.mp4 -vcodec libx264 -crf 28 -vf crop=out_w:out_h:x:y,scale=500:-1 output.mp4 First crop the video to out_w width and out_h height, with x:y being the top-left corner of the rectangle, then rescale and downgrade
ffmpeg -r 24 -f image2 -s 840x560 -start_number 15 -i %04d.png -vcodec libx264 -crf 25 -pix_fmt yuv420p video.mp4 Turn a collection of 0001.png images into mp4. With -r 24 24 fps, -s 840x560 resolution of 840x560 pixels, -start_number 15 starting at image 15

Some more commands from Neil.

ImageMagick

A command-line tool to edit and convert images, either for one file or in batch mode.

command functionality
identify [file] Get the details of the (image) file
convert -resize 1280x720 [file-in] [file-out] Resize the file-in to 1280x720 pixels and called file-out
convert -resize x800 -quality 55 [file-in] [file-out] Resize the image to a height of 800px and reduce the quality to 55
convert -crop 600x800+35+0 [file-in] [file-out] Crop the image to 600x800px taking the top-left corner at 35 pixels from the left and 0 pixels from the top
mogrify -format jpg *.png Create a jpg copy of each png file
mogrify -resize 1200\> -quality 55 *.png Resize any png image larger than 1200px wide to 1200px, keeping the aspect ratio, and reduce the quality to 55

ChatGPT helped me write the following command to take a folder with a bunch of images in it (could be .jpg, .png, or .HEIC (a format from iphone photos)) and convert them all to .jpg (and compress 80% and resize down to 1000px x 1000px). It also appends “W##” (whatever week number) to the name of the image:

mkdir converted_images
mogrify -resize "1000x1000>" -quality 80 -path converted_images -format jpg *.png *.jpg *.HEIC *.jpeg

# Rename converted files
cd converted_images
for file in *.jpg; do
    mv "$file" "W##-$file"
done

Explanation of the command:

  • mkdir converted_images: Creates a directory named “converted_images” to store the converted images.
  • for file in *.png *.jpg *.HEIC; do … done: Loops through each PNG and JPG file in the current directory.
  • mv “$file” “W##-$file”: Renames each file by appending “W##-” to the beginning of the filename.
  • mogrify: This is the command for batch processing images in ImageMagick.
  • -resize “1000x1000>”: Resizes images larger than 1000x1000 pixels down to fit within those dimensions.
  • -quality 80: Sets the quality of the JPEG compression to 80.
  • -path converted_images: Specifies the directory where the converted images should be saved.
  • -format jpg: Specifies the format of the output images as JPEG.
  • *.png *.jpg *.HEIC: Specifies the input files. This will process all PNG, JPG, and HEIC files in the current directory.

Ensure you run this command in the directory where your PNG and JPG files are located. It will resize, compress, and convert all images to JPEG format, saving them in the “converted_images” directory.

  • mkdir converted_images: Creates a directory named “converted_images” to store the converted images.
  • mogrify -resize “1000x1000>” -quality 80 -path converted_images -format jpg *.png *.jpg *.heic: Converts, resizes, and sets the quality of all PNG, JPG, and HEIC files to JPG format with the specified resizing and quality settings, and saves them in the “converted_images” directory.
    • mogrify: This is the command for batch processing images in ImageMagick.
    • -resize “1000x1000>”: Resizes images larger than 1000x1000 pixels down to fit within those dimensions.
    • -quality 80: Sets the quality of the JPEG compression to 80.
    • -path converted_images: Specifies the directory where the converted images should be saved.
    • -format jpg: Specifies the format of the output images as JPEG.
    • *.png *.jpg *.HEIC: Specifies the input files. This will process all PNG, JPG, and HEIC files in the current directory.
  • cd converted_images: Changes the directory to “converted_images”.
  • The loop renames each converted JPG file by prepending “W##-” to its filename.

This way, the original images remain unchanged, and only the converted images in the “converted_images” directory will have “W04-” appended to their filenames.

Markdown

Markdown is a lightweight markup language for creating formatted text using a plain-text editor. It basically maps human-readable files to HTML.

command functionality
# H1 <h1> header
## H2 <h2> header
### H3 <h3> header
#### H4 <h4> header
_italics_ italics
**bold** bold
`inline code` inline code
```html ``` longer code blocks
- list item creates an enumerated list with bullet points
[link title](https://url.com) create a link
![image alt tag / figure caption](image.png) add an image

Even more options can be found in the Markdown Cheatsheet. The possible language options for the syntax highlighting.

To serve my hugo site locally so I can see changes to my website before pushing to the remote server: hugo serve -D -F

Built with Hugo | Using a personally adjusted version of Nadieh Bremer's website and the theme Stack