Commands using eval (48)

  • alias sp='screen -X eval "chdir $PWD"' # save the path in the current sp # create new window ctrl + ] pwd # has same path as last window


    0
    screen -X eval "chdir $PWD"
    hbt · 2016-12-09 01:38:38 0
  • The result will be a bunch of 'tail' commands running in the background in your current shell.


    0
    eval `lsof +D /var/log|(read;awk '{print "tail -f " $9 " &" }'|sort|uniq)`
    p_b_r · 2016-08-25 20:23:38 0
  • This command will display the file, but you can change 'cat' to anything else (type 'n' when prompted to cancel the command or anything else to proceed). . Some hints for newbies: type unset bar to make 'bar' function annihilated. For permanent usage you can put this (bar) function in your .bashrc (for bash) or in .profile (for sh). With: . ~/.bashrc you can get all new inserted functions in .bashrc (so the function 'bar' or whatever name you choose) immediately available. Show Sample Output


    0
    bar() { foo=$(ls -rt|tail -1) && read -ep "cat $foo? <y/n> " a && [[ $a != "n" ]] && eval "cat $foo" ;}
    knoppix5 · 2015-10-21 20:09:33 2

  • 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
    knoppix5 · 2015-05-03 01:51:27 0
  • 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.*//'"
    omap7777 · 2015-04-07 14:28:32 0
  • So this first obtains address of the DBUS session, as it's not available by default over SSH. Then it tells plasma-overlay to exit. `kquitapp` is pretty much an equivalent of the qdbus calls.


    0
    ( eval $(grep -z '^DBUS_SESSION_BUS_ADDRESS' /proc/$(pgrep -u $USER plasma-overlay)/environ); export DBUS_SESSION_BUS_ADDRESS; kquitapp plasma-overlay )
    mig_hg · 2014-09-01 12:49:58 0
  • echoprint identify your song, then return artist, song name and album name(release) in a JSON. jq parse it and mp3info set the data in your mp3 file. of course it depends on: mp3info jq echoprint You need to set the environment variable export CODEGEN_NEST_API_KEY='YOUR_ECHONEST_KEY_HERE' You can use it with find, but probably will bypass the 120 request/minute of developer account key. So, use a sleep to do it. Something like: find -name \*.mp3 | while read $f; do eval echo $(echoprint-codegen "$f" | jq ' .[0].metadata | "mp3info -a \"" + .artist + "\" -t \"" + .title + "\" -l \"" + .release + "\" \"" + .filename + "\"" ' ) | bash; sleep 1; done


    0
    eval echo $(echoprint-codegen "/path/to/file.mp3"| jq ' .[0].metadata | "mp3info -a \"" + .artist + "\" -t \"" + .title + "\" -l \"" + .release + "\" \"" + .filename + "\"" ' ) | bash
    glaudiston · 2014-08-08 21:14:53 0
  • Connects to the last adb connection in history. Show Sample Output


    0
    eval $(history | cut -c 8- | grep "adb connect [0-9]" | tail -1)
    CanOrhan · 2014-02-27 14:44:27 0

  • 0
    $(eval "echo {${min}..${max}}")
    bbates · 2014-02-22 14:24:48 0
  • 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
    bbbco · 2013-09-04 20:12:45 1
  • 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"'
    ichbins · 2013-08-24 16:18:45 1

  • 0
    eval `ls -1d * | awk '{print "zip -r "$1".zip "$1";"}'`
    javaloper · 2013-04-29 12:00:54 0
  • 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; }
    michelsberg · 2013-01-21 12:57:45 3
  • 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 &
    SQUIIDUX · 2012-11-17 23:56:17 4
  • Creates a directory and then cds into it directly Show Sample Output


    0
    function mkdircd () { mkdir -p "$@" && eval cd "\"\$$#\""; }
    ankush108 · 2012-06-26 17:19:16 0
  • If you're using GNIP as as data source provider for Twitter data in their "Activity Streams" format, use this search to pull out the geo coordinates from tweets as "latitude & longitude". You'll find that splunk creates a "multivalued" field out of the "geo.coordinates{}" field from a tweet. A mulitvalued field is an array, so by using "mvindex(field,position_in_array_starting_with_zero), we can create new fields on the fly for lat/lon. Show Sample Output


    0
    index=twitter geo.coordinates{}="*"| spath path=geo.coordinates{} output=geocoordinates| eval latitude=mvindex(geocoordinates,1)| eval longitude=mvindex(geocoordinates,0)
    SplunkNinja · 2012-06-19 02:57:40 0
  • `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}"); }
    Mozai · 2012-06-15 17:10:45 1
  • If $INBACK is set, command will launch in foreground and inverse. Very useful in script ! We could apply the inverse comportement like that : eval command ${INBACK:+&}


    -1
    eval <command> ${INBACK:-&}
    Zulu · 2012-04-05 03:50:57 0
  • Usage: watch ls -l Basic but usable replacement for the "watch" command for those systems which don't have it (e.g. the Solaris I'm trapped on). Type Ctrl+V to escape the following Ctrl+L which clears the screen. It will be displayed as "^L".


    0
    watch() { while true; do echo "<Ctrl+V><Ctrl+L>Every 2.0s: $@"; date; eval "$@"; sleep 2; done }
    hfs · 2012-03-07 09:30:15 0
  • Scan a file and print out a list of ASCII characters that are not used in the file which can then be safely used to delimit fields. Useful when needing to convert CSV files using "," to a single character delimiter. Piping it into less at the end (which could be redundant) stops the command characters being interpreted by the terminal.


    0
    for i in `seq 0 9` A B C D E F; do for j in `seq 0 9` A B C D E F; do HEX=\$\'\\x${i}${j}\'; if ! eval grep -qF "$HEX" file; then eval echo $HEX \\x${i}${j}; fi; done; done 2> /dev/null | less
    moogmusic · 2012-01-05 10:09:07 0
  • 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\'" }
    libdave · 2012-01-03 17:03:00 0
  • Schematics: command [options] [paste your variable here] parameter command [options] [paste entire column of variables here] parameter ... (hard-code command "c" and parameter "e" according to your wishes: in example shown command = "cp -a" and parameter = "~") Features: - Quick exchange only variable part of a long command line - Make variable part to be an entire column of data (i.e. file list) - Full control while processing every single item Hints: Paste column of data from anywhere. I.e. utilize the Block Select Mode to drag, select and copy columns (In KDE Konsole with Ctrl+Alt pressed, or only Ctrl pressed in GNOME Terminal respectively). Disadvantages: You can paste only one single variable in a row. If there are more space separated variables in a row only first one will be processed, but you can arrange your variables in a column instead. To transpose rows to columns or vice versa look at Linux manual pages for 'cut' and 'paste'. TODO: - add edit mode to vary command "c" and parameter "e" on the fly - add one edit mode more to handle every list item different - add y/n/a (=All) instead of only y(=default)/n to allowed answers Disclaimer: The code is not optimized, only the basic idea is presented here. It's up to you to shorten code or extend the functionality. Show Sample Output


    -1
    c="cp -a";e="~";echo -e "\npaste\n";i=0;k="1"; while [[ "$k" != "" ]]; do read -a k;r[i]=$k;((i++));done;i=0;while :;do t=${r[i]};[ "$t" == "" ] && break; g=$(echo $c ${r[i]} $e);echo -e $g "\ny/n?";read y;[ "$y" != "n" ] && eval $g;((i++));done
    knoppix5 · 2011-12-04 12:45:44 0
  • 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 }
    iynaix · 2011-10-04 08:56:18 0

  • 0
    isdef() { eval test -n \"\${$1+1}\"; }
    keymon · 2011-09-29 15:39:51 0
  • 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")
    xakon · 2011-07-29 12:47:26 6
  •  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

Print text string vertically, one character per line.

Fastest segmented parallel sync of a remote directory over ssh
Mirror a remote directory using some tricks to maximize network speed. lftp:: coolest file transfer tool ever -u: username and password (pwd is merely a placeholder if you have ~/.ssh/id_rsa) -e: execute internal lftp commands set sftp:connect-program: use some specific command instead of plain ssh ssh:: -a -x -T: disable useless things -c arcfour: use the most efficient cipher specification -o Compression=no: disable compression to save CPU mirror: copy remote dir subtree to local dir -v: be verbose (cool progress bar and speed meter, one for each file in parallel) -c: continue interrupted file transfers if possible --loop: repeat mirror until no differences found --use-pget-n=3: transfer each file with 3 independent parallel TCP connections -P 2: transfer 2 files in parallel (totalling 6 TCP connections) sftp://remotehost:22: use sftp protocol on port 22 (you can give any other port if appropriate) You can play with values for --use-pget-n and/or -P to achieve maximum speed depending on the particular network. If the files are compressible removing "-o Compression=n" can be beneficial. Better create an alias for the command.

Command Line to Get the Stock Quote via Yahoo
Retrieve the current stock price from Yahoo Finance. The output is simply the latest price (which could be delayed). If you want to look up stock for a different company, replace csco with your symbol.

Batch edition of all OpenOffice.org Writer files in the current directory (body text)
This function does a batch edition of all OOO3 Writer files in current directory. It uses sed to search a FOO pattern into body text of each file, then replace it to foo pattern (only the first match) . I did it because I've some hundreds of OOO3 Writer files where I did need to edit one word in each ones and open up each file in OOO3 gui wasn't an option. Usage: bsro3 FOO foo

View any already in progress copy command in detail
If you spot a dubious looking cp command running you can use this command to view what is being copied and to where. 1234 is the PID of the cp command being passed to the lsof utility. 3r.*REG will display the file/directory that is being read/copied. 4w.*REG will display the destination it is being written to.

Generate random valid mac addresses
First set the variable $hexchars: $hexchars="0123456789ABCDEF" Change the number in the first for loop if you need less then 1200 mac addresses

Install pip with Proxy
Installs pip packages defining a proxy

Super Speedy Hexadecimal or Octal Calculations and Conversions to Decimal.
^Hexadecimal Ten minus Octal Ten is Eight(in Decimal). $ echo "$(( 0xaf )) = $(( 0257 ))" ^Hexadecimal AF and Octal 257 are both Decimal 175.

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"

find process associated with a port
e.g. fuser 25/tcp (see which pid is listening on smtp)


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: