Commands by emphazer (25)

  • Fast and simple awk urldecoder! Note: Parameter -n is specific to GNU awk Show Sample Output


    2
    awk -niord '{printf RT?$0chr("0x"substr(RT,2)):$0}' RS=%..
    emphazer · 2023-03-30 15:05:58 319
  • Explanation Firstly the function checks if user gave it any input, and notifies the user if they failed to do so. If user has inputed a search string, the function will call upon youtube-dl to find url of the audio of the first matching youtube video and play that with mpv. Call function by wrapping search string in quotes: listen-to-yt "sultans of swing" You have to paste the line in your .zshrc and source .zshrc for it to work. Limitations The dependancies are youtube-dl and mpv. this oneliner is stolen from http://www.bashoneliners.com/oneliners/302/


    1
    listen-to-yt() { if [[ -z "$1" ]]; then echo "Enter a search string!"; else mpv "$(youtube-dl --default-search 'ytsearch1:' \"$1\" --get-url | tail -1)"; fi }
    emphazer · 2019-12-18 14:22:12 76
  • google has added 2 more netblocks... Show Sample Output


    4
    for NETBLOCK in $(echo _netblocks.google.com _netblocks2.google.com _netblocks3.google.com); do nslookup -q=TXT $NETBLOCK ; done | tr " " "\n" | grep ^ip[46]: | cut -d: -f2- | sort
    emphazer · 2019-12-16 07:09:12 288

  • 0
    seq 1 9 | perl -MList::Util=shuffle -e 'print shuffle <>;'
    emphazer · 2019-07-03 09:39:08 38
  • blktrace is a block layer IO tracing mechanism which provide detailed information about request queue operations up to user space. blkparse will combine streams of events for various devices on various CPUs, and produce a formatted output the the event information. It take the output of above tool blktrace and convert those information into fency readable form. Show Sample Output


    1
    sudo blktrace -d /dev/sda -o - | blkparse -i -
    emphazer · 2019-07-02 06:13:58 39

  • 7
    for i in {1..65535}; do (echo < /dev/tcp/127.0.0.1/$i) &>/dev/null && printf "\n[+] Open Port at\n: \t%d\n" "$i" || printf "."; done
    emphazer · 2019-05-21 09:34:15 51

  • 7
    curl -s https://ipvigilante.com/$(curl -s https://ipinfo.io/ip) | jq '.data.latitude, .data.longitude, .data.city_name, .data.country_name'
    emphazer · 2019-04-26 09:15:00 48

  • 1
    curl -s https://ip-ranges.amazonaws.com/ip-ranges.json | awk -F'"' '/ipv6_prefix/ {print $4}'
    emphazer · 2018-10-05 13:01:03 392

  • 1
    curl -s https://ip-ranges.amazonaws.com/ip-ranges.json | awk -F'"' '/ip_prefix/ {print $4}'
    emphazer · 2018-10-05 12:59:33 376

  • 2
    nslookup -q=TXT _netblocks.google.com | grep -Po '\b([0-1]?\d{1,2}|2[0-4]\d|25[0-5])(\.([0-1]?\d{1,2}|2[0-4]\d|25[0-5])){3}(/\d{1,2})\b'
    emphazer · 2018-10-05 12:50:48 390
  • requires imagemagick. -background transparent is of course optional. Show Sample Output


    1
    convert -background transparent input.png -define icon:auto-resize=16,32,48,64,128 favicon.ico
    emphazer · 2018-09-27 13:12:03 351
  • wget http://nginx.org/download/nginx-1.15.3.tar.gz && tar -xzf 1.15.3.tar.gz && cd nginx-1.15.3 Show Sample Output


    1
    ./configure --help | grep -P "^ +--with-(?!(poll|select))[^=]+(_module( |$)| (module|support)$)" | sed -r 's/((dis|en)able|build) /# /'
    emphazer · 2018-09-14 12:54:06 355
  • opposite of https://www.commandlinefu.com/commands/view/10014/urldecoding-with-one-pure-bash-builtin ;-) Show Sample Output


    2
    function URLEncode { local dataLength="${#1}"; local index; for ((index = 0;index < dataLength;index++)); do local char="${1:index:1}"; case $char in [a-zA-Z0-9.~_-]) printf "$char"; ;; *) printf "%%%02X" "'$char"; ;; esac; done; }
    emphazer · 2018-09-14 12:08:10 366
  • sleep in microseconds instead of seconds Alternatively to usleep, which is not defined in POSIX 2008 (though it was defined up to POSIX 2004, and it is evidently available on Linux and other platforms with a history of POSIX compliance), the POSIX 2008 standard defines nanosleep Show Sample Output


    1
    time usleep 100000
    emphazer · 2018-09-06 10:28:26 338
  • Binding a server to privileged port on Linux w/o running as root This is applicable to any service using privileged ports (< 1024), for instance to run a HTTP server on port 80 or a LDAP directory server on port 389 for example. Show Sample Output


    4
    sudo setcap CAP_NET_BIND_SERVICE=+eip /usr/bin/python2.7
    emphazer · 2018-09-04 17:30:47 333

  • 0
    mknod -m 0666 /dev/null c 1 3
    emphazer · 2018-08-16 12:10:16 327
  • https://stackoverflow.com/questions/10768160/ip-address-converter Show Sample Output


    1
    awk {'print rshift(and($1, 0xFF000000), 24) "." rshift(and($1, 0x00FF0000), 16) "." rshift(and($1, 0x0000FF00), 8) "." and($1, 0x000000FF)'}
    emphazer · 2018-08-16 11:46:26 362
  • (echo "https://example.com/"; echo "https://example.com/"; echo "https://example.com/"; echo "https://example.com/") | parallel -k 'ab -n 10000 -c 15 {}'


    0
    cat url_list.txt | parallel -k 'ab -n 10000 -c 15 {}'
    emphazer · 2018-05-17 11:23:28 210
  • # 4 cores with 2500 pi digits CPUBENCH 4 2500 . every core will use 100% cpu and you can see how fast they calculate it. if you do 50000 digitits and more it can take hours or days Show Sample Output


    1
    CPUBENCH() { local CPU="${1:-1}"; local SCALE="${2:-5000}"; { for LOOP in `seq 1 $CPU`; do { time echo "scale=${SCALE}; 4*a(1)" | bc -l -q | grep -v ^"[0-9]" & } ; done }; echo "Cores: $CPU"; echo "Digit: $SCALE" ;}
    emphazer · 2018-05-14 17:30:37 200

  • 2
    find /var/www/ -type f -name '*.[jJ][pP][gG]' -print0 | xargs -n 1 -P 8 -0 jpegoptim --strip-all --preserve --preserve-perms --quiet
    emphazer · 2018-05-14 16:39:21 168

  • 1
    find /var/www/ -type f -name '*.[pP][nN][gG]' -print0 | xargs -L 1 -n 1 -P 8 -0 optipng -preserve -quiet -o7 -f4 -strip all
    emphazer · 2018-05-14 16:38:11 165
  • Explanation It creates dnsmasq-com-blackhole.conf file with one line to route all domains of com zones to 0.0.0.0 You might use "address=/home.lab/127.0.0.1" to point allpossiblesubdomains.home.lab to your localhost or some other IP in a cloud. Show Sample Output


    1
    echo "address=/com/0.0.0.0" | sudo tee /etc/dnsmasq.d/dnsmasq-com-blackhole.conf && sudo systemctl restart dnsmasq
    emphazer · 2018-05-14 16:28:18 166
  • a quick function for searching changed files. just copy it in the bash Show Sample Output


    0
    FINDDATE() { LOCATION="${1:-.}"; find ${LOCATION} -type f -print0 | xargs -0 stat -c "%y %n" | sort | sed 's/.\([0-9]\)\{9,\} +0[1-2]00/\t/' | sed 's/ /\t/g' }
    emphazer · 2018-05-14 14:27:41 166
  • Check whether hyperthreading is enabled or not. a better solution as nproc should work on all OS with awk Show Sample Output


    2
    awk -F: '/^core id/ && !P[$2] { CORES++; P[$2]=1 }; /^physical id/ && !N[$2] { CPUs++; N[$2]=1 }; END { print CPUs*CORES }' /proc/cpuinfo
    emphazer · 2018-05-14 14:17:33 163
  • this is good for variables if you have many script created files and if you want to know which one is the last created/changed one..


    1
    find . -type f -print0 | xargs -0 stat -c '%y %n' | sort -n -k 1,1 | awk 'END{print $NF}'
    emphazer · 2018-05-14 08:47:41 162

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands


Check These Out

Rename files in batch

Count git commits since specific commit

Detect illegal access to kernel space, potentially useful for Meltdown detection
Based on capsule8 agent examples, not rigorously tested

get a list of top 1000 sites from alexa
a little bit smarter & i only want .de domains, so .....

list block devices
Shows all block devices in a tree with descruptions of what they are.

Get memory total from /proc/meminfo in Gigs

Calculates the number of physical cores considering HyperThreading in AWK
Check whether hyperthreading is enabled or not. a better solution as nproc should work on all OS with awk

output your microphone to a remote computer's speaker
This will output the sound from your microphone port to the ssh target computer's speaker port. The sound quality is very bad, so you will hear a lot of hissing.

Convert PDF to JPG
Without the bashisms and unnecessary sed dependency. Substitutions quoted so that filenames with whitespace will be handled correctly.

Get a list of IP Addresses that have failed to login via SSH
This command shows a sorted list of the IP addresses from which there have been authentication errors via SSH (possible script kiddies trying to gain access to your server), it eliminates duplicates so it's easier to read, but you can remove the "uniq" command at the end, or even do a "uniq -c" to have a count of how many times each IP address shows in the log (the path to the log may vary from system to system)


Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: