Commands tagged bash (735)

  • Execute commands serially on a list of hosts. Each ssh connection is made in the background so that if, after five seconds, it hasn't closed, it will be killed and the script will go on to the next system. Maybe there's an easier way to set a timeout in the ssh options...


    0
    for host in $MYHOSTS; do ping -q -c3 $H 2>&1 1>/dev/null && ssh -o 'AllowedAuthe ntications publickey' $host 'command1; command2' & for count in 1 2 3 4 5; do sleep 1; jobs | wc -l | grep -q ^0\$ && continue; done; kill %1; done
    a8ksh4 · 2012-11-13 23:12:27 0
  • Generate a 18 character password from character set a-zA-Z0-9 from /dev/urandom, pipe the output to Python which prints the password on standard out and in crypt sha512 form. Show Sample Output


    1
    cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 18 | head -1 | python -c "import sys,crypt; stdin=sys.stdin.readline().rstrip('\n'); print stdin;print crypt.crypt(stdin)"
    cnyg · 2012-11-09 00:40:22 0
  • This will check if a user is logged in using ssh and will log out the user automatically after the specified time in seconds without data retrieval on the server side. Will work with bash and zsh so put it into your sourced shell file on the server side. Be aware that users can change this themselves as it's just a envoronment variable. Show Sample Output


    0
    if [ -n "$SSH_CONNECTION" ]; then export TMOUT=300; fi
    Testuser_01 · 2012-11-03 18:39:25 0
  • Put this in your zshrc, source it, then run 'pkill -usr1 zsh' to source it in all open terminals. Also works with bash. More info: http://www.reddit.com/r/commandline/comments/12g76v/how_to_automatically_source_zshrc_in_all_open/


    5
    trap "source ~/.zshrc" USR1
    ppaschka · 2012-11-03 07:24:03 1
  • simple table


    -1
    for k in `git branch -r|awk '{print $1}'`;do echo -e `git show --pretty=format:"%Cgreen%ci_%C(blue)%c r_%Cred%cn_%Creset" $k|head -n 1`$k;done|sort -r|awk -F"_" '{printf("%s %17s %-22s %s\n",$1,$2,$3,$4)}'
    varon · 2012-10-29 12:38:24 0
  • There is no need to use the shell or construct. Screen offers varius ways of detaching and reattaching. man screen and look for -[rRdD]. to create a named session: sdr moo hide: resume: sdr moo Show Sample Output


    -1
    alias sdr="screen -dR"
    tox2ik · 2012-10-22 21:46:26 0
  • Tries to avoid the fragile nature of scrapers by looking for user-input in the output as opposed to markup or headers on the web site. Show Sample Output


    0
    function ip-where { wget -qO- -U Mozilla http://www.ip-adress.com/ip_tracer/$1 | html2text -nobs -style pretty | sed -n /^$1/,/^$/p;}
    tox2ik · 2012-10-22 21:39:53 0
  • Tries to reattach to screen, if it's not available, creates one. created an alias "irc" for it, since sometimes i forget if there already is a screen session running with irssi, this way I avoid creating a new one by mistake.


    -2
    screen -r irc || screen -S irc irssi
    daneoshiga · 2012-10-19 12:12:54 1

  • 7
    . ~/.bashrc
    xamaco · 2012-10-13 09:07:02 1
  • Renames all files ending in "_test.rb" to "_spec.rb"


    0
    for i in `find -name '*_test.rb'` ; do mv $i ${i%%_test.rb}_spec.rb ; done
    olopopo · 2012-10-09 14:08:38 0
  • I doubt this works with other than bash, but then again, I havent tried. The 'yes' utility is very simple, it outputs a hell of a lot of 'y's to standard input. The '!!' command means 'the last command'. So this one-lines inputs a lot of y's into the last command, aggressively agreeing to everything. For instance, when doing apt-get.


    1
    yes | !!
    freck · 2012-10-05 10:09:39 0

  • 0
    . ~/.bashrc
    brandizzi · 2012-10-02 17:20:29 0
  • You may want to just use the shortcut "." instead of "source"


    1
    . ~/.bashrc
    DNSpyder · 2012-10-01 08:41:19 0
  • Any changes to BASH shell made in .bashrc will be active in the current terminal window from the moment you execute this command, ie. aliases, prompt settings etc. No need to restart terminal. (In BASH 'source' simile to 'eval' lets you generally execute any bunch of commands stacked in a text file).


    5
    source ~/.bashrc
    knoppix5 · 2012-10-01 08:30:19 0
  • Add this line to your ~/.gitconfig for a git alias "git brd" (i.e., brd = (br)anch+(d)ate) which sorts branches by date. Allows you to pass in limited "git branch" options such as "-r" (remote) or "-a" (all). (Note: forum added "$" prefix to command; obviously in gitconfig there is no "$" prefix.) Show Sample Output


    0
    brd = "! f() { for k in $(git branch $@ | sed 's/^..//; s/ .*//'); do echo "$(git log -1 --pretty='%Cgreen%ci %Cblue(%cr)%Creset ' $k) $k" ; done | sort -r; }; f"
    michael_n_1138 · 2012-09-28 10:20:51 0

  • 1
    git for-each-ref --sort='-authordate' --format='%(refname)%09%(authordate)' refs/heads | sed -e 's-refs/heads/--'
    ptitfred · 2012-09-25 09:05:09 0
  • Use meaningful exit codes change "source" to "cat" to view output instead of assigning Show Sample Output


    -1
    source <(egrep '^#define EX_.*' /usr/include/sysexits.h | sed -e 's/#define/declare -r/g' | sed 's/\//#/g' | sed -e 's/\s\{1,\}/ /g' | sed -e 's/ \([0-9]\)/\=\1/'g )
    fishdaemon · 2012-09-21 13:30:37 0
  • typeset command gives to stdout all the functions defined in a bash session, -f and -F switches are for: all functions names with body (-f) and all functions names only (-F). Show Sample Output


    2
    typeset -f
    kLeZ · 2012-09-17 13:48:39 0
  • Had trouble with the other function, because of missing semicolons. (According to my bash on OS X)


    0
    function cdf () { [ -f $1 ] && { cd $(dirname $1); } || { cd $1 ; }; pwd; };
    Josso · 2012-09-08 10:50:58 1
  • This makes your commandlinefu.com's favorites appear as most recent commands in your history.


    5
    (cat ~/.bash_history;U='curl -s www.commandlinefu.com';$U/users/signin -c/tmp/.c -d'username=<USER>&password=<PASS>&submit=1'|$U/commands/favourites/json -b/tmp/.c|grep -Po 'nd":.*?[^\\]",'|sed -re 's/.*":"(.*)",/\1/g')>~/.h;HISTFILE=~/.h bash --login
    xenomuta · 2012-08-17 12:31:51 0
  • Helps when I'm editing a script and want to double check some commands without having to exit out of vi multiple times or having to use another terminal session.


    2
    :!bash
    CLIxBOBxBOM · 2012-08-13 17:13:53 3
  • This command attempts to attach to existing irssi session, if one exists, otherwise creates one. I use "irc" because I use different irc clients depending on what system I am working on. Consistency is queen.


    2
    alias irc="screen -D -R -S chatclient irssi"
    expelledboy · 2012-08-12 13:24:43 0
  • To use this comment you'll have to create a file entitled 'ignorelist' where you put the file name or pattern of the files you want to ignore. I used it for my maven project which generates the child project files in each folder so I can import them into eclipse. By adding these project files to the ignore list ensure they won't appear each time I run 'svn status'. Show Sample Output


    0
    for folder in $( find $( pwd ) -maxdepth 1 -type d | grep -v .svn ); do svn propset svn:ignore -F ignorelist ${folder}; done
    Highwayman · 2012-08-03 13:50:45 0
  • Depending on your Apache access log configuration you may have to change the sum+=$11 to previous or next awk token. Beware, usually in access log last token is time of response in microseconds, penultimate token is size of response in bytes. You may use this command line to calculate sum and average of responses sizes. You can also refine the egrep regexp to match specific HTTP requests. Show Sample Output


    0
    egrep '.*(("STATUS)|("HEAD)).*' http_access.2012.07.18.log | awk '{sum+=$11; ++n} END {print "Tot="sum"("n")";print "Avg="sum/n}'
    fanchok · 2012-07-27 12:18:29 0

  • 0
    eselect bashcomp enable --global $(eselect bashcomp list | sed -e 's/ //g'| cut -d']' -f2 | sed -e 's/\*//'| xargs)
    proteusx · 2012-07-20 22:01:08 1
  • ‹ First  < 6 7 8 9 10 >  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



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: