Skip to content

Instantly share code, notes, and snippets.

@discarn8
Last active January 6, 2024 22:10
Show Gist options
  • Save discarn8/87d1e115bd90120a2c0b692a336deac0 to your computer and use it in GitHub Desktop.
Save discarn8/87d1e115bd90120a2c0b692a336deac0 to your computer and use it in GitHub Desktop.
Bash One-line-lovelies
# Remove blank lines from a text file
sed -i '/^$/d' file.txt
# Delete line 7000 with sed
sed -i '7000d' file.txt
# Replace 'Earth' with 'Globe' "globally"
sed -i 's/Earth/Globe/g' file.txt
# Replace 'Earth' with 'Globe' "globally" in multiple files
for i in `ls *.txt`; do sed -i 's/Earth/Globe/g' $i; done
# Replace drive in fstab using sed
sed -i 's/^acme_prod_vfiler:\/vol\/prod_dmzdrive/#acme_prod_vfiler:\/vol\/prod_dmzdrive/g' fstab
# Remove everything before the "=" and replace it with blank
sed -i 's/.*\=//g' file.txt
# Replace a set of characters between a-e & A-E with _
sed 's/[A-Ea-e]/_/g' file.txt
# Replace every occurrence of 'hello' with 'world' on lines 10-20 and write the output to a new file
sed '10,20s/hello/world/' input.txt > output.txt
# Rename a list of files in a directory / Replace text. Here: "OLDTEXT - " is removed from all filenames
for i in *; do mv "$i" "`echo $i | sed "s/OLDTEXT - //"`"; done
# Replace a character globally in a list of filenames. Here: "_" is replaced with " " if it exists in the filename
for i in *.zip; do if [[ "$i" == *"_"* ]];then mv "$i" "`echo $i | sed "s/_/ /g"`"; fi; done
# Show deleted files in /tmp still in use
lsof /tmp | grep "(deleted)$" | sed -re 's/^\S+\s+(\S+)\s+\S+\s+([0-9]+).*/\1\/fd\/\2/' | while read file; do sudo bash -c ": > /proc/$file"; done
# SunOS Compatible grep showing 1 line before and 2 lines after the results found for "text"
nslookup hostname | nawk 'c-->0;$0~s{if(b)for(c=b+1;c>1;c--)print r[(NR-c+1)%b];print;c=a}b{r[NR%b]=$0}' b=1 a=2 s="Text"
# ksh: Find all files that are ksh type and then grep them for text, case insensitive and show line number
find . -type f -iname "*.ksh" -exec grep -i -n "text" {} +
# exiftool: Extract lat and long from *.MOV but combines them, separated by a comma
exiftool -n -ee sample.MOV | egrep -E 'GPS Latitude|GPS Longitude' | awk -F": " '{print $2}' | sed ':a;N;$!ba;s/\n-/,-/g' > sample.MOV.GPS.txt
# exiftool: Recurse and extract GPS dater from *.MOV files into *.txt file with summary text file [converted.txt]
D=$PWD;echo "Starting Directory: $D"; while IFS= read -r -d '' file; do echo "Processing $file" >> "$D/converted.txt"; sleep 1; exiftool -n -ee $file | egrep -E 'GPS Latitude|GPS Longitude' | awk -F": " '{print $2}' > "${file%.*}_GPS.txt"; echo "${file%.*}_GPS.txt"; done < <(find $D -maxdepth 10 -type f -name "*.MOV" -print0)
# ffmpeg: Convert a directory of images to mp4
ffmpeg -i image%d.jpg output.mp4
# ffmpeg: Use this command to make simple edits to your video without re-encoding. In this command you are saying,
# use the ffmpeg CLI (ffmpeg) and seek forward five seconds into the video clip (--s 00:00:05) called input.mp4.
# From there, move forward 10 seconds (-t 00:00:10) and extract the video from the start to endpoint.
# If you don't put the endpoint with the -t flag, then the video before the start point is cut off, and the rest of
# the video is included. The rest of the script looks familiar by now - it's just like the changing the container script.
# You're going to copy the video and audio codecs from the input video to your video excerpt, then output your new
# video into a file called excerpt.mp4. You can do light editing this way.
ffmpeg -ss 00:00:05 -i input.mp4 -t 00:00:10 -c:v copy -c:a copy excerpt.mp4
# ffmpeg: Create a list of mp4 files to merge
for f in *.mp4 ; do echo file \'$f\' >> list; done
# ffmpeg: Combine those files into a single new mp4
ffmpeg -f concat -safe 0 -i list -c copy mergedVideo.mp4
# ffmpeg: Re-encode mp4 as h.265
ffmpeg -i "input.mp4" -strict -2 -c:v libx265 -crf 28 -c:a aac -b:a 256k "input_h265.mp4"
# ffmpeg: Adjust mp3 volume
ffmpeg -i input.mp3 -af 'volume=0.5' output.mp3
# ffmpeg: resample flac to mp3
for x in *.flac; do ffmpeg -nostdin -i "$x" -vn -ab 320k -ar 48000 -y "${x%.*}.mp3"; done
# ffmpeg: convert VP9 webm to h265 mkv
ffmpeg -i source.webm -c:v libx265 -x265-params "level=5.2:colorprim=bt2020:colormatrix=bt2020nc:transfer=smpte2084" -crf 12 -preset medium -c:a copy output.mkv
[some files may require '-strict -2 ']
ffmpeg -i source.webm -c:v libx265 -x265-params "level=5.2:colorprim=bt2020:colormatrix=bt2020nc:transfer=smpte2084" -crf 12 -preset medium -strict -2 -c:a copy output.mkv
# ffprobe:file: Loop through a folder of filenames to determine which are VP9 encoded - echo only these files
SAVEIFS=$IFS;IFS=$(echo -en "\n\b");for i in $(file -N -i -- $(ls) | sed -n 's!: video/[^:]*$!!p' | sed 's/.\///g'); do ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 "$i" | if grep -qi vp9; then echo "$i"; fi; done; IFS=$SAVEIFS
# file:ffprobe : ffmpeg Find all VP9 video files in a folder and convert them to h265 mp4 [requires h265 compiled ffmpeg]
SAVEIFS=$IFS;IFS=$(echo -en "\n\b");for i in $(file -N -i -- $(ls) | sed -n 's!: video/[^:]*$!!p' | sed 's/.\///g'); do ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 "$i" | if grep -qi vp9; then ffmpeg -i "$i" -c:v libx265 -x265-params "level=5.2:colorprim=bt2020:colormatrix=bt2020nc:transfer=smpte2084" -crf 12 -preset medium -strict -2 -c:a copy "${i%.*}.mp4"; fi; done; IFS=$SAVEIFS
# Start with the smallest files first
SAVEIFS=$IFS;IFS=$(echo -en "\n\b");for i in $(file -N -i -- $(ls -Sr) | sed -n 's!: video/[^:]*$!!p' | sed 's/.\///g'); do ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 "$i" | if grep -qi vp9; then ffmpeg -i "$i" -c:v libx265 -x265-params "level=5.2:colorprim=bt2020:colormatrix=bt2020nc:transfer=smpte2084" -crf 12 -preset medium -strict -2 -c:a copy "${i%.*}.mp4"; fi; done; IFS=$SAVEIFS
# ffmpeg: Cat a file of VP9 files [VP9] and convert them to h265 mp4 [requires h265 compiled ffmpeg]
SAVEIFS=$IFS; IFS=$(echo -en "\n\b"); for i in $(cat VP9); do ffmpeg -i "$i" -c:v libx265 -x265-params "level=5.2:colorprim=bt2020:colormatrix=bt2020nc:transfer=smpte2084" -crf 12 -preset medium -strict -2 -c:a copy "${i%.*}.mp4"; done; IFS=$SAVEIFS
# find: Find all FOLDERS named batch but exclude the /users, /nfs, and /logs folders
find / -name *batch* -type d -not \( -name .users -o -name .nfs -o -name .logs -prune \)
find . -type d \( -path dir1 -o -path dir2 -o -path dir3 \) -prune -false -o -name '*.txt'
# find: Find all files of type: video
find . -maxdepth 1 -type f -exec file -N -i -- {} + | sed -n 's!: video/[^:]*$!!p' | sed 's/.\///g'
# audio
find . -maxdepth 1 -type f -exec file -N -i -- {} + | sed -n 's!: audio/[^:]*$!!p' | sed 's/.\///g'
# text
find . -maxdepth 1 -type f -exec file -N -i -- {} + | sed -n 's!: text/[^:]*$!!p' | sed 's/.\///g'
# image
find . -maxdepth 1 -type f -exec file -N -i -- {} + | sed -n 's!: image/[^:]*$!!p' | sed 's/.\///g'
# find: Find all files older than 90 days and delete them
find . \( ! -name . -prune \) -mtime +90 -print -exec /bin/rm {} \;
# find:rename: Find and rename all folders
find . -maxdepth 15 -type d -iname "Unwanted - *" -execdir rename 's/Unwanted - //' '{}' \+
# find: Find all files since Mar 01, 2021 that contain the partial IP of 11.22.33.
find . -maxdepth 1 -type f -newermt "01 MAR 2021" -print0 | xargs -0 grep "11.22.33."
# find: Finding largest file recursively. One can only list files and skip the directories with the find command
# instead of using the du + sort + NA command combination:
find / -type f -printf "%s\t%p\n" | sort -n | tail -1
find $HOME -type f -printf '%s %p\n' | sort -nr | head -10
# crontab: find - Crontab find tar files 5 folders deep, older than 10 days and remove them, every midnight
0 0 * * * /usr/bin/find / -maxdepth 5 -type f -name '*.tar.gz' -mtime +10 -exec rm {} \;
# find:
find /var -xdev -printf '%h\n' | sort | uniq -c | sort -k 1 -n
# find: Find all files over 100M in /var/logs folder
find /var/logs -type f -xdev -size +10000k -exec ls -lh {} \; 2>/dev/null
# find: Find all text files in a folder and print them out, pausing, separated by 2 lines
find . -type f -iname "*.txt" -exec echo {} \; -exec cat {} \; -exec echo -e "\n\n" \; | more
# find: Add all files in a directory that are not empty, to a zip file
find . -type f -name '*.csv' -size +0c -exec /opt/java9/bin/jar -cvfM ${zipfile_name}.zip {} +
# find: Return the file paths of all *.log files that have a line that begins with: ERROR
find . -name "*.log" -exec egrep -l '^ERROR' {} \;
# find: Find all files that are txt files
find . -type f -name '*.txt' -exec egrep -l pattern {} \;
# Move a specific line of text [line 7777] within a file to a specific line [1st line]
printf '7777m0\nw\n' | ed editme.txt
printf '%s\n' '7000m0' 'wq' | ed -s editme.txt
# COPY a specific line to a line, within a file
printf '7000t0\nw\n' | ed editme.txt
# truncate: clear a log file in use
truncate -s 0 varlog/firewall.log
# ip: If netstat is unavailable, query the ip to get the gateway
/sbin/ip route | awk '/default/ { print $3 }'
# SAN: Get the SAN port channel WORLD WIDE NAME [WWN]
cat /sys/class/fc_host/host*/port_name
# time: Show time it takes to run a command [list files in /var/log and show the count]
time ls -ltr /var/log |wc -l
# xpstopdf: Convert XPS to PDF at 300DPI
for doc in *.xps; do xpstopdf -r 300 $doc; done
# find: Find each subdirectory in /var/, find each file contained within and return a word count
for i in /var/*; do echo $i; find $i | wc -l; done
# meminfo: Show total system memory in single digit
printf %.0f $(grep MemTotal /proc/meminfo | awk '{print $2/1000000}')
echo "$(printf %.0f $(grep MemTotal /proc/meminfo | awk '{print $2/1000000}'))Gb"
# swap: Show swap file size
echo "$(printf %.0f $(grep swapfile /proc/swaps | awk '{print $3/1000024}'))Gb"
# zcat: Find failed or a user's failed SSH attempt in archived SSH logs
zcat /var/log/secure-*.gz | grep sshd | grep userid
zcat /var/log/secure-*.gz | grep sshd | grep failure
# ssh: Show successful ssh logins current and archived
grep -i sshd /var/log/secure* | grep -i accepted | awk '{print $9}' | sort | uniq
zcat /var/log/secure* | grep -i sshd | grep -i accepted | awk '{print $9}' | sort | uniq
# mount: Show age [in number of days] for a specific mount
cat /proc/self/mountstats | grep -A4 NFS | grep -i age: | awk -F":" '{print ($2/86400) " days"}'
# mount: Show the actual day / date a mount was mounted
echo $(date -d "$date -$(cat /proc/self/mountstats | grep -A4 NFS | grep -i age: | awk -F":" '{print ($2/86400)}' | awk '{print int($1+0.5) "days"}')" +"%Y%m%d")
# ssh: Loop through a list of hosts, ssh into them and run a script on them
for host in $(cat server.list); do ssh -o ConnectTimeout=5 -o BatchMode=yes root@$host exec bash < do_stuff.sh &; done
# dsp: piping the microphone from one machine to the speakers of another via ssh:
dd if=/dev/dsp | ssh -C user@host dd of=/dev/dsp
# cipher:ssh What cipher(s) is your ssh set to allow?
sshd -T | grep cipher
# tar:ssh Copy /tmp/folder to /tmp/folder on a remote system. Creating the destination folder is unnecessary. (bash)
tar cvf - /tmp/folder | ssh remotehost "tar xvf - -C /"
# tcpdump: Get Cisco switch config, i.e.: switch, blade, port and vlan - To look at an interface in any recent version of RHEL, you use tcpdump and look for a specific message from the Cisco switch. The switch sends a message to each connected port every so often, showing you its current configuration. That will allow you to tell if the port you’re looking at is configured the way you think it is.
# In the example below, we’re looking at interface em3:
tcpdump -i em3 -c1 -vv ether[20:2] == 0x2000
# swap: Find the top 3 "swap hogs"
for file in /proc/*/status ; do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done | sort -k 2 -n -r |head -n 3
# lpq: Look for IP/hostname in CUPS print queue
lpoptions -p <print_queue_name> | awk '{for (i=1; i<=NF; i++) {if ($i ~ /device-uri/) {print $i}}}'
# ping: Ping a list of hosts and report if each is up or down
for printer in $(cat pri.txt); do ping -c 5 $printer > /dev/null && echo $printer "up" || echo $printer "down"; done
# vm:memory:awk When adding memory to a VM but it shows offline
for i in grep line /sys/devices/system/memory/*/state |grep offline |awk -F/ '{print $6}'^Jdo^Jecho online >/sys/devices/system/memory/$i/state^Jdone
# pbis:PCI Get the PBIS version, Mode and Site - good for PCI audits
pbis status | egrep 'Compiled daemon version:|Site:|Mode' | egrep -v ' Site:| Mode:'
# Notepad++: Find all white spaces, empty lines, etc. using RegEx Search and Replace
(\r\n|\r|\n)(\s*(\r\n|\r|\n))+
# dpk: Find Kernel packages
dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d'
# Find Kernel packages and delete old ones
dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge
# curl:ilo Check ILO version remotely
curl -ks http://i$server/xmldata?item=All | grep -i "<PN>"
# ssh: Loop through a hostlist and gather RHEL Release
for server in $(cat hostlist)^Jdo^Jecho $server^Jecho $server>>HOST_RELEASE^Jssh $server "echo $HOSTNAME; cat /etc/redhat-release" >>HOST_RELEASE^Jdone
# ssh: Loop through a hostlist and stop then disable a service
for server in $(cat hostlist)^Jdo^Jecho $server^Jecho $server>>HOSTS_DISABLED^Jssh $server "systemctl stop service; systemctl disable service" >> HOSTS_DISABLED^Jdone
# ssh: Loop through a hostlist and uninstall a package
for server in $(cat hostlist)^Jdo^Jecho $server^Jecho $server>>PACKAGE_REMOVED^Jssh $server "yum remove package -y" >> PACKAGE_REMOVED^Jdone
# ssh: Loop through a hostlist and gather the McAfee Version
for server in $(cat hostlist)^Jdo^Jecho $server^Jecho $server>>MCAFEE_VER^Jssh $server "/opt/McAfee/agent/bin/cmdagent -i | grep Version | grep -v Epo" >> MCAFEE_VER^Jdone
# HP-UX: System stats / Machine Info - Good for PCI Audits
# HP-UX:Get CPU Info
/usr/contrib/bin/machinfo | awk ' { if($0 ~ /Hz/) { print $0 } }' | sed -e 's/Intel(R)//g' -e 's/Itanium(R)//g' -e 's/Processor//g'
# HP-UX:Machine SN
/usr/contrib/bin/machinfo | grep -i "machine serial" | awk '{print $4}'
# HP-UX:Processor
/usr/contrib/bin/machinfo | awk '{ if ($0 ~ /Processor/) { printf("%s %s\n", $3, $4) } }'
# HP-UX:Software ID
/opt/ignite/bin/print_manifest -s | grep "Software ID" | awk '{print $3}'
# HP-UX:Model #
/opt/ignite/bin/print_manifest -s | grep "Model" | awk '{ if ($0 ~/ia64/ ) { print $0 } else {print $NF} }'
# HP-UX:Memory
/opt/ignite/bin/print_manifest -s | awk '/Main Memory/ {printf "%.0f GB\n",$3/1024}'
# HP-UX: Processors
/opt/ignite/bin/print_manifest -s | awk '/Processors/ {print $2}'
# HP-UX: Network Info / Hostname
nslookup $(hostname) | grep Address | tail -1 | awk '{print $2}'
# HP-UX: Services listening
ifconfig $(netstat -rn | grep $(nslookup $(hostname) | grep Address | tail -1 | awk '{print $2}') | awk '{print $5}' | uniq) | grep inet | awk '{print $4}'
# HP-UX: Swapinfo
swapinfo | awk '/dev/ {total+=$2}; END {printf "%0.f GB\n", total/(1024*1024)}'
# HP-UX: Software
swlist > /tmp/swlist.out; cat /tmp/swlist.out
# HP-UX: Systen Serial
( echo "selclass qualifier system;info;wait;infolog" | /usr/sbin/cstm ) | grep -i "System serial" | awk '{print $4}'
# HP-UX: Network
lanscan -p | while read lan ; do ifconfig lan${lan}; done 2>/dev/null | grep inet | grep -v "127.0.0.1" | awk '{print($2)}' | cut -d ':' -f 2 | xargs -L 1 host | grep arpa | awk -F . '{split ($6,a," "); print a[5] " - " $4 "." $3 "." $2 "." $1}'
# SunOS: Global Zone info
if [ `zonename` == "global" ] ; then prtdiag |grep 'System' | sed 's/System Configuration://' | sed 's/Sun Microsystems//' ; fi
# SunOS: Global Zone System info
if [ `zonename` == "global" ] ; then prtdiag -v |egrep 'Intel|SPARC' | head -5 | grep -v '^System' | awk -F" " ' { if ($0 ~ /SPARC/) { printf("%s\n",$4) } else { printf("%s %s\n",$2,$4)} } ' | uniq ; fi
# SunOS: Network info
netstat -rn | grep $(nslookup `hostname` | grep Address | tail -1 | awk '{print $2}') | awk '{print $6}' | uniq | xargs ifconfig | grep netmask | awk '{print $4}'
# SunOS: Release Info
echo "`head -1 /etc/release |sed -e 's/HW //g' |awk -F/ '{print $2}' |awk '{print $2}'`(`head -1 /etc/release |awk -F/ '{print $1}' |awk '{print $NF}'`/`head -1 /etc/release |awk -F/ '{print $2}' |awk '{print $1}'`).`uname -v`"
# Check returned value and display status
retVal=$?; if [ $retVal -ne 0 ]; then echo "Error"; fi ; exit; $retVal
# while-do:Looks for the input from the COUNTER command. I.e.: "counter 10" will count for 10 minutes
#takes the input and multiplies it times 60
#while the value of COUNTER is not 0, do the next command
#echo the value of COUNTER + seconds left
#sleep for 1 second
#Take the value of COUNTER and reduce it by 1
COUNTER=$1; COUNTER=$(( COUNTER * 60 )); while [ $COUNTER -gt 0 ]do; echo $COUNTER seconds left; sleep 1; COUNTER=$(( COUNTER -1 )); done
# create file - verify success
touch /test 2> /dev/null; if [ $? -eq 0 ]; then echo "Successfully created file"; else echo "Could not create file" >&2; fi
# while-do: Misc echo and ping
while sleep 1; do echo `date`; ps aux |grep -v grep | grep -v housekeeper | grep --color -E 'syncer|items'; echo; done
while sleep 1; do echo `date`; ps aux |grep -v grep | grep -v housekeeper | grep --color -E 'syncer|ipmi|vmware'; echo; done
while sleep 1; do echo `date`; ping -c 5 1.1.1.1 | grep -v grep | grep --color -E 'packet loss'; echo ; done
# Release: Get the release, Major and Minor and Async
full=`cat /etc/centos-release | tr -dc '0-9.'`; major=$(cat /etc/*release | tr -dc '0-9.'|cut -d \. -f1); minor=$(cat /etc/*release | tr -dc '0-9.'|cut -d \. -f2); asynchronous=$(cat /etc/*release | tr -dc '0-9.'|cut -d \. -f3); echo CentOS Version: $full; echo Major Release: $major; echo Minor Release: $minor; echo Asynchronous Release: $asynchronous
# SunOS:Perl Inline search and replace
perl -pi -e 's/search/replace/g' file.name
# cut: Get Debian version
cut -d"." -f1 /etc/debian_version
# if:Vormetric Check for ver RHEL6 or RHEL7 then check for status of Vormetric
if grep -q -i "release 6" /etc/redhat-release; then chkconfig --list |grep secfs | sed "s/^/`hostname` /"; else systemctl list-unit-files |grep vmd.service | sed "s/^/`hostname` /"; fi
# telnet: Check for open NFS
echo -e '\035\nquit' | timeout 12 telnet remote_host 2049 && echo "success" || echo "failed"
# ping:nslookup Nslookup a range of /23 IPs against a specified DNS server [172.168.0.2]
for x in {0..10}; do for y in {1..255}; do nslookup 192.168.$x.$y 172.168.0.2 2> /dev/null | egrep -v 'REFUSED|NXDOMAIN' | grep -v '^$' | awk -F"name = " '{print "192.168.'$x'.'$y' = " $2}'; done; done
# ffprobe: get the Video Codec for a directory of mp4 videos
for i in *.mp4; do echo -n "$i = "; ffprobe -v error -show_format -show_streams "$i" | grep -m 1 codec_long_name; done
# for loop: find all zip files in a directory and then unzip them to their own folder and then remove the source zip
for file in *.zip; do unzip "${file}" -d "${file%%.zip}" && rm "${file}"; done
# grep:awk:sum Find every line with a dollar amount, awk that out and then sum all amounts
grep \\$ list | grep -v FREE | awk -F"\$" '{print $2}' | awk '{ SUM += $1} END { print SUM }'
# wget:grep : sed wget a news feed and format it to one-line headlines or output to a text file or db for ingestion elsewhere
wget -q -O- "https://linux.com/feed/" | sed 's/<\/h6> /.../g; s/ <a href/<a href/g; s/\&nbsp;/ /g; s/\&#39;//g;s/&hellip;/...more/g'| grep -Po '<title>.*?</title>' | sed 's/<title>//g;s/<\/title>//g'| sed '/</ {:k s/<[^>]*>//g; /</ {N; bk}}' | sed -e 's/^/[*] /'| awk NF
wget -q -O- "https://www.baynews9.com/services/contentfeed.fl%7ctampa.hero.rss" | sed 's/<\/h6> /.../g; s/ <a href/<a href/g; s/\&nbsp;/ /g; s/\&#39;//g;s/&hellip;/...more/g'| grep -Po '<title>.*?</title>'| sed '/</ {:k s/<[^>]*>//g; /</ {N; bk}}' | sed -e 's/^/[*] /'| awk NF
wget -q -O- "https://linux.slashdot.org/" | sed 's/&lt;/</g; s/&gt;/>/g; s/&quot;/\"/g' | grep "story-title"| awk -v FS="(\">|<)" '{print $5}'
wget -q -O- "https://www.reutersagency.com/feed/?best-regions=north-america&post_type=best" | sed 's/<\/h6> /.../g; s/ <a href/<a href/g; s/\&nbsp;/ /g; s/\&#39;//g;s/&hellip;/...more/g' | xargs | grep -Po "<title>\K(.*?)</title>" | sed "s/..title.//g" | sed 's/^.* [Rr]eveals//' | sed "s/..title.//g" | grep -iv "News Agency" | sed -e 's/^/[*]/'
# awk:sed:netstat Show the ESTABLISHED connections to your Linux host
netstat -tn | grep ESTABLISHED | awk '{print $4 " " $5}' | awk -F":| " '{print $2 "," $3 "," $4}' | sed -e $'1i\\\nFROM,TO,PORT'
<!-- /////////////////////////////////////////////////////////////////////////// -->
Ok - not a one-liner, but good
------------------
vi .bashrc
------------------
[ADD]
dmesg_with_human_timestamps () {
FORMAT="%a %b %d %H:%M:%S %Y"
now=$(date +%s)
cputime_line=$(grep -m1 "\.clock" /proc/sched_debug)
if [[ $cputime_line =~ [^0-9]*([0-9]*).* ]]; then
cputime=$((BASH_REMATCH[1] / 1000))
fi
dmesg | while IFS= read -r line; do
if [[ $line =~ ^\[\ *([0-9]+)\.[0-9]+\]\ (.*) ]]; then
stamp=$((now-cputime+BASH_REMATCH[1]))
echo "[$(date +"${FORMAT}" --date=@${stamp})] ${BASH_REMATCH[2]}"
else
echo "$line"
fi
done
}
alias dmesgt=dmesg_with_human_timestamps
------------------
source .bashrc
------------------
[enjoy human readable time/date stamps in your dmesg output]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment