
Terminal - Commands using printf - 166 results
set-proxy () { P=webproxy:1234; DU="fred"; read -p "username[$DU]:" USER; printf "%b"; UN=${USER:-$DU}; read -s -p "password:" PASS; printf "%b" "\n"; export http_proxy="http://${UN}:${PASS}@$P/"; export ftp_proxy="http://${UN}:${PASS}@$P/"; }
This is sample output - yours may be different.
[[email protected] ~]$ set-proxy
username[fred]: bob
password:
[[email protected] ~]$ wget google.co.uk
--13:05:20-- http://google.co.uk/
=> `index.html'
Resolving webproxy... 192.168.1.3
Connecting to webproxy|192.168.1.3|:1234... connected.
Proxy request sent, awaiting response... 200 OK
Length: unspecified [text/html]
13:05:20 (50.33 KB/s) - `index.html' saved [7381]
Prompts the user for username and password, that are then exported to http_proxy for use by wget, yum etc
Default user, webproxy and port are used.
Using this script prevent the cleartext user and pass being in your bash_history and on-screen
This is sample output - yours may be different.
This is sample output - yours may be different.
$ time printf "%50s\n"|tr \ -
--------------------------------------------------
real 0m0.008s
user 0m0.000s
sys 0m0.008s
Better -and faster- using bash printf.
This is sample output - yours may be different.
Replace 70 with the desired height.
Replace 180 with the desired width.
I put it in my bashrc, because by default my terminal is too small.
p(){ printf "\033[%d;%dH\033[4%dm \033[m" $((RANDOM%LINES+1)) $((RANDOM%COLUMNS+1)) $((RANDOM%8)); }; clear;while :;do p; sleep .001;done
This is sample output - yours may be different.
COL=$(( $(tput cols) / 2 )); clear; tput setaf 2; while :; do tput cup $((RANDOM%COL)) $((RANDOM%COL)); printf "%$((RANDOM%COL))s" $((RANDOM%2)); done
This is sample output - yours may be different.
printf "%s\n" !(pattern) ## ksh, or bash with shopt -s extglob
This is sample output - yours may be different.
There's no need for ls or grep; printf is builtin to most modern shells
printf $(echo -n $1 | sed 's/\\/\\\\/g;s/\(%\)\([0-9a-fA-F][0-9a-fA-F]\)/\\x\2/g')
This is sample output - yours may be different.
Hello%20World
gives
Hello World
\unescaped!
gives
\unescaped!
My version uses printf and command substitution ($()) instead of echo -e and xargs, this is a few less chars, but not real substantive difference.
Also supports lowercase hex letters and a backslash (\) will make it through unescaped
This is sample output - yours may be different.
In most modern shells, printf is a builtin command.
printf "%s\n" ${PATH//:/\/* }
This is sample output - yours may be different.
This is sample output - yours may be different.
cat *.c | { printf "se te du\nplot '-' t '' w dots\n"; tr '[[:upper:]]' '[[:lower:]]' | tr -s [[:punct:][:space:]] '\n' | sort | uniq -c | sort -nr | head -n 100 | awk '{print $1}END{print "e"}'; } | gnuplot
This is sample output - yours may be different.
$ cat *.c | { printf "se te du\nplot '-' t '' w dots\n"; tr '[[:upper:]]' '[[:lower:]]' | tr -s [[:punct:][:space:]] '\n' | sort | uniq -c | sort -nr | head -n 100 | awk '{print $1}END{print "e"}'; } | gnuplot
60 .+-----+------+------+------+-------+------+------+------+------+-----++
+ + + + + + + + + + +
| |
50 ++ ++
| |
|. |
|. |
40 ++ ++
| |
| .. |
30 ++ ++
| . |
| |
20 ++ .. ++
| .. |
| .. |
| ... |
10 ++ .... ++
| ............... |
+ + + + + .......................................+
0 ++-----+------+------+------+-------+------+------+------+------+-----++
0 10 20 30 40 50 60 70 80 90 100
Uses the dumb terminal option in gnuplot to plot a graph of frequencies. In this case, we are looking at a frequency analysis of words in all of the .c files.
export I=$(date +%s); watch -t -n 1 'T=$(date +%s);E=$(($T-$I));hours=$((E / 3600)) ; seconds=$((E % 3600)) ; minutes=$((seconds / 60)) ; seconds=$((seconds % 60)) ; echo $(printf "%02d:%02d:%02d" $hours $minutes $seconds) | toilet -f shadow'
This is sample output - yours may be different.
_ \ _ \ ___ \ ___ / | | ___|
| | | | _) ) | _ \ _) | | __ \
| | | | __/ ) | ___ __| ) |
\___/ \___/ _) _____| ____/ _) _| ____/
already described on the other two versions, this one uses ascii characters on game style to display elapsed time.
export I=$(date +%s); watch -t -n 1 'T=$(date +%s);E=$(($T-$I));hours=$((E / 3600)) ; seconds=$((E % 3600)) ; minutes=$((seconds / 60)) ; seconds=$((seconds % 60)) ; echo $(printf "%02d:%02d:%02d" $hours $minutes $seconds) | osd_cat -o 20 -d 1 -p bottom'
This is sample output - yours may be different.
Variation of the theme, this one blinks in low profile on top level of X, ie, it is visible, indeed small.
Try changing fonts and sizes of osd_cat
export I=$(date +%s); watch -t -n 1 'T=$(date +%s);E=$(($T-$I));hours=$((E / 3600)) ; seconds=$((E % 3600)) ; minutes=$((seconds / 60)) ; seconds=$((seconds % 60)) ; echo $(printf "%02d:%02d:%02d" $hours $minutes $seconds)'
This is sample output - yours may be different.
Works on real time clock, unix time based, decrementing the actual time from initial time saved in an environment variable exported to child process inside watch
Shows elapsed time from start of script in hh:mm:ss format
Non afected by system slow down due to the use of date.
ord() { printf "%d\n" "'$1"; }
This is sample output - yours may be different.
printf treats first char after single ' as numeric equivalent
This is sample output - yours may be different.
chr() { printf \\$(printf %o $1); }
This is sample output - yours may be different.
chr () { printf \\$(($1/64*100+$1%64/8*10+$1%8)); }
This is sample output - yours may be different.
I've corrected the function. My octal conversion formula was completely wrong. Thanks to pgas at http://mywiki.wooledge.org/BashFAQ/071 for setting me straight. The new function is from pgas and is very fast.
(printf "PERMISSIONS LINKS OWNER GROUP SIZE MONTH DAY HH:MM PROG-NAME\n" \ ; ls -l | sed 1d) | column -t
This is sample output - yours may be different.
PERMISSIONS LINKS OWNER GROUP SIZE MONTH DAY HH:MM PROG-NAME
-rw-r--r-- 1 root root 61167 12. Nov 2008 120253snmp.log
-rw-r--r-- 1 root root 246313 6. M?r 2008 120_43.log
-rw-r--r-- 1 root root 22947 14. Mai 09:42 120discovery.log
Using column to format a directory listing
cat file.txt | while read line; do printf "%7.2f -> %7.2f\n" $line; done
This is sample output - yours may be different.
find -type f -name "*.avi" -print0 | xargs -0 mplayer -vo dummy -ao dummy -identify 2>/dev/null | perl -nle '/ID_LENGTH=([0-9\.]+)/ && ($t +=$1) && printf "%02d:%02d:%02d\n",$t/3600,$t/60%60,$t%60' | tail -n 1
This is sample output - yours may be different.
change the *.avi to whatever you want to match, you can remove it altogether if you want to check all files.
printf "%02u " {3..20}; echo
This is sample output - yours may be different.
03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20
emulates bash4's "echo {03..20}"
Uses bash3 builtin function printf
yes "$(seq 1 255)" | while read i; do printf "\x1b[48;5;${i}m\n"; sleep .01; done
This is sample output - yours may be different.
Rainbow, instead of greys
printf '%*s\n' 20 | tr ' ' '#'
This is sample output - yours may be different.