Commands using echo (1,545)

  • If you have lots of subversion working copies in one directory and want to see in which repositories they are stored, this will do the trick. Can be convenient if you need to move to a new subversion server. Show Sample Output


    0
    (for i in `find . -maxdepth 2 -name .svn | sed 's/.svn$//'`; do echo $i; svn info $i; done ) | egrep '^.\/|^URL'
    jespere · 2010-05-09 11:54:37 3
  • Here's a super simple one liner that could have gotten our team 300 points! #facepalm! Show Sample Output


    0
    echo "6d5967306474686924697344406b3379" | xxd -r -p
    IsraelTorres · 2010-05-24 22:48:41 3
  • This renames a pattern matched bunch of files by their last modified time. rename by timestamp rename by time created rename by time modified Show Sample Output


    0
    for i in somefiles*.png ; do echo "$i" ; N=$(stat -c %Y $i); mv -i $i $N.png; done
    sufoo · 2010-06-01 19:28:05 3
  • This is a simple solution to running a remote program on a remote computer on the remote display through ssh. 1. Create an empty 'commander' file in the directory where you intend on running these commands. 2. Run the command 3. Hop on another computer and ssh in to the PC where you ran the command 4. cd to the directory where the 'commander' file is. 5. Test it by doing the following: echo "xeyes" > commander 6. If it worked properly, then xeyes will popup on the remote computer. Combined with my other one liner, you can place those in some start-up scripts and be able to screw with your wife/daughter/siblings, w/e by either launching programs or sending notifications(my other one liner). Also, creates a log file named comm_log in working directory that logs all commands ran.


    0
    while :;do if [ ! $(ls -l commander |cut -d ' ' -f5) -eq 0 ]; then echo "Ran command: $(less commander) @ $(date +%D) $(date +%r)" >> comm_log;"$(less commander)";> commander;fi;done
    evil · 2010-06-15 01:20:27 4
  • 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 }
    meathive · 2010-06-19 01:11:00 7
  • Same as another one I saw, just with a cleaner sed command Edit: updated the sed command to use the [[:xdigit:]] character class - more portable between locales Note that it will have a newline inserted after every 32 characters of input, due to the output of xxd Show Sample Output


    0
    echo -n 'text' | xxd -ps | sed 's/[[:xdigit:]]\{2\}/\\x&/g'
    camocrazed · 2010-07-13 21:46:30 3
  • 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
    LinuxMan · 2010-07-13 22:36:38 5
  • first off, if you just want a random UUID, here's the actual command to use: uuidgen Your chances of finding a duplicate after running this nonstop for a year are about the same as being hit by a meteorite before finishing this sentence The reason for the command I have is that it's more provably unique than the one that uuidgen creates. uuidgen creates a random one by default, or an unencrypted one based on time and network address if you give it the -t option. Mine uses the mac address of the ethernet interface, the process id of the caller, and the system time down to nanosecond resolution, which is provably unique over all computers past, present, and future, subject to collisions in the cryptographic hash used, and the uniqueness of your mac address. Warning: feel free to experiment, but be warned that the stdin of the hash is binary data at that point, which may mess up your terminal if you don't pipe it into something. If it does mess up though, just type reset Show Sample Output


    0
    printf $(( echo "obase=16;$(echo $$$(date +%s%N))"|bc; ip link show|sed -n '/eth/ {N; p}'|grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}'|head -c 17 )|tr -d [:space:][:punct:] |sed 's/[[:xdigit:]]\{2\}/\\x&/g')|sha1sum|head -c 32; echo
    camocrazed · 2010-07-14 14:04:53 10
  • Just use "od" and it can also dump in decimal or octal. (use -t x1 and not just -x or it confuses the byte order) There is a load of other formatting options, I'm not sure if you can turn off the address at the start of the line. Show Sample Output


    0
    echo "text" | od -t x1
    max_allan · 2010-07-14 14:53:25 3
  • Replace the echo command with whatever commands you want. 'read' reads a line from stdin and places the text in the variable, the stdin of the while loop comes from the find command. Note that with simple commands, an easier way is using the '-exec' option of find. My command is useful if you want to execute multiple commands in the loop. Show Sample Output


    0
    find -name 'foo*' | while read i; do echo "$i"; done
    imgx64 · 2010-07-16 15:35:27 6

  • 0
    echo "1+1" | bc
    firstohit · 2010-08-08 20:53:14 3
  • Another way to do it with slightly fewer characters. It doesn't work on Russian characters; please don't vote down because of that. :p It's very handy for those of us working in ascii :) Show Sample Output


    0
    echo StrinG | tr 'A-Z' 'a-z'
    randy909 · 2010-08-12 15:42:56 3
  • Simple way of having random mrxvt backgrounds. Add this to your bashrc and change the path names for the pictures.


    0
    LIST="/some/pic/file /another/picture /one/more/pic"; PIC=$(echo $LIST | sed s/"\ "/"\n"/g | shuf | head -1 | sed s/'\/'/'\\\/'/g ); sed -i s/Mrxvt.Pixmap:.*/"Mrxvt.Pixmap:\t$PIC"/ ~/.mrxvtrc
    dog · 2010-08-23 10:17:42 3
  • the comm utility (opposite of diff) show commonalities in files (in this case strings) Show Sample Output


    0
    Array1=( "one" "two" "three" "four" "five" );Array2=( "four" "five" "six" "seven" );savedIFS="${IFS}";IFS=$'\n';Array3=($(comm -12 <(echo "${Array1[*]}" |sort -u) <(echo "${Array2[*]}" | sort -u)));IFS=$savedIFS
    elofland · 2010-08-23 19:25:22 3

  • 0
    python -c $(echo -e 'import py_compile\npy_compile.compile("/path/to/script.py")');
    quinncom · 2010-09-02 00:41:51 4
  • command was too long... this is the complete command: fname=$1; f=$( ls -la $fname ); if [ -n "$f" ]; then fsz=$( echo $f | awk '{ print $5 }' ); if [ "$fsz" -ne "0" ]; then nrrec=$( wc -l $fname | awk '{ print $1 }' ); recsz=$( expr $fsz / $nrrec ); echo "$recsz"; else echo "0"; fi else echo "file $fname does not exist" >&2; fi First the input is stored in var $fname The file is checked for existance using "ls -lart". If the output of "ls -lart" is empty, the error message is given on stderr Otherwise the filelength is taken from the output of "ls -lart" (5th field) With "wc -l" the number of records (or lines) is taken. The record size is filelength devided by the number of records. please note: this method does not take into account any headers, variable length records and only works on ascii files where the records are sperated by 0x0A (or 0x0A/0x0D on MS-DOS/Windows). Show Sample Output


    0
    fname=$1;f=$(ls -la $fname);fsz=$(echo $f|awk '{ print $5 }');nrrec=$(wc -l $fname|awk '{ print $1 }');recsz=$(expr $fsz / $nrrec);echo "$recsz"
    vuurst · 2010-09-14 08:40:22 3
  • Get the hour and greet the user! Make sure you add this to your bashrc, for a pleasant hacking experience! Show Sample Output


    0
    echo Good $(i=`date | cut -d: -f1 | cut -d' ' -f4-4` ; if [ $i -lt 12 ] ; then echo morning ; else if [ $i -lt 15 ] ; then echo afternoon ; else echo evening ; fi ; fi)
    foolcraft · 2010-09-21 11:16:36 7
  • Saves all the "cut" hacks


    0
    echo Good $(i=`date +%H` ; if [ $i -lt 12 ] ; then echo morning ; else if [ $i -lt 15 ] ; then echo afternoon ; else echo evening ; fi ; fi)
    jyro · 2010-09-23 09:50:13 3
  • Useful for creating MAC addresses for virtual machines on a subnet. 00:16:3e is a standard Xen OID, change as needed. Show Sample Output


    0
    echo 00:16:3e$(gethostip 10.1.2.11 | awk '{ print tolower(substr($3,3)) }' |sed 's/.\{2\}/:&/g' )
    chwilk · 2010-09-23 16:46:21 3

  • 0
    echo -e "12 morning\n15 afternoon\n24 evening" |awk '{if ('`date +%H`'<$1) {print "Good "$2;exit}}'
    dendoes · 2010-09-27 14:16:19 3

  • 0
    find . -name "*.jar" | while read line; do echo "### $line "; unzip -l $line; done | grep "^###\|you-string" |less
    onk · 2010-09-28 17:51:40 3
  • Shows a zenity progressbar for each file in a script, see the samble output. Works with any number, less, equal or greater than 100. x is not initially defined. If used twice in the script, set it: x=0 (for FILE in $@; do echo $[100*++x/$#]; command... "$FILE"; done)|zenity --progress --auto-close Show Sample Output


    0
    (for FILE in $@; do echo $[100*++x/$#]; command-for-each-parameter; done)|zenity --progress --auto-close
    rodolfoap · 2010-10-05 10:07:04 5
  • Article mentions what each part of the command is responsible for. http://raymondcrandall.com/post/1360780719/easily-renaming-lots-of-files Show Sample Output


    0
    for f in * ; do mv "$f" $( echo $f | tr ' ' '-' ) ; done
    RaymondCrandall · 2010-10-20 20:07:33 9

  • 0
    while read line; do pais=$(whois "$line" | grep -E '[Cc]ountry') echo -n "IP=$line Pais=$pais" && echo done <listaip
    pathcl · 2010-10-25 15:39:50 31
  • Use bc for decimals...


    0
    echo $(echo 'scale=2; ' '100 * ' $(eix --only-names -I | wc -l) / $(eix --only-names | wc -l) | bc -l)%
    MeaCulpa · 2010-10-25 15:42:15 3
  • ‹ First  < 33 34 35 36 37 >  Last ›

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

Run a program transparently, but print a stack trace if it fails
For automated unit tests I wanted my program to run normally, but if it crashed, to add a stack trace to the output log. I came up with this command so I wouldn't have to mess around with core files. The one downside is that it does smoosh your program's stderr and stdout together.

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

Hold off any screensavers/timeouts
Moves the mouse 1 pixel down and to the right, then immediately back again, every 4 minutes. This keeps screensavers from turning on. I have used this extensively and I've never even noticed the mouse movement because it is so subtle.

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.

Get your outgoing IP address


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: