Commands tagged printf (41)

  • 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 323

  • 2
    printf '*%.s' {1..40}; echo
    metropolis · 2019-07-01 07:41:18 48

  • 1
    ls -d $PWD/*
    putnamhill · 2011-12-16 19:12:55 3
  • DOCKER_APP_VARS=(DATABASE_USER=dbuserro, DATABASE_PASSWORD=maipass) [jeff@omniscience container] (master)$ echo docker run $(printf -- " -e %s" ${DOCKER_APP_VARS[*]}) -name 12factorapp mattdm/fedora-small docker run -e DATABASE_USER=dbuserro, -e DATABASE_PASSWORD=maipass -name 12factorapp mattdm/fedora-small Note that the printf method by itsself doesn't include a newline (\n), so you'll need to embed it into an echo statement or something that does. Show Sample Output


    1
    printf -- " -e %s" ${ARRAY[*]}
    SEJeff · 2014-02-25 03:34:12 7
  • Find biggest files in a directory Show Sample Output


    1
    find . -printf '%.5m %10M %#9u %-9g %TY-%Tm-%Td+%Tr [%Y] %s %p\n'|sort -nrk8|head
    AskApache · 2014-12-10 23:48:20 9
  • I created this command to give me a quick overview of how many file types a directory, and all its subdirectories, contains. It works based off file extension, rather than file(1)'s magic output, because it ended up being more accurate and less confusing. Files that don't have an ext (README) are generally not important for me to want to count, but you're free to customize this fit your needs. Show Sample Output


    0
    printf "\n%25s%10sTOTAL\n" 'FILE TYPE' ' '; for ext in $(find . -iname \*.* | egrep -o '\.[^[:space:].]+$' | egrep -v '\.svn*' | sort -f | uniq -i); do count=$(find . -iname \*$ext | wc -l); printf "%25s%10s%d\n" $ext ' ' $count; done
    rkulla · 2010-04-16 21:12:11 3
  • function for .bash_aliases that prints a line of the character of your choice in the color of your choice across the terminal. Default character is "=", default color is white.


    0
    println() {echo -n -e "\e[038;05;${2:-255}m";printf "%$(tput cols)s"|sed "s/ /${1:-=}/g"}
    joedhon · 2011-01-09 18:08:18 3
  • Way more easy to understand for naive user. Just returns the biggest file with size.


    0
    find . -printf '%s %p\n'|sort -nr| head -1
    ranjha · 2014-12-14 15:40:56 8

  • 0
    du -k . | sort -rn | head -11
    b0wlninja · 2014-12-29 17:12:25 8
  • Basically, \033[ is a semi-portable unix escape character. It should work in linux, osx, bsd, etc. The first option is 38. This tells whatever is interpreting this (and this is merely convention) that a special color sequence follows. The next option is 5 which says that the next option will specify a color ? {0..256} of course. These options, as you can see, are separated by a single `;` and the entire escape sequence is followed by a mandatory `m`. The second escape sequence (following "COLOR") is simply to clear all terminal attributes (for our purposes, it clears color). This for loop is helpful for testing all 256 colors in a 256 console (note: this will not work in a standard Linux tty console) or to see which number corresponds to which color so that perhaps you can use it! Show Sample Output


    0
    for i in {0..256}; do echo -e "${i} \033[38;05;${i}m COLOR \033[0m"; done
    Benharper · 2015-12-17 23:49:42 12
  • Compactly display a bitcoin-cli fee estimate in satoshis/Byte, sat/B, date time stamp. Change the 6 to the desired number of confirmations. Display in btc/KB unit of measure: printf %g "$(bccli estimatesmartfee 6 "ECONOMICAL" | jq .feerate)";printf " btc/KB estimated feerate for 6 confirmations\nMultiply by 100,000 to get sat/B\n"; Two settings for estimate mode are "ECONOMICAL". "CONSERVATIVE" is the same as "UNSET" # jq is a json filter. sudo apt-get install jq Show Sample Output


    0
    printf %g "$(bitcoin-cli estimatesmartfee 6 "ECONOMICAL" | jq .feerate*100000)";printf " sat/B estimated feerate for 6 confirmations as of $(date +%c)\nDivide by 100,000 to get btc/KB\n"
    deinerson1 · 2018-06-20 13:40:32 208
  • This shell calculator uses POSIX features only and is therefore portable. By default the number of significant figures is limited to 8 with trailing zeros stripped, resembling the display of a basic pocket calculator. You might want to increase this to 12 to emulate a scientific calculator. Show Sample Output


    0
    calc(){ printf "%.8g\n" $(printf "%s\n" "$*" | bc -l); }
    lordtoran · 2019-02-06 23:32:35 601
  • No need to fork off a process.


    0
    printf "%.s*" {1..40}; printf "\n"
    doododoltala · 2019-07-11 00:27:20 37
  • For BSD-based systems, including OS X, that don't have seq. This version provides a default using tput in case $COLUMNS is not set: jot -b '#' -s '' ${COLUMNS:-$(tput cols)} Show Sample Output


    -1
    jot -b '#' -s '' $COLUMNS
    dennisw · 2010-04-13 22:03:39 6
  • This is longer than others on here. The reason for this is I have combined two different matrix commands so it would work on all computers. I logged onto my server through a computer and it worked fine. I logged into my server through a mac and it looked $4!t so I have made one that works through both. Show Sample Output


    -1
    echo -e "CHECK=SAMPLE" output --command_to_long
    techie · 2013-04-03 08:46:47 10
  • I find the other timers are inaccurate. It takes some microseconds to perform the date function. Therefore, using date/time math to calculate the time for us results in millisecond accuracy. This is tailored to the BusyBox date function. May need to change things around for GNU date function. Show Sample Output


    -1
    let T=$(date +%s)+3*60;while [ $(date +%s) -le $T ]; do let i=$T-$(date +%s); echo -ne "\r$(date -d"0:0:$i" +%H:%M:%S)"; sleep 0.3; done
    davidk · 2019-10-22 15:04:21 129
  •  < 1 2

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

Which processes are listening on a specific port (e.g. port 80)
swap out "80" for your port of interest. Can use port number or named ports e.g. "http"

Rename files in batch

Download an Entire website with wget

Set laptop display brightness
Run as root. Path may vary depending on laptop model and video card (this was tested on an Acer laptop with ATI HD3200 video). $ cat /proc/acpi/video/VGA/LCD/brightness to discover the possible values for your display.

Get AWS temporary credentials ready to export based on a MFA virtual appliance
You might want to secure your AWS operations requiring to use a MFA token. But then to use API or tools, you need to pass credentials generated with a MFA token. This commands asks you for the MFA code and retrieves these credentials using AWS Cli. To print the exports, you can use: `awk '{ print "export AWS_ACCESS_KEY_ID=\"" $1 "\"\n" "export AWS_SECRET_ACCESS_KEY=\"" $2 "\"\n" "export AWS_SESSION_TOKEN=\"" $3 "\"" }'` You must adapt the command line to include: * $MFA_IDis ARN of the virtual MFA or serial number of the physical one * TTL for the credentials

a short counter
Maybe you know shorter ?

Log colorizer for OSX (ccze alternative)
Download colorizer by @raszi @ http://github.com/raszi/colorize

add all files not under version control to repository
This should handle whitespaces well and will not get confused if your filenames have "?" in them

back ssh from firewalled hosts
host B (you) redirects a modem port (62220) to his local ssh. host A is a remote machine (the ones that issues the ssh cmd). once connected port 5497 is in listening mode on host B. host B just do a ssh 127.0.0.1 -p 5497 -l user and reaches the remote host'ssh. This can be used also for vnc and so on.

Happy Days
AFAIR this is the wording ;)


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: