rss logo

My few useful GNU/Linux commands

Here are a few commands that I've found useful.

System

  • Find out which MTA is behind sendmail:
user@host:~$ ls -al /usr/sbin/sendmail
  • Find out which MTA is behind sendmail (alternative):
user@host:~$ ls -al `which sendmail`
  • Modify a user account:
root@host:~# usermod -g GROUP -d USER_DIRECTORY -s USER_SHELL
  • Connect to a Windows Server and share a local directory with rdesktop or freerdp:
user@host:~$ rdesktop 192.168.1.200 -g1900x1024 -u domain\\administrator -p password -r disk:docs=/share -0 -r sound:remote user@host:~$ xfreerdp /v:192.168.1.200 /w:1900 /h:1024 /u:"administrator" /p:"password" /cert-ignore /drive:share,/share /audio-mode:1
  • rsync 30 large files at random via ssh:
user@host:~$ for i in:~$(find /data/videos/ -size +1200M | grep -v "Name.That.I.Dont.Share" | sed "s/\s/__@__/g" | sort -R | head -n 30); do b=$(echo "$i" | sed 's/__@__/\ /g'); rsync -av "$b" root@host:/var/www/www.shebangthedolphins.net/shebangflix/; done
  • Displays a list of the most recently logged-in users:
user@host:~$ last
  • Displays a list of failed connection attempts:
user@host:~$ lastb
  • Show available shells:
user@host:~$ cat /etc/shells
  • Delete .cache files older than one year:
user@host:~$ find ~/.cache -type f -mtime +365 -delete

Debian/Ubuntu

  • Display Debian version:
user@host:~$ lsb_release -ds
  • On Debian, look for a filename in the installed packages:
user@host:~$ dpkg -S courier-imap
  • On Debian, list the files installed on your system by package name:
user@host:~$ dpkg -L courier-imap
  • On Debian, backup through ssh with tar and lzip:
root@host:~# apt-get install lzip; tar --lzip -cvf - /my/fodler/ | ssh root@10.0.0.124 "cat > /backup/$(date +%Y.%m.%d)backup.tar.lz"

Hardware

  • Get hardware informations:
root@host:~# dmidecode -t chassis -t system root@host:~# lshw

Multimedia

  • Search and randomly play all audio and video files in a directory with vlc:
user@host:~$ find /tmp/ppp/ -type f | sed "s/\\s/\\\ /g" | sed "s/\x27/\\\&/g" | sort -R | xargs -t vlc
  • Search and randomly play all audio and video files in a directory with vlc at a specific time:
user@host:~$ echo export DISPLAY=$DISPLAY \&\& 'find /mon/dossier/audios/ou/videos -type f | sed "s/\\s/\\\ /g" | sed "s/\x27/\\\&/g" | sort -R | xargs -t vlc' | at 7h50
  • Search and randomly play all audio and video files from a given period in a directory with vlc:
user@host:~$ touch --date=20150601 /tmp/begin; touch --date=20151231 /tmp/end; find /musics/ -newer /tmp/begin -not -newer /tmp/end -type f | sed "s/\\s/\\\ /g" | sed "s/\x27/\\\&/g" | sort -R | xargs -t vlc
  • Search and randomly play all audio and video files from a given period in a directory with vlc (alternative with the newermt parameter):
user@host:~$ find /musics/ -newermt 20150601 -not -newermt 20151231 -type f | sed "s/\\s/\\\ /g" | sed "s/\x27/\\\&/g" | sort -R | xargs -t vlc
  • Automatic volume up/down in audio files (here with ogg files):
user@host:~$ for i in *ogg; do a=$(ffmpeg -i "$i" -af volumedetect -f null - 2>&1| grep "max_volume:" | cut -d " " -f 5 | sed 's/-//'); i="${i%.ogg}"; ffmpeg -i "$i".ogg -af volume="$a"dB "$i"INCREASED.ogg; done
  • Convert an ogg audio file to mp3 with ffmpeg:
user@host:~$ for i in *ogg; do a="${i%.ogg}"; ffmpeg -i "$i" -aq 1 "$a".mp3; done
  • Automatically rename ogg files to yyyy.mm.dd_hh.mm.ss.jpg (requires mediainfo to run):
user@host:~$ mkdir NEW; for i in *.ogg; do new=$(mediainfo -f "$i" | grep "File last modification date (local)" | tr -s " " | cut -d " " -f 7,8 | tr "-" "." | tr " " "_" | tr -d ":" | sed 's/$/.ogg/'); cp -a "$i" NEW/"$new"; done

Network

  • Display current public IP address:
user@host:~$ host myip.opendns.com resolver1.opendns.com user@host:~$ dig TXT +short o-o.myaddr.l.google.com @ns1.google.com
  • Display network usage information (group bandwidth per process):
root@host:~# nethogs
  • Display sessions opened by a process:
root@host:~# lsof -i -p <pid-proc>

Misc

  • Ask your GNU/Linux for lottery numbers (never worked for me…):
user@host:~$ i=0; while [ "$i" -ne 5 ] ; do test=$RANDOM; let 'test %= 50'; echo "$test"; let i="$i"+1; done ; test=$RANDOM;let 'test %= 11';echo "$test"
  • Use the terminal as a calculator:
user@host:~$ let "i = 360 / 12"; echo:~$i
  • Use the terminal as a calculator with a precision of two decimal places:
user@host:~$ echo "scale=2; 23 / 7" | bc
  • Display raw characters in a file:
user@host:~$ cat file | od -c

Pictures

  • Export image thumbnails with exiftool:
user@host:~$ exiftool -b -ThumbnailImage IMG_0605.jpg > thumbnail.jpg
  • Automatically rename images files to yyyy.mm.dd_hh.mm.ss.jpg (requires imagemagick to run):
user@host:~$ mkdir NEW; for i in *.jpg; do new=$(identify -format %[exif:*] "$i" | grep DateTimeDigitized | sed 's/=/ /' | cut -d " " -f 2,3 | tr ":" "." | tr " " "_"| sed 's/$/.jpg/'); cp -a "$i" NEW/"$new"; done
Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Contact :

contact mail address