### Commands using eval (54) the last day the last week the last month all time sorted by date votes

• This creates a permanent stock ticker in the terminal. it has scrolling action and refreshes when each cycle is done to get the latest news.

7
while true;do n="$(curl -s http://news.yahoo.com/rss/|sed 's/</\n/g'|grep "title>"|sed -e '/^\// d' -e 's/title>/---------- /g' -e '1,3d'|tr '\n' ' ')";for i in$(eval echo {0..${#n}});do echo -ne "\e[s\e[0;0H${n:$i:$COLUMNS}\e[u";sleep .15;done;done &
· 2012-11-17 23:56:17
• up 3 will climb the directory tree by three steps. up asdf will do nothing, and returns exit code 1 as an error should.

6
up() { [ $(($1 + 0 )) -gt 0 ] && cd $(eval "printf '../'%.0s {1..$1}"); }
· 2012-06-15 17:10:45
• Place the regular expression you want to validate between the forward slashes in the eval block. Show Sample Output

5
perl -we 'my $regex = eval {qr/.*/}; die "$@" if $@;' · 2009-10-13 21:50:47 • Usage: up N I did not like two things in the submitted commands and fixed it here: 1) If I do cd - afterwards, I want to go back to the directory I've been before 2) If I call up without argument, I expect to go up one level It is sad, that I need eval (at least in bash), but I think it's safe here. eval is required, because in bash brace expansion happens before variable substitution, see http://rosettacode.org/wiki/Repeat_a_string#Using_printf 5 function up { cd$(eval printf '../'%.0s {1..$1}) && pwd; } · 2013-01-21 12:57:45 • The coolest way I've found to backup a wordpress mysql database using encryption, and using local variables created directly from the wp-config.php file so that you don't have to type them- which would allow someone sniffing your terminal or viewing your shell history to see your info. I use a variation of this for my servers that have hundreds of wordpress installs and databases by using a find command for the wp-config.php file and passing that through xargs to my function. Show Sample Output 4 eval$(sed -n "s/^d[^D]*DB_$$[NUPH]$$[ASO].*',[^']*'$$[^']*$$'.*/_\1='\2'/p" wp-config.php) && mysqldump --opt --add-drop-table -u$_U -p$_P -h$_H$_N | gpg -er AskApache >date +%m%d%y-%H%M.$_N.sqls · 2009-08-18 07:03:08 • When you start screen as ssh-agent screen, agent will die after detatch. If you don't want to take care about files when stored agent's pid/socket/etc, you have to use this command. 4 eval ssh-agent; screen · 2010-03-07 14:58:54 • Set a bookmark as normal shell variable p=/cumbersome/path/to/project To go there to p This saves one "$" and is faster to type ;-) The variable is still useful as such: vim $p/<TAB> will expand the variable (at least in bash) and show a list of files to edit. If setting the bookmarks is too much typing you could add another function bm() { eval$1=$(pwd); } then bookmark the current directory with bm p 4 to() { eval dir=\$$1; cd "dir"; } · 2010-10-15 13:40:35 • It's quite easy to capture the output of a command and assign it in a shell's variable: day=(date +%d) month=(date +%m) But, what if we want to perform the same task with just one program invocation? Here comes the power of eval! date(1) outputs a string like "day=29; month=07; year=11" (notice the semicolons I added on purpose at date's custom output) which is a legal shell line. This like is then parsed and executed by the shell once again with the help of eval. Just setting 3 variables! Inspired by LinuxJournal's column "Dave Taylor's Work the Shell". Show Sample Output 4 eval (date +"day=%d; month=%m; year=%y") · 2011-07-29 12:47:26 • Looks up a word on merriam-webster.com, does a screen scrape for the FIRST audio pronunciation and plays it. USAGE: Put this one-liner into a shell script (e.g., ~/bin/pronounce) and run it from the command line giving it the word to say: pronounce lek If the word isn't found in merriam-webster, no audio is played and the script returns an error value. However, M-W is a fairly complete dictionary (better than howjsay.com which won't let you hear how to pronounce naughty words). ASSUMPTIONS: GNU's sed (which supports -r for extended regular expressions) and Linux's aplay. Aplay can be replaced by any program that can play .WAV files from stdin. KNOWN BUGS: only the FIRST pronunciation is played, which is problematic if you wanted a particular form (plural, adjectival, etc) of the word. For example, if you run this: pronounce onomatopoetic you'll hear a voice saying "onomatopoeia". Playing the correct form of the word is possible, but doing so might make the screen scraper even more fragile than it already is. (The slightest change to the format of m-w.com could break it). Show Sample Output 3 cmd=(wget -qO- "http://www.m-w.com/dictionary/(echo "@"|tr '[A-Z]' '[a-z]')" | sed -rn "s#return au$$'([^']+?)', '([^'])[^']*'$$;.*#\nwget -qO- http://cougar.eb.com/soundc11/\2/\1 | aplay -q#; s/[^\n]*\n//p"); [ "cmd" ] && eval "cmd" || exit 1 · 2010-03-12 13:56:41 • This is an alternative to another command using two xargs. If it's a command you know there's only one of, you can just use: ls -l /proc/(pgrep COMMAND)/cwd Show Sample Output 3 eval ls -l /proc/{(pgrep -d, COMMAND)}/cwd · 2011-04-14 13:41:58 • 3 clear; while sleep 1; do d=(date +"%H:%M:%S"); e=(echo "toilet -t -f mono12 d");tput setaf 1 cup 0; eval e; tput setaf 4 cup 8; eval "e -F flop";tput cup 0; done · 2015-05-03 01:51:27 • This only makes sense if you are using command line editing. Create the function in your current zsh session, then type eve PATH go 'UP' in your history and notice the current (editable) definition of PATH shows up as the previous command. Same as doing: PATH="'PATH'" but takes fewer characters and you don't have to remember the escaping. 2 function eve (); { eval "print -s {1?no variable}=\'\$$1\'" } · 2012-01-03 17:03:00 • It works as a method applicated to a variable, converts the string variable into an array Show Sample Output 1 Split() { eval "$1=( \"$(echo "${!1}" | sed "s/$2/\" \"/g")\" )"; } · 2010-02-08 17:41:59 • Some commands (such as sed and perl) have options to support in-place editing of files, but many commands do not. This shell function enables any command to change files in place. See the sample output for many examples. The function uses plain sh syntax and works with any POSIX shell or derivative, including zsh and bash. Show Sample Output 1 inplace() { eval F=\"\$$#\"; "@" > "F".new && mv -f "F".new "F"; } · 2010-04-09 11:36:31 • Validate a file using xmllint. If there are parser errors, edit the file in vim at the line of the first error. 1 vimlint(){ eval (xmllint --noout "1" 2>&1 | awk -F: '/parser error/{print "vim \""1"\" +"2; exit}'); } · 2010-06-23 15:55:02 • Takes the same arguments that ack does. E.g. ack-open -i "searchterm" opens all files below the current directory containing the search term. The search term is also highlighted within vim if you have hlsearch set. Works on zsh, unsure if it works on bash. Note: ubuntu users have to change ack to ack-grep unless you already have it aliased (as I do) 1 ack-open () { local x="(ack -l * | xargs)"; if [[ -n x ]]; then eval vim -c "/*[-1] x"; else echo "No files found"; fi } · 2011-10-04 08:56:18 • Starts and shows a timer. banner command is a part of the sysvbanner package. Instead of the banner an echo or figlet commands could be used. Stop the timer with Ctrl-C and elapsed time will be shown as the result. Show Sample Output 1 alias timer='export ts=(date +%s);p='\''(date -u -d @"(((date +%s)-ts))" +"%H.%M.%S")'\'';watch -n 1 -t banner p;eval "echo p"' · 2013-08-24 16:18:45 • Use dots to cd down directories instead of having to remember all of the pesky back slashes! Better yet, works on even and odd number of dots! Now, just estimate how far down you want to traverse. Show Sample Output 1 for i in {1..6};do c=;d=;for u in eval echo {1..i};do c="c../";d="d..";eval "d(){ cd c;}"; eval "d.(){ cd c;}";done;done · 2013-09-04 20:12:45 • Uses the lm-sensors package in Linux to display fan speed. Grep RPM is used to discover lines containing the text RPM, and sed is used to edit out everything but the RPM number. The watch utility is used to update the display every 10 seconds and -d highlights any changes from the previous value. The eval function of Bash is used to execute the command enclosed in the ".." string. Show Sample Output 1 watch -n 10 -d eval "sensors | grep RPM | sed -e 's/.*: *//;s/ RPM.*//'" · 2015-04-07 14:28:32 • This command will automate the creation of ESSIDs and batch processing in pyrit. Give it a list of WPA/WPA2 access points you're targeting and it'll import those ESSIDs and pre-compute the potential password hashes for you, assuming you've got a list of passwords already imported using: pyrit -i dictionary import_passwords Once the command finishes, point pyrit to your packet capture containing a handshake with the attack_db module. Game over. Show Sample Output 0 gopyrit () { if [ # -lt 1 ]; then echo 0 '< list of ESSIDs >'; return -1; fi; for i in "@"; do pyrit -e i create_essid && pyrit batch; done; pyrit eval } · 2010-06-19 01:11:00 • Thanks th John_W for suggesting the fix allowing ~/ to be used when saving a directory. directions: Type in a url, it will show a preview of what the file will look like when saved, then asks if you want to save the preview and where you want to save it. Great for grabbing the latest commandlinefu commands without a full web browser or even a GUI. Requires: w3m Show Sample Output 0 read -p "enter url:" a ; w3m -dump a > /dev/shm/e1q ; less /dev/shm/e1q ; read -p "save file as text (y/n)?" b ; if [ b = "y" ] ; then read -p "enter path with filename:" c && touch (eval echo "c") ; mv /dev/shm/e1q (eval echo "c") ; fi ; echo DONE · 2010-07-13 22:36:38 • I used to do a lot of path manipulation to set up my development environment (PATH, LD_LIBRARY_PATH, etc), and one part of my environment wasn't always aware of what the rest of the environment needed in the path. Thus resetting the entire PATH variable wasn't an option; modifying it made sense. The original version of the functions used sed, which turned out to be really slow when called many times from my bashrc, and it could take up to 10 seconds to login. Switching to parameter substitution sped things up significantly. The commands here don't clean up the path when they are done (so e.g. the path gets cluttered with colons). But the code is easy to read for a one-liner. The full function looks like this: remove_path() { eval PATHVAL=":\$$1:" PATHVAL=${PATHVAL//:$2:/:} # remove$2 from $PATHVAL PATHVAL=${PATHVAL//::/:} # remove any double colons left over PATHVAL=${PATHVAL#:} # remove colons from the beginning of$PATHVAL PATHVAL=${PATHVAL%:} # remove colons from the end of$PATHVAL export $1="$PATHVAL" } append_path() { remove_path "$1" "$2" eval PATHVAL="\$$1" export 1="{PATHVAL}:2" } prepend_path() { remove_path "1" "2" eval PATHVAL="\$$1" export $1="$2:${PATHVAL}" } I tried using regexes to make this into a cleaner one-liner, but remove_path ended up being cryptic and not working as well: rp() { eval "[[ ::\$$1:: =~ ^:+(2:)?((.*):2:)?(.*):+ ]]"; export 1={BASH_REMATCH[3]}:{BASH_REMATCH[4]}; }; Show Sample Output 0 rp() { local p; eval p=":\$$1:"; export$1=${p//:$2:/:}; }; ap() { rp "$1" "$2"; eval export $1=\$$12; }; pp() { rp "1" "2"; eval export 1=2:\$$1; } · 2010-07-15 18:52:01 • 0 l=10;for((i=0;i<$l;i++));do eval "a$i=($(pv=1;v=1;for((j=0;j<$l;j++));do [$i -eq 0 -o $j -eq 0 ]&&{ v=1 && pv=1; }||v=$((pv+a$((i-1))[$((j))]));echo -n "$v ";pv=$v;done;));";eval "echo \"\${a$i[@]}\"";done | column -t;
· 2011-02-11 17:00:20
• In order to create, let's say, 10 directories with a single process we can use the command: mkdir test{1,2,3,4,5,6,7,8,9,10} something extremely boring to type! Why not use seq? seq -s, 1 10 and use its output inside the curly braces? The obvious solution mkdir test{$(seq -s, 1 10)} is, unfortunately, too naive and doesn't work. The answer is the order of the shell expansions (feature of Bourne Shell, actually), where brace expansion happens before command substitution (according to Bash's manual). The solution is to put another level of substitution, using the powerful and mystic command eval. I found the trick in a similar problem in the post at http://stackoverflow.com/questions/6549037/bash-brace-expansion-in-scripts-not-working-due-to-unwanted-escaping 0 eval "mkdir test{$(seq -s, 1 10)}"
· 2011-07-23 17:09:01

• 0
isdef() { eval test -n \"\${$1+1}\"; }
· 2011-09-29 15:39:51
•  1 2 3 >

### 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.

### Check These Out

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

Virtualbox: setup hardware
where - memory 256 assign 256 Mb RAM - acpi on enable ACPI (mandatory if you use Winfog 2000 - ioapic off disable the IO APIC. Not useful if you use one CPU (on virtual machine or a 32 bit operative system). As ACPI, this switch is mandatory for Winbug 2000 - pae on enable the Phisical Address Extension how to use more than 4Gb of RAM on x86 CPU - hwvirtex on enables hardware virtualization extensions for microprocessors that have this feature (which should be also enabled in the BIOS of the motherboard) - nestedpaging on allows part of the processes of memory management hardware are made directly

escape any command aliases
e.g. if rm is aliased for 'rm -i', you can escape the alias by prepending a backslash: rm [file] # WILL prompt for confirmation per the alias \rm [file] # will NOT prompt for confirmation per the default behavior of the command

backup system over ssh, exlucde common dirs

Display packages and versions on Debian/Ubuntu distrib
Need admin right to run dpkg-query

python smtp server
This command will start a simple SMTP server listening on port 1025 of localhost. This server simply prints to standard output all email headers and the email body.

Follow the flow of a log file
tailf same as tail -f follow the flow of a log file, showing it in real time to stdout.

list folders containing less than 2 MB of data
This command will search all subfolders of the current directory and list the names of the folders which contain less than 2 MB of data. I use it to clean up my mp3 archive and to delete the found folders pipe the output to a textfile & run: $while read -r line; do rm -Rv "$line"; done < textfile

Selecting a random file/folder of a folder
Also looks in subfolders

print a python-script (or any other code) with syntax-highlighting and no loss of indentation