Commands using echo (1,545)

  • If you use HISTTIMEFORMAT environment e.g. timestamping typed commands, $(echo "1 2 $HISTTIMEFORMAT" | wc -w) gives the number of columns that containing non-command parts per lines. It should universify this command. Show Sample Output


    0
    history | awk '{a[$'$(echo "1 2 $HISTTIMEFORMAT" | wc -w)']++}END{for(i in a){print a[i] " " i}}' | sort -rn | head
    bandie91 · 2010-05-02 21:48:53 3
  • 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
  • ‹ 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

Display a cool clock on your terminal
This command displays a clock on your terminal which updates the time every second. Press Ctrl-C to exit. A couple of variants: A little bit bigger text: $ watch -t -n1 "date +%T|figlet -f big" You can try other figlet fonts, too. Big sideways characters: $ watch -n 1 -t '/usr/games/banner -w 30 $(date +%M:%S)' This requires a particular version of banner and a 40-line terminal or you can adjust the width ("30" here).

Generat a Random MAC address
Original author unknown (I believe off of a wifi hacking forum). Used in conjuction with ifconfig and cron.. can be handy (especially spoofing AP's)

Install pip with Proxy
Installs pip packages defining a proxy

Fix "broken" ID3 tags in the current directory and subdirectories
Some MP3s come with tags that don't work with all players. Also, some good tag editors like, EasyTAG output tags that don't work with all players. For example, EasyTAG saves the genre as a numeric field, which is not used correctly in Sansa MP3 players. This command corrects the ID3 tags in MP3 files using mid3iconv, which comes with mutagen. To install Mutagen on Fedora use "yum install python-mutagen"

Find usb device
I often use it to find recently added ou removed device, or using find in /dev, or anything similar. Just run the command, plug the device, and wait to see him and only him

A snooze button for xmms2 alarm clock
you can also run "xmms2 pause & at now +5min

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"

Convert seconds to [DD:][HH:]MM:SS
Converts any number of seconds into days, hours, minutes and seconds. sec2dhms() { declare -i SS="$1" D=$(( SS / 86400 )) H=$(( SS % 86400 / 3600 )) M=$(( SS % 3600 / 60 )) S=$(( SS % 60 )) [ "$D" -gt 0 ] && echo -n "${D}:" [ "$H" -gt 0 ] && printf "%02g:" "$H" printf "%02g:%02g\n" "$M" "$S" }

Buffer in order to avoir mistakes with redirections that empty your files
A common mistake in Bash is to write command-line where there's command a reading a file and whose result is redirected to that file. It can be easily avoided because of : 1) warnings "-bash: file.txt: cannot overwrite existing file" 2) options (often "-i") that let the command directly modify the file but I like to have that small function that does the trick by waiting for the first command to end before trying to write into the file. Lots of things could probably done in a better way, if you know one...

Find the package that installed a command


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: