shell.md 2.4 KB

Shell

Useful common Unix commands and tricks

Link a binary in your local bin

ln -s -T ~/Software/GitAhead/GitAhead ~/.bin/gitahead

To use a physical link instead of a symlink, use -S instead of -s

Compress

sudo tar --create --gzip --file bck_var_log.tgz --verbose /var/log

Systemctl

systemctl list-units --state=failed

Merge photos from others

Let's assume different people took pictures with format like IMG_YYYYMMDD_hhmmss[suffixe].jpg e.g. IMG_20220713_210605__01.jpg.

If you want to mix photos while keeping chronological order in viewers, you have to rename them in order to sort them alphabetically by date.

Use the command below to make every file start by YYYYMMDD_hhmmss.

Metadata extraction

Replace firstname by the firstname of the person taking the picture.

exiftool -p 'mv $FileName ${CreateDate}_firstname.jpg' -d "%Y%m%d_%H%M%S" -q
 . > rename.sh
exiftool -p 'heif-convert $FileName ${CreateDate}_firstname.jpg' -d "%Y%m%d_%H%M%S" -q *.HEIC >> rename.sh

Then execute and remove rename.sh.

Exotic formats

Some phones use HEIC, that's a weird closed format. To convert them, two ways (use the one which works) :

Image magick

convert 20240816_194033.heic 20240816_194033_user.jpg

Heif converter

sudo apt install libheif-examples
heif-convert -q 85 20240816_194033.heic 20240816_194033_user.jpg

File name manipulations

On Ubuntu, you have two different utilities : rename.ul making simple replacements, and rename working with regex.

Add a name suffixe

p1.jpg -> p1_suffixe.jpg

rename.ul '.jpg' '_suffixe.jpg' *

Replace strange chars

20220711_181620~2.jpg -> 20220711_181620_2.jpg

rename.ul '~' '_' *.jpg
rename.ul ')' '' *.jpg
rename.ul '(' '_' *.jpg

Device to end

CANON_20220711_181620.jpg -> 20220711_181620_IMG_CANON.jpg

rename 's/(\w+)_(\d{8}_.*)\./$2_IMG_$1./' *.jpg

Device and type to end

CANON_IMG_20220713_210605__01.jpg -> 20220713_210605__01_IMG_CANON SAM_VID_20220713_210605__01.mp4 -> 20220713_210605__01_VID_SAM.mp4

rename 's/(\w+)_(\w{3})_(\d{8}_.*)\./$3_$2_$1/\.' *

Fix Google Pixel length

rename 's/(^PXL_.*_[0-9]{6}).*\.jpg$/$1_IMG_person.jpg/' *.jpg
rename 's/(^PXL_.*_[0-9]{6}).*\.mp4$/$1_IMG_person.mp4/' *.mp4
rename.ul -- 'PXL_' '' *

Take care, timestamp seems to be in UTC.