Table des matières

How-tos (Some useful Linux tips)

Multimedias - Conversions

Convert Wav to Flac

Convert all wav files to flac files in a folder

for i in *.wav; do ffmpeg -i "$i" "$i".flac ; done

Convert Flac to Mp3 files

for f in *.flac; do flac -cd "$f" | lame -b 320 - "${f%.*}".mp3; done

Compress all mp4 videos in a folder

for i in *.mp4; do ffmpeg -i "$i" -vcodec libx265 -crf 28 "${i%.*}_compressed.mp4"; done

Compress all mov videos in a folder

for i in *.mov; do ffmpeg -i "$i" -vcodec libx265 -crf 28 "${i%.*}_compressed.mp4"; done

Convert HEIC images to jpg

sudo apt install libheif-examples
for file in *.heic; do heif-convert "$file" "${file/%.heic/.jpg}"; done

Pick a random file with Totem

totem "$(ls -R | shuf -n1)"

Compress PDF files

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/default \
    -dNOPAUSE -dQUIET -dBATCH -dDetectDuplicateImages \
    -dCompressFonts=true -r150 -sOutputFile=output.pdf input.pdf

If Totem can't read some mkv or mp4 vidéo

After upgrading to Ubuntu 22.04 I had some issue to read some video files (Totem crash at startup, display the error “The specified movie could not be found” or open the video with a strange format. I did install the Intel non-free drivers to solve this issue:

sudo apt install intel-media-va-driver-non-free ubuntu-restricted-extras

Files

Remove files recursively

# remove lrc files
find -type f -name "*.lrc" -delete
# remove .DS_Store files
find -type f -name ".DS_Store" -delete

Remove duplicate files

fdupes -rdN .

Uncompress .tar.gz file

tar -zxvf file.tar.gz

Uncompress .tar.bz2 file

tar -xvjf file.tar.bz2 

Remove empty folders

find . -type d -delete

Search .Mp3 files

find . -iname "*.mp3" -print

Network

Download test

curl -4 -o /dev/null http://bouygues.testdebit.info/100M.iso

Upload test

curl -o /tmp/temp.iso https://bouygues.testdebit.info/100M.iso
curl -4 -o /dev/null -F "filecontent=@/tmp/temp.iso" http://bouygues.testdebit.info

Display public IP address

host myip.opendns.com resolver1.opendns.com

Open ports connexions

sudo netstat -antp

Connected users list

who

Disconnect a user

sudo slay user_name

Firewall - Status

sudo ufw status verbose

Trafic - bandwidth utilisation

sudo iftop -i enp9s0

SSH - Launch X application over SSH

ssh user@host -XC application

FTP - Add user

ftpasswd --passwd --name=bob --uid=1001 --home=/home/bob --shell=/bin/false

NcFTP - connection

ncftp -u username -p apssword ftp://ftpperso.free.fr/dir/

NcFTP - folder copy

sudo ncftpput -R -u username ftpperso.free.fr / /dir_to_copy/*

Hardware

Component list

sudo lshw | more

Getting SMBIOS data from sysfs

sudo dmidecode

CPU information

sudo lscpu

Battery information

upower -i /org/freedesktop/UPower/devices/battery_BAT0

Check Wifi signal

wavemon

System

Monitor

sudo glances --enable-plugin sensors

CPU frequency

cpufreq-info

CPU Over temperatures Log occurrences

sudo journalctl --since "2023-01-01" | grep temperature

Power Usage

sudo powertop

Security: detect signs of rootkits

sudo chkrootkit

Hard-drive

Folders/files usage

sudo gt5

Disk - Free space on /boot partition

//check current kernel
uname -r
//check if list of old kernels is correct 
dpkg -l linux-{image,headers}-"[0-9]*" | awk '/^ii/{ print $2}' | grep -v -e `uname -r | cut -f1,2 -d"-"` | grep -e '[0-9]'
//purge old kernels
dpkg -l linux-{image,headers}-"[0-9]*" | awk '/^ii/{ print $2}' | grep -v -e `uname -r | cut -f1,2 -d"-"` | grep -e '[0-9]' | xargs sudo apt-get -y purge

SMART information

sudo smartctl -A /dev/sda

Set HD to low power consumption standby mode

sudo hdparm -y /dev/sdb

Hard drive current state

sudo hdparm -C /dev/sdb

Hard drive current Advanced Power Management (APM) value

sudo hdparm -B /dev/sdb

Change APM value

60 = 5×60 = (5 minutes)

sudo hdparm -B60 /dev/sdb

Fstab

Install cifs/nfs

sudo apt install nfs-common
sudo apt install cifs-utils

Install DCP-7055W scan driver

brsaneconfig4 -a name=(name your device) model=(model name) ip=xx.xx.xx.xx

https://support.brother.com/g/b/downloadhowto.aspx?c=us_ot&lang=en&prod=dcp7055w_us_eu_as&os=128&dlid=dlf006645_000&flang=4&type3=566

Fail2ban

Get SSH banned IP

fail2ban-client status sshd

Nginx

GoAccess - Log statistics (terminal)

tail -f access.log | goaccess -
goaccess access.log
zcat -f access.log* | goaccess -
sed -n '/'$(date '+%d\/%b\/%Y' -d 'last week')'/,$ p' access.log | goaccess -a -
sed -n '/'$(date '+%d\/%b\/%Y' -d 'last month')'/,$ p' access.log | goaccess -a - 
sed -n '/'$(date '+%d\/%b\/%Y' -d '1 month ago')'/,$ p' access.log | goaccess -a - 
sed -n '/'$(date '+%d\/%b\/%Y' -d '1 week ago')'/,$ p' access.log | goaccess -a - 
sed -n '/'$(date '+%d\/%b\/%Y' -d 'yesterday')'/,$ p' access.log | goaccess -a - 
sed -n '/'$(date '+%d\/%b\/%Y' -d 'today')'/,$ p' access.log | goaccess -a -

GoAccess - Log statistics (dynamic HTML page)

goaccess access.log -o /var/www/html/report.html --log-format=COMBINED --real-time-html

Count pages sorted by response code

awk '{print $9}' access.log | sort | uniq -c | sort -rn

Count 404 respond code

cd /var/log/nginx/
awk '($9 ~ /404/)' access.log | awk '{print $7}' | sort | uniq -c | sort -rn
awk -F\" '($2 ~ /\.(jpg|gif)/ && $4 !~ /^https:\/\/eolienne\.f4jr\.org/){print $4}' access.log | sort | uniq -c | sort

List of 20 most connected IP address (since a date)

awk '/Jan\/2024/ {print $1};' access.log | sort | uniq -c | sort -rn | head -20

Top 10 IP address sort by bandwidth utilization

awk 'BEGIN{ PROCINFO["sorted_in"]="@val_num_desc" }
     { a[$1]++; b[$1]+=$10 }
     END{ 
         for(i in a) { if(++c>10) break; printf "IP: %s: ",i ; system(sprintf("numfmt --to=iec-i %s",b[i])) ; } 
     }' access.log

MySQL

Secure

sudo /usr/bin/mysql_secure_installation

Create backup user

sudo mysql -uroot -p
GRANT LOCK TABLES, SELECT, RELOAD ON *.* TO 'backup'@'localhost' IDENTIFIED BY 'PASSWORD';

Password for backup

/etc/mysql/conf.d/mysqldump.cnf

Create database

mysql -p -u root
 
CREATE DATABASE db_name;
 
GRANT ALL PRIVILEGES ON db_name.* TO 'db_user'@'localhost'
IDENTIFIED BY 'password' WITH GRANT OPTION;

Connect to database

mysql -p -u root -D db_name

Show tables

SHOW TABLES ;

AirPlay

Pulse Audio

Installation of Airplay in Ubuntu 22.04 with Pulse Audio

# Airplay ability 
sudo apt install pulseaudio build-essential paprefs git pulseaudio-module-raop intltool libjack0 pavucontrol pulseaudio-module-zeroconf
 
#bug pulseaudio 
sudo ln -s /usr/lib/pulse-16.1+dfsg1/ /usr/lib/pulse-16.1
pactl load-module module-raop-discover

PipeWire

Discover Airplay in Ubuntu 22.10 with PipeWire

sudo vi /etc/pipewire/pipewire.conf

Add the following line to load module inside the context.modules = [ section

{ name = libpipewire-module-raop-discover }

HandBrake

sudo apt install libdvdnav4 libdvdread4 gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly libdvd-pkg
sudo dpkg-reconfigure libdvd-pkg
sudo apt install ubuntu-restricted-extras

Pi-hole

Upgrade

pihole -up

Gnome

Move the Dock 'Show Applications' button at top

gsettings set org.gnome.shell.extensions.dash-to-dock show-apps-at-top true

Move the windows control button to the left

gsettings set  org.gnome.desktop.wm.preferences button-layout 'close,minimize,maximize:'

Nice projects