How-tos (Some useful Linux tips)

Convert all wav files to flac files in a folder

for i in *.wav; do ffmpeg -i "$i" "$i".flac ; done
for i in *.wav; do ffmpeg -i "$i" -acodec mp3 -ab 320k "$i".mp3 ; done
 
for i in *.flac; do ffmpeg -i "$i" -af aresample=dither_method=triangular -sample_fmt s16 -ar 44100 "$i".flac ; done
for f in *.flac; do flac -cd "$f" | lame -b 320 - "${f%.*}".mp3; done

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
sudo apt install libheif-examples
for file in *.heic; do heif-convert "$file" "${file/%.heic/.jpg}"; done
totem "$(ls -R | shuf -n1)"
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

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
# remove lrc files
find -type f -name "*.lrc" -delete
# remove .DS_Store files
find -type f -name ".DS_Store" -delete
fdupes -rdN .
tar -zxvf file.tar.gz
tar -xvjf file.tar.bz2 
find . -type d -delete
find . -iname "*.mp3" -print
curl -4 -o /dev/null http://bouygues.testdebit.info/100M.iso
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
host myip.opendns.com resolver1.opendns.com
sudo netstat -antp
who
sudo slay user_name
sudo ufw status verbose
sudo iftop -i enp9s0
ssh user@host -XC application
ftpasswd --passwd --name=bob --uid=1001 --home=/home/bob --shell=/bin/false
ncftp -u username -p apssword ftp://ftpperso.free.fr/dir/
sudo ncftpput -R -u username ftpperso.free.fr / /dir_to_copy/*
sudo lshw | more
sudo dmidecode
sudo lscpu
upower -i /org/freedesktop/UPower/devices/battery_BAT0
wavemon
sudo glances --enable-plugin sensors
cpufreq-info
sudo journalctl --since "2023-01-01" | grep temperature
sudo powertop
sudo chkrootkit
sudo gt5
//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
sudo smartctl -A /dev/sda
sudo hdparm -y /dev/sdb
sudo hdparm -C /dev/sdb
sudo hdparm -B /dev/sdb

60 = 5x60 = (5 minutes)

sudo hdparm -B60 /dev/sdb

Install cifs/nfs

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

Get SSH banned IP

fail2ban-client status sshd
  • 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 access.log -o /var/www/html/report.html --log-format=COMBINED --real-time-html
awk '{print $9}' access.log | sort | uniq -c | sort -rn
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
awk '/Jan\/2024/ {print $1};' access.log | sort | uniq -c | sort -rn | head -20
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
sudo /usr/bin/mysql_secure_installation
sudo mysql -uroot -p
GRANT LOCK TABLES, SELECT, RELOAD ON *.* TO 'backup'@'localhost' IDENTIFIED BY 'PASSWORD';
/etc/mysql/conf.d/mysqldump.cnf
mysql -p -u root
 
CREATE DATABASE db_name;
 
GRANT ALL PRIVILEGES ON db_name.* TO 'db_user'@'localhost'
IDENTIFIED BY 'password' WITH GRANT OPTION;
mysql -p -u root -D db_name
SHOW TABLES ;

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

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 }
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
pihole -up

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:'

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";
  • wiki/user/jean/ubuntu_tips.txt
  • Dernière modification : 21/12/2024 15:57
  • de jean