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 Wav to Mp3
for i in *.wav; do ffmpeg -i "$i" -acodec mp3 -ab 320k "$i".mp3 ; done
Convert to 16 bits Flac
for i in *.flac; do ffmpeg -i "$i" -af aresample=dither_method=triangular -sample_fmt s16 -ar 44100 "$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 and .mov videos in a folder
Note: this will exclude videos already compressed (named with '_compressed.mp4')
find . \( -iname "*.mp4" -or -iname "*.mov" \) -and ! -name "*_compressed.mp4" -print0 | while read -d $'\0' file; do ffmpeg -i "$file" -vcodec libx265 -crf 28 "${file%.*}_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=/ebook \ -dNOPAUSE -dQUIET -dBATCH -dDetectDuplicateImages \ -dCompressFonts=true -r150 -sOutputFile=output.pdf input.pdf
Summary of -dPDFSETTINGS:
dPDFSETTINGS=/screen
lower quality, smaller size. (72 dpi)dPDFSETTINGS=/ebook
for better quality, but slightly larger pdfs. (150 dpi)dPDFSETTINGS=/prepress
output similar to Acrobat Distiller "Prepress Optimized" setting (300 dpi)dPDFSETTINGS=/printer
selects output similar to the Acrobat Distiller "Print Optimized" setting (300 dpi)dPDFSETTINGS=/default
selects output intended to be useful across a wide variety of uses, possibly at the expense of a larger output file
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 = 5x60 = (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
Fail2ban
Get SSH banned IP
fail2ban-client status sshd
Nginx
GoAccess - Log statistics (terminal)
- Live statistics
tail -f access.log | goaccess -
- Using single log file
goaccess access.log
- Using all log files (including .gz files)
zcat -f access.log* | goaccess -
- Date ranges
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
Hotlink
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:'
Synology
Edit Synology IP Block list
Remove an IP address in case your IP address has been blocked by DSM firewall (Error message "IP Address blocked due to too many failed login attempts")
Login to your NAS using SSH with an admin group account
ssh user@192.168.x.x -p port_number
Once connected, get the root rights entering your password
sudo -i
Now remove the blocker IP address from the database
cd /etc sqlite3 synoautoblock.db sqlite> delete from AutoBlockIP where IP ="x.x.x.x";
Nice projects
- Raspberry Pi : https://www.raspberrypi.org/ - Tiny computer
- Pi-Hole : https://pi-hole.net - Ad blocking using DNS - With DNSCrypt-Proxy
- Firefox : https://www.mozilla.org/en-US/firefox/new/ - The Web Browser
- Bitwarden : https://bitwarden.com/open-source/ - Password manager
- MoodeAudio : http://www.moodeaudio.org/ - Audiophile-quality music playback
- HifiBerry : https://www.hifiberry.com/ - Audio additional boards for Rpi
- OpenHAB : https://www.openhab.org/ - Smart Home
- Home Assistant : https://www.home-assistant.io/ - Open source home automation
- DD-WRT : https://dd-wrt.com/ - Free your router
- Ubuntu : https://ubuntu.com/ - Linux distribution
- Shelly : https://www.shelly.com/en-fr - Smart Home Automation
- Nicotine+ : https://nicotine-plus.org/ - Soulseek is not dead
- Kodi : https://kodi.tv/ - Media Centre
- NGINX : https://www.nginx.com/ - Web Server
- Amplify : https://amplify.nginx.com - Web Server Monitoring
- VideoLAN : https://www.videolan.org/ - Powerful media player
- Waze : https://www.waze.com/ - GPS