Linux commandline tips 4

From www.ReeltoReel.nl Wiki
Revision as of 08:41, 25 December 2018 by Pvdm (talk | contribs)
Jump to navigation Jump to search

watch if a website changes:

while :;do curl -Ls "X\.com"|md5sum;sleep 5m;done|awk '{if(NR>1&&l!=$1){system("echo the site changed|mail -s NOTIFY you@isp\.net");};l=$1}'

scan pdf to file. first extract the pages and ocr them, then make one doc

pdfimages -tiff input.pdf plaatje
for i in *.tif; do tesseract $i tempje-$i; done
cat tempje-plaatje-0*.txt >> docje.txt

ps ax -o state -o ppid | awk '$1=="Z"{print $2}' | xargs kill -9 # Kill all #zombies on the system.

ps aux |tail -n+2 |sort -nrk4 |head -$(($(tput lines)-1)) |cut -c 1-$(tput cols) # Display top RAM using processes.

ethtool -p eth0 # Blink eth0's LED so you can find it in the rat's next of server cables. Ctrl-C to stop.

find . -xdev -ls | sort -n -k 7 | tail -5 # Quickly find the largest 5 files in the CWD tree without crossing filesystem boundaries.

for f in *; do b=$(echo "$f" | tr '[A-Z]' '[a-z]'); mv "$f" "$b"; done # Lower case all files in a folder.

rpm -qf $( which lspci ) # Pass the output of which (showing path to lspci) into rpm's -qf, which tells you the pkg.

rename -v 's/^([0-9])_/0\1_/' *.flac # Rename all single leading digit flac files so that they have a padding 0 for easier sorting.

ps aux | awk '{if ($8=="Z") { print $2 }}'# On Linux, print out a list of the process IDs that are in the zombie state.

exiv2 -k -F rename *.jpg # Use the exiv2 EXIF program to rename your jpg files according to their exif date/time data.

curl http://wttr.in/castricum # see weatherforecast

finger amsterdam@graph.no

rpm -qa --queryformat "%{NAME} %{INSTALLTIME:date}\n" | grep "Nov 2015" # In RPM, determine which packages where installed in Nov 2015.

echo "wall \"hallo\""| at 11:48 2016-02-27 # execute a command at a certain time and date

ls -la "$(find . -type f -printf '%T@ %p\n' | sort -n | tail -1 | cut -f2- -d" ")" # show the most recent file in subtree

grep -Ev "((accept|drop|reject)log|ftpd)" /var/log/messages | less # Yes! You can do nested grouping in extended regexes.

With Bash history, `^str1^str2^` will repeat the previous command replacing `str1` by `str2`, so

echo 1223
^2^4^

The #Bash has the notion of "integer" variable:

declare A=1; declare -i B=2
A+=3; B+=4
echo $A $B
⇒ 13 6


sort -t, -k5nr data.csv | less # Sort data.csv by the 5th column's numeric values in descending order.

Play a sound if you get an unsuccessful return code from last command.

PROMPT_COMMAND='[ $? -ne 0 ] && play -qn synth sin G3 trim 0 0.1'

Command used by P2V process:

tar --one-file-system --sparse -C / -cf - .

Show error warn and criticals in color:

# tail -f "foo.log"|egrep --line-buffered --color=auto 'ERROR|WARN|CRITICAL$

Very good overview of open ports and their programs:

# lsof -Pan -i tcp -i udp