Commands using echo (1,545)


  • -2
    echo "12345,12346" |sed -e's/ //'|tr "," "\n"| while read line; do echo -n $line" "; svn log -vr $line https://url/to/svn/repository/|grep "/"|head -1|cut -d"/" -f2; done
    psytek · 2009-04-15 15:21:20 4
  • You've opened a terminal window and you've connected off to a remote host that didn't pick up your terminal size, and all your curses and paging apps are screwed up as a result. You need to quickly determine how many lines are in your current terminal view (to feed into "stty rows X"). Show Sample Output


    -2
    _llines=100; while [ $_llines -gt 1 ]; do echo $_llines; _llines=$(($_llines-1)); done
    romulusnr · 2009-04-29 00:19:45 7
  • get desired info from machine and pipe it txt file. Show Sample Output


    -2
    echo "-------------" >> nicinfo.txt; echo "computer name x" >> nicinfo.txt; ifconfig | grep status >> nicinfo.txt; ifconfig | grep inet >> nicinfo.txt; ifconfig | grep ether >> nicinfo.txt; hostinfo | grep type >> nicinfo.txt;
    miccaman · 2009-06-25 12:32:37 30

  • -2
    wget http://checkip.dyndns.org && clear && echo && echo My IP && egrep -o '([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3}' index.html && echo && rm index.html
    onkelchentobi · 2009-08-07 21:21:59 4

  • -2
    echo $PATH|awk -F: ' { for (i=1; i <= NF; i++) print $i }'
    nitins · 2009-08-12 07:56:56 4
  • Ummmm.. Saw that gem on some dead-head hippies VW bus at phish this summer.. It's actually one of my favorite ways of using bash, very clean. It shows what you can do with the cool advanced features like job control, redirection, combining commands that don't wait for each other, and the thing I like the most is the use of the ( ) to make this process heirarchy below, which comes in very handy when using fifos for adding optimization to your scripts or commands with similar acrobatics. F UID PID PPID WCHAN RSS PSR CMD 1 gplovr 30667 1 wait 1324 1 -bash 0 gplovr 30672 30667 - 516 3 \_ sleep 3 1 gplovr 30669 1 wait 1324 1 -bash 0 gplovr 30673 30669 - 516 0 \_ sleep 5 1 gplovr 30671 1 wait 1324 1 -bash 0 gplovr 30674 30671 - 516 1 \_ sleep 7 Show Sample Output


    -2
    S=$SSH_TTY && (sleep 3 && echo -n 'Peace... '>$S & ) && (sleep 5 && echo -n 'Love... '>$S & ) && (sleep 7 && echo 'and Intergalactic Happiness!'>$S & )
    AskApache · 2009-08-19 07:57:16 7
  • Enable 'sleep' function in Windows environment where this does not exist, although not exact in time. (there is a delay for each ping) This is a simple way to separate commands with a time-period. Show Sample Output


    -2
    echo sleep() begins: %TIME% && FOR /l %a IN (10,-1,1) do (ECHO 1 >NUL %as&ping -n 2 -w 1 127.0.0.1>NUL) && echo sleep() end: %TIME%
    pfredrik · 2009-08-19 13:43:09 3
  • If you need to ssh into a computer on the local network but you're unsure of the ip to use, then ping them and see if you get a response. If you do, print out the address you got it from. Adjust the range to suit your network.


    -2
    for i in 192.168.1.{61..71};do ping -c 1 $i &> /dev/null && echo $i;fi;done
    AlecSchueler · 2009-08-26 06:04:24 11
  • Removes trailing newline; colon becomes record separator and newline becomes field separator, only the first field is ever printed. Replaces empty entries with $PWD. Also prepend relative directories (like ".") with the current directory ($PWD). Can change PWD with env(1) to get tricky in (non-Bourne) scripts. Show Sample Output


    -2
    echo src::${PATH} | awk 'BEGIN{pwd=ENVIRON["PWD"];RS=":";FS="\n"}!$1{$1=pwd}$1!~/^\//{$1=pwd"/"$1}{print $1}'
    arcege · 2009-09-09 04:03:46 3
  • another replacement for cat.


    -2
    echo "$(</etc/issue)"
    mobidyc · 2009-09-14 09:44:35 34
  • regex to match an ip Show Sample Output


    -2
    echo "123.32.12.134" | grep -P '([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])'
    KeePon · 2009-09-17 12:17:32 5

  • -2
    n=$RANDOM$RANDOM$RANDOM; let "n %= 10000000000"; echo $n
    alset · 2009-10-15 05:10:00 4
  • This script will list all the files in the tarballs present on any folder or subfolder of the provided path. The while loop is for echoing the file name of the tarball before listing the files, so the tarball can be identified


    -2
    find <path> -name "*.tgz" -or -name "*.tar.gz" | while read file; do echo "$file: "; tar -tzf $file; done
    polaco · 2009-11-10 20:39:04 36
  • If you gzip an empty file it becomes 20 bytes. Some backup checks i do check to see if the file is greater than zero size (-s flag) but this is no good here. Im sure someone has a better check than me for this? No check to see if file exists before checking it's size.


    -2
    BACKUP_FILE_SIZE=`eval ls -l ${BACKUP_FILE} | awk {'print $5'}`; if [ $BACKUP_FILE_SIZE -le 20 ]; then echo "its empty"; else echo "its not empty"; fi
    Redrocket · 2009-12-29 08:34:37 3
  • CHANGELOG Version 1.1 removedir () { echo "You are about to delete the current directory $PWD Are you sure?"; read human; if [[ "$human" = "yes" ]]; then blah=$(echo "$PWD" | sed 's/ /\\ /g'); foo=$(basename "$blah"); rm -Rf ../$foo/ && cd ..; else echo "I'm watching you" | pv -qL 10; fi; } BUG FIX: Folders with spaces Version 1.0 removedir () { echo "You are about to delete the current directory $PWD Are you sure?"; read human; if [[ "$human" = "yes" ]]; then blah=`basename $PWD`; rm -Rf ../$blah/ && cd ..; else echo "I'm watching you" | pv -qL 10; fi; } BUG FIX: Hidden directories (.dotdirectory) Version 0.9 rmdir () { echo "You are about to delete the current directory $PWD. Are you sure?"; read human; if [[ "$human" = "yes" ]]; then blah=`basename $PWD`; rm -Rf ../$blah/ && cd ..; else echo "I'm watching you" | pv -qL 10; fi; } Removes current directory with recursive and force flags plus basic human check. When prompted type yes 1. [user@host ~]$ ls foo bar 2. [user@host ~]$ cd foo 3. [user@host foo]$ removedir 4. yes 5. rm -Rf foo/ 6. [user@host ~]$ 7. [user@host ~]$ ls bar Show Sample Output


    -2
    removedir () { echo "Deleting the current directory $PWD Are you sure?"; read human; if [[ "$human" = "yes" ]]; then blah=$(echo "$PWD" | sed 's/ /\\ /g'); foo=$(basename "$blah"); rm -Rf ../$foo/ && cd ..; else echo "I'm watching you" | pv -qL 10; fi; }
    oshazard · 2010-01-17 11:34:38 31
  • Outputs multiple whois from a plain text file.


    -2
    for domain in `cat list_of_domains.txt`; do echo $domain; whois $domain >> output.txt; done
    pathcl · 2010-02-15 17:13:45 7
  • You don't want the -ar parameters in this case. The man page for BASH_BUILTINS(1) states: "-a option means to remove or mark all jobs" and "-r option without a jobspec argument restricts operation to running jobs" In this case we are supplying the process id of the job to disown so neither of these should be used.


    -2
    echo "Starting Daemon"; ( while :; do sleep 15; echo "I am still running =]"; done ) & disown -h $!
    daleki · 2010-02-23 19:17:05 3
  • find all files in cur dir add to url and append to file


    -2
    find . type f -exec echo http://exg.com/{} \; > file
    unixmonkey8504 · 2010-03-02 14:18:01 3
  • Tested on bash, and follows all the rules about leap years. Show Sample Output


    -2
    leapyear() { if [ $[$1 % 4] -eq 0 ] && [ $[$1 % 100] -ne 0 ] || [ $[$1 % 400] -eq 0 ]; then echo $1' is a leap year!'; else echo $1' is not a leap year.'; fi; }
    kaedenn · 2010-03-30 17:19:20 4
  • Not really an easier solution. But an example using && for (if last command returned 0). You can use || for (if last command returned other than 0).. Show Sample Output


    -2
    prefix="10.0.0" && for i in `seq 25`; do ping -c 1 $prefix.$i &> /dev/null && echo "Answer from: $prefix.$i" ; done
    xeor · 2010-04-07 17:17:21 4
  • Some servers don't have ssh-copy-id, this works in those cases. It will ask for the destination server, this can be IP, hostname, or user@hostname if different from current user. Ssh keygen will let you know if a pubkey already exists on your system and you can opt to not overwrite it.


    -2
    echo 'Host or User@Host?:'; read newserver && ssh-keygen -N "" -t rsa -f ~/.ssh/id_rsa ; ssh $newserver cat <~/.ssh/id_rsa.pub ">>" ~/.ssh/authorized_keys ; ssh $newserver
    alf · 2010-05-07 06:24:53 4
  • Currently Facebook has updated their headers to display 127.0.0.1 but if you have saved e-mails from messages and FB related mail you can still reveal the IP. :) Tested on Mac OS X 10.6.3 Show Sample Output


    -2
    echo "X-Facebook: from zuckmail ([MTI3LjAuMC4x])" | cut -d \[ -f 2 | cut -d \] -f 1 | openssl base64 -d
    IsraelTorres · 2010-05-09 00:46:28 4
  • simple bash one liner to pass multiple arguments to command one by one. optional yes/no pipe at beginning of command Show Sample Output


    -2
    yes|for x in one two three; do echo result - $x; done
    Panikos · 2010-06-01 14:49:29 3
  • Instead of having someone else read you the Digg headlines, Have OSX do it. Requires Curl+Sed+Say. This could probably be easily modified to use espeak for Linux.


    -2
    IFS=`echo -en "\n\b"`; for i in $(curl http://feeds.digg.com/digg/container/technology/popular.rss | grep '<title>' | sed -e 's#<[^>]*>##g' | tail -n10); do echo $i; echo $i | sed 's/^/Did you hear about /g' | say; sleep 30; done
    echosedawk · 2010-06-07 22:16:19 4

  • -2
    for i in 192.168.1.{1..254} ; do if ping -c1 -w1 $i &>/dev/null; then echo $i alive; fi; done
    wiburg · 2010-06-12 18:38:36 3
  • ‹ First  < 54 55 56 57 58 >  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

most used commands in history (comprehensive)
Most of the "most used commands" approaches does not consider pipes and other complexities. This approach considers pipes, process substitution by backticks or $() and multiple commands separated by ; Perl regular expression breaks up each line using | or < ( or ; or ` or $( and picks the first word (excluding "do" in case of for loops) note: if you are using lots of perl one-liners, the perl commands will be counted as well in this approach, since semicolon is used as a separator

check open ports without netstat or lsof

Move a folder and merge it with another folder
This will move a folder and merge it with another folder which may contain duplicates. Technically it's just creating hardlinks of everything in the folder, and after it's done, delete the source (with rm -r source/ ) to complete the move. This is much faster than, for example, using rsync to merge folders which would actually copy the entire contents and so for a lot of files would take much longer. This uses macutils gcp port of cp so it can be used on osx/MacOS. If using in linux or some unix where cp includes the ability to create links with -l you can just use cp instead of gcp.

download a list of urls

Find the package that installed a command

Generate a random password 30 characters long

Generate a random left-hand password
Generates a random 8-character password that can be typed using only the left hand on a QWERTY keyboard. Useful to avoid taking your hand off of the mouse, especially if your username is left-handed. Change the 8 to your length of choice, add or remove characters from the list based on your preferences or kezboard layout, etc.

vi a new file with execution mode
$ vix /tmp/script.sh Open a file directly with execution permission. Put the function in your .bashrc You can also put this in your vimrc: $ command XX w | set ar | silent exe "!chmod +x %" | redraw! and open a new file like this: $ vi +XX /tmp/script.sh

Extract tarball from internet without local saving

Swap a file or dir with quick resotre
This lets you replace a file or directory and quickly revert if something goes wrong. For example, the current version of a website's files are in public_html. Put a new version of the site in public_html~ and execute the command. The names are swapped. If anything goes wrong, execute it again (up arrow or !!).


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: