Linux Cheat Sheet
find
Delete files that don’t have a .txt
extension:
$ find . -type f ! -name '*.pdf' -delete
Delete empty directories:
$ find . -type d -empty -delete
Find directories with “foo” in their name:
$ find . -type d -name '*foo*'
Find files with “foo” in their name:
$ find . -type f -name '*foo*'
Find files containing the text “foo”:
$ find . -type f -exec grep -l "foo" {} \;
ffmpeg
Change video speed (2.0x):
$ ffmpeg -i input.mkv -vf "setpts=(PTS-STARTPTS)/2.0" -af atempo=2.0 output.mkv
Change container from MKV to MP4:
$ ffmpeg -i input.mkv -codec copy output.mp4
Record RTSP stream w/ hardware acceleration (NVIDIA):
$ ffmpeg -rtsp_transport tcp -i rtsp://10.0.0.1/ -c:v h264_nvenc -preset fast -b:v 1000k -c:a copy output.mp4
Download a portion of a video using yt-dlp
and ffmpeg
:
$ yt-dlp --external-downloader ffmpeg --external-downloader-args "ffmpeg_i:-ss 00:01:07 -to 00:01:13" -f best https://youtu.be/LR6KIFIJwHU -o "output.mp4"
rsync
Copy an entire directory (preserving permissions, ownership, timestamps, etc.):
$ rsync -a /source/dir /destination
Sync files with progress display and compression:
$ rsync -avz --progress /source/dir/ user@remote:/destination
Mirror directories (with deletion of files that don’t exist in source):
$ rsync -avz --delete /source/dir/ /destination/
magick
Trim transparent pixels from an image:
$ convert input.png -fuzz 0% -trim +repage output.png
Convert PDF to JPG:
$ convert -density 70 -quality 100 -flatten input.pdf output.jpg
Add drop shadow:
NOTE: 20x4+0+0
is 20% opacity, 4px sigma (blur amount), 0 horizontal offset, 0 vertical offset.
$ convert input.jpg \( +clone -background black -shadow 20x4+0+0 \) +swap -background none -layers merge +repage output.png
scp
Copy file from local to remote:
$ scp file.txt user@remote:/path/to/destination/
Copy file from remote to local:
$ scp user@remote:/path/to/file.txt /local/destination/
Copy directory recursively:
$ scp -r /local/directory user@remote:/path/to/destination/
Copy with compression (faster for large files):
$ scp -C file.txt user@remote:/path/to/destination/
Copy with custom SSH port:
$ scp -P 2222 file.txt user@remote:/path/to/destination/
Copy with verbose output:
$ scp -v file.txt user@remote:/path/to/destination/
Copy preserving file attributes (timestamps, permissions):
$ scp -p file.txt user@remote:/path/to/destination/
Copy between two remote hosts:
$ scp user1@host1:/path/to/file.txt user2@host2:/path/to/destination/
Copy multiple files:
$ scp file1.txt file2.txt user@remote:/path/to/destination/
Copy with bandwidth limit (KB/s):
$ scp -l 1000 file.txt user@remote:/path/to/destination/
Copy using SSH key:
$ scp -i ~/.ssh/my_key file.txt user@remote:/path/to/destination/
Copy with custom SSH config:
$ scp -F ~/.ssh/custom_config file.txt user@remote:/path/to/destination/
yt-dlp
Download best video and audio, merge into MP4:
$ yt-dlp -f "bv*+ba/b" --merge-output-format mp4 https://youtu.be/CyngSr5svDI
Download entire playlist as MP3s:
$ yt-dlp -x --audio-format mp3 https://www.youtube.com/playlist?list=YOUR_PLAYLIST_ID
Download subtitles and embed in video:
$ yt-dlp --write-subs --write-auto-subs --sub-lang en --embed-subs https://youtu.be/CyngSr5svDI
Custom output filename and folder:
$ yt-dlp -o "%(uploader)s/%(title)s.%(ext)s" https://youtu.be/CyngSr5svDI
Download highest quality audio without format conversion:
$ yt-dlp -f bestaudio https://youtu.be/CyngSr5svDI
Download highest quality audio and convert to MP3:
$ yt-dlp -f bestaudio --extract-audio --audio-format mp3 https://youtu.be/CyngSr5svDI
Download highest quality audio and convert to Opus:
$ yt-dlp -f bestaudio --extract-audio --audio-format opus https://youtu.be/CyngSr5svDI
Download highest quality audio with custom filename:
$ yt-dlp -f bestaudio -o "%(title)s.%(ext)s" https://youtu.be/CyngSr5svDI
Download highest quality audio with metadata and thumbnail embedding:
$ yt-dlp -f bestaudio --extract-audio --audio-format mp3 --embed-thumbnail --add-metadata https://youtu.be/CyngSr5svDI