Skip to content

Instantly share code, notes, and snippets.

@andrashann
Last active February 16, 2024 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save andrashann/84abf091c97cd25799b0d49e81460ea5 to your computer and use it in GitHub Desktop.
Save andrashann/84abf091c97cd25799b0d49e81460ea5 to your computer and use it in GitHub Desktop.
Command line notes – a collection of useful one-liners
# Copyright 2019 A. H.
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
# RENAME
# Replace a string in all file names in a folder
rename 's/old/new/' *
# EXIFTOOL
# Add coordinates to images in folder from gpx file
exiftool -P -overwrite_original -geotag=track.gpx /path/to/images
# Name files according to EXIF date and timestamp
exiftool -ext jpg -ext mp4 '-filename<CreateDate' -d '%Y-%m-%d %H.%M.%S%%-c.%%e' ../exiftool_test/
# Delete all EXIF information
exiftool -all= foo.jpg
# Modify file modification/creation date to match EXIF data
exiftool '-DateTimeOriginal>FileModifyDate' foo.jpg
# Modify EXIF creation date to match filename for files in this folder
exiftool "-createdate<filename" "-datetimeoriginal<filename" -overwrite_original_in_place ./
# Shift all timestamps of pictures
exiftool -AllDates-=1:10 -filemodifydate-=1:10 -P -overwrite_original *.jpg
# Retrieve original file number (e.g. IMG_007.jpg from the FileNumber exif field and use as filename
exiftool '-filename<$FileNumber.%e' *.jpg
# FFMPEG
# Combine image files as video
cat *.jpg | ffmpeg -f image2pipe -r 24 -vcodec mjpeg -i - -vcodec libx264 out.mp4
# Trim video from -ss to length -t
ffmpeg -i input.mp4 -ss 00:29:21 -t 00:02:26 -async 1 -c copy output.mp4
# convert .mov from fcpx into much smaller mp4
ffmpeg -i input.mov -c:v libx264 -c:a aac -strict experimental output.mp4
# YOUTUBE-DL
# Download with subtitles
youtube-dl url -o output.mp4 --write-sub
# Download audio only from
youtube-dl -f 'bestaudio[ext=m4a]' 'http://youtu.be/videoid'
# GHOSTSCRIPT
# Convert all text to curves in PDF
gs -o file-with-outlines.pdf -dNoOutputFonts -sDEVICE=pdfwrite input-file.pdf
# MKGMAP
# Combine multiple img files into one
java -jar mkgmap.jar --gmapsupp a.img b.img c.img typ.TYP
# MP3INFO
# Print mp3 file names with track lengths of files in current folder
mp3info -p "%f: %m:%02s\n" *.mp3
# Print the total length of all mp3 files in a folder (in minutes)
# (corrected version of https://superuser.com/a/947201)
for file in *.mp3; do mp3info -p "%S\n" "$file"; done | paste -sd+ - | sed 's+\(.*\)+(\1)/60+' | bc
# in hh:mm:ss format (https://stackoverflow.com/a/54541337)
for file in *.mp3; do mp3info -p "%S\n" "$file"; done | paste -sd+ - | bc | dc -e '?1~r60~r60~r[[0]P]szn[:]ndZ2>zn[:]ndZ2>zn[[.]n]sad0=ap'
# FLUIDSYNTH
# Convert a folder of midis to wav using a soundfont
for filename in ./*.mid; do
fluidsynth -F "$(basename "$filename" .mid).wav" soundfont.sf2 "$filename"
done
# ZIP
# remove mac-related files from zip archives
zip -d filename.zip __MACOSX/\* \*/.DS_Store
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment