command line interface (cli) tips
A web page for gathering various tips and commands for the command line interface (cli) to share with friends, students, colleagues and collaborators.
basics
When you open the command line interface (cli) - you will likely see something like this:
[your user name]@[your machine's name] ~ %
The command line runs prompts from within a folder.
Where are you? You will likely start out in your “home” folder.
To check where you are you can try to “print working directory”:
pwd
What is in this directory?
To find out you can try “listing” what is there:
ls
Maybe there is a mix of files and folders.
You can try listing only the folders:
ls -d */
You may see a list of folders like this:
Applications/
Desktop/
Documents/
Downloads/
Library/
Movies/
Music/
Pictures/
To change into the Downloads folder, for example, you can “change directory”:
cd Downloads
cwebp
convert input.png into a compressed WebP image at quality 82, saving it as output.webp
cwebp -q 82 input.png -o output.webp
ffmpeg
extract the audio from a video input.mp4 as a 24-bit wav file, preserving original sample rate and channel configuration, and save as output.wav:
ffmpeg -i input.mp4 -vn -acodec pcm_s24le output.wav
extract the audio from a video input.mp4 as a 16-bit wav file, resampled to 48 kHz converted to stereo, and save as output.wav:
ffmpeg -i input.mp4 -vn -acodec pcm_s16le -ar 48000 -ac 2 output.wav
create a directory wav_24bit and batch extract audio from all .mp4 files in the current folder as 24-bit wav files, preserving original audio properties:
mkdir -p wav_24bit
for f in *.mp4; do
ffmpeg -i "$f" -vn -acodec pcm_s24le "wav_24bit/${f%.mp4}.wav"
done
create a directory wav_24bit and batch extract audio from all .mp4 and .mov files in the current folder as 24-bit 48kHz wav files:
mkdir -p wav_24bit
for f in *.mp4 *.mov; do
[ -f "$f" ] || continue
ext="${f##*.}"
ffmpeg -i "$f" -vn -ar 48000 -acodec pcm_s24le "wav_24bit/${f%.$ext}.wav"
done
extract 1 frame from 1 second of video input.mp4 and save image as output.png:
ffmpeg -ss 1 -i input.mp4 -vframes 1 output.png
some bash scripts for batch converting folders of sound with ffmpeg can be found here.
grep
todo
image magick
todo
man
read the manual page for ffmpeg:
man ffmpeg
moviepy
todo
nano
open a text file in nano:
nano notes.txt
yt-dlp
video
download the best quality video (H.264) and audio (M4A) from <video url> merging them into an MP4 when available, otherwise falling back to the best MP4 or best available format
yt-dlp -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best' -S vcodec:h264,res,acodec:m4a <video url>
audio
download the best available audio from a video url as a wav file with date, uploader and title in the file name:
yt-dlp -f "bestaudio" --extract-audio --audio-format wav --audio-quality 0 -o "%(upload_date)s_%(uploader)s_%(title).60s.%(ext)s" <video url>
download the best available audio from a video url as a wav file with video id in the file name:
yt-dlp -f "bestaudio" --extract-audio --audio-format wav --audio-quality 0 -o "%(id)s.%(ext)s" <video url>
download the best available audio from seconds 0-18 of a video url as a wav file with video id in the file name:
yt-dlp -f "bestaudio" \
--download-sections "*0-18" \
--extract-audio --audio-format wav --audio-quality 0 \
-o "%(id)s.%(ext)s" <video url>
download the first 10 seconds of the best available audio from video url, using node.js as the javascript runtime and cookies from chrome, saving as [video id].wav:
yt-dlp --js-runtimes node --cookies-from-browser chrome -f "bestaudio/best" --extract-audio --audio-format wav --audio-quality 0 -o "%(id)s.%(ext)s" --download-sections "*0-10" <video url>
get a wav file with the best quality audio of a list of video urls urls.txt:
yt-dlp -f "bestaudio" --extract-audio --audio-format wav --audio-quality 0 -o "%(id)s.%(ext)s" -a urls.txt
get the best available audio from a video url as an mp3:
yt-dlp -f "bestaudio" --extract-audio --audio-format mp3 --audio-quality 0 <video url>
vclip
todo
videogrep
todo
zsh
reset
source ~/.zshrc