rss logo

Some GNU/Linux useful commands

I will put here some commands that I find usefull.

System

  • Know which MTA is hiding behind sendmail :
user@host:~$ ls -al /usr/sbin/sendmail
    • or
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 big files randomly through 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
  • Show a listing of last logged in users :
user@host:~$ last
  • Show a listing of failed logins :
user@host:~$ lastb
  • Show availables shells :
user@host:~$ cat /etc/shells
  • Remove .cache files older than one year :
user@host:~$ find ~/.cache -type f -mtime +365 -delete

Debian/Ubuntu

  • Print Debian version :
user@host:~$ lsb_release -ds
  • On Debian search for a filename from installed package :
user@host:~$ dpkg -S courier-imap
  • On Debian list files installed to your system from 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 play randomly every audio and video files from 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 play randomly every audio and video files from 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 play randomly every audio and video files from a directory with vlc from a specific period of time :
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
    • Or, if your find version is compatible with 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
  • Automaticly increase/normalize volume 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 ogg to mp3 with ffmpeg :
user@host:~$ for i in *ogg; do a="${i%.ogg}"; ffmpeg -i "$i" -aq 1 "$a".mp3; done
  • Automaticly rename ogg files with yyyy.mm.dd_hh.mm.ss.jpg format (need mediainfo program to work) :
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

  • Get 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
  • Get network usage informations (group bandwidth per process) :
root@host:~# nethogs
  • Show opened sessions by a process :
root@host:~# lsof -i -p <pid-proc>

Misc

  • Ask lottery numbers to his GNU/Linux (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 two numbers precise :
user@host:~$ echo "scale=2; 23 / 7" | bc
  • Print every characters of a file :
user@host:~$ cat file | od -c

Pictures

  • Export thumbnail from an image thanks to exiftool :
user@host:~$ exiftool -b -ThumbnailImage IMG_0605.jpg > thumbnail.jpg
  • Automaticly rename pictures files with yyyy.mm.dd_hh.mm.ss.jpg format (need imagemagick program to work) :
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