working on it ...

Filters

Explore Public Snippets

Sort by

Found 13k snippets matching: bash

    public by lbottaro  341350  3  7  1

    How to checkout the latest tag of a Git repository

    This simple bash script allows to automatically checkout your local git repository on the latest tagged version available on the remote repository. The script assumes to be run from your local repo. The command 'git rev-list --tags' lists the tags IDs in reverse chronological order, getting the very last one on top. The command 'git describe
    # Get new tags from the remote
    git fetch --tags
     
    # Get the latest tag name
    latestTag=$(git describe --tags `git rev-list --tags --max-count=1`)
     
    # Checkout the latest tag
    git checkout $latestTag  

    public by cghersi  264226  2  5  0

    Bash command to get current directory

    VAR_NAME=$(pwd)

    public by thepatrick  226053  2  4  0

    My .bashrc

    My .bashrc: .bashrc
    #~/.bashrc: executed by bash(1) for non-login shells
    
    #01;32m:
    #35 = magenta
    #34 = blue
    #32 = green
    #33 = yellow
    #31 = red
    #30 = black
    #29 = white
    
    DEFAULT_COLOR="33"
    
    if [ "$OSTYPE" == "darwin13" ]; then
    	DEFAULT_COLOR="29"
    fi
    if [ -f /etc/redhat-release ]; then
    	DEFAULT_COLOR="31"
    fi
    if [ -f /etc/debian_version ]; then
    	DEFAULT_COLOR="32"
    fi
    
    case "$TERM" in
    xterm-256color)
        PS1='[\[\033[${DEFAULT_COLOR};${DEFAULT_COLOR}m\]${USER}@\h\[\033[00m\]] \[\033[32;32m\]${PWD}\[\033[00m\]\$ '
        ;;
    xterm-color)
        PS1='\[\033[${DEFAULT_COLOR};${DEFAULT_COLOR}m\]${USER}@\h\[\033[00m\]:\[\033[32;32m\]${PWD}\[\033[00m\]\$ '
        ;;
    xterm-256color)
        PS1='\[\033[${DEFAULT_COLOR};${DEFAULT_COLOR}m\]${USER}@\h\[\033[00m\]:\[\033[32;32m\]${PWD}\[\033[00m\]\$ '
        ;;
    xterm*|rxvt*)
        PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'
        ;;
    *)
        ;;
    esac
    
    #Top 5 memory hogs
    function memh() {
      top -n 5 -o rprvt -l1 | tail -n 5 | awk '{ printf "%5d\t%-10s\t%4.1fMB\n", $1, $2, $(NF-3) }';
    }
     
    #Back Up and date
    function bkdate() {
      cp $1 $1.`date +%Y%m%d`;
    }
    
    # Add a directory to PATH if it exists
    function add_to_path() {
    	if [ -d $1 ]; then
    		PATH="$1":"${PATH}"
    	fi
    }
    
    add_to_path /usr/bin
    add_to_path /usr/sbin
    add_to_path /usr/local/bin
    add_to_path /usr/local/sbin
    add_to_path /Library/PostgreSQL8/bin
    add_to_path /usr/local/lib/erlang/lib/rabbitmq_server-1.4.0/sbin
    add_to_path ~/SourceCache/from-svn/depot_tools
    add_to_path ~/bin
    export PATH
    
    if [ -f /usr/bin/nano ]; then
    	export EDITOR="nano"
    fi
    
    if [ -f /usr/bin/pico ]; then
    	export EDITOR="pico"
    fi
    
    if [ -f /usr/local/bin/mate ]; then
        export EDITOR="mate -aw"
    fi
    
    alias lsl='ls -lFh'
    alias lsa='ls -laFh'
    
    # don't put duplicate lines in the history. See bash(1) for more options
    export HISTCONTROL=ignoredups
    
    # check the window size after each command and, if necessary,
    # update the values of LINES and COLUMNS.
    shopt -s checkwinsize
    
    if [ "$OSTYPE" == "darwin13" ]; then
    	alias getinfo='xcrun GetFileInfo'
    	alias screenback='/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine -background &'
    	alias top='top -u'
    fi
    if [ "$OSTYPE" == "linux-gnu" ]; then
    	if [ "$TERM" != "dumb" ]; then
    	    eval "`dircolors -b`"
    	    alias ls='ls --color=auto'
    	fi
    fi
    
    if [ -f /etc/bash_completion ]; then
        . /etc/bash_completion
    fi
    
    # Allow per-host customization
    if [ -f ~/.bashrc_local ]; then
        . ~/.bashrc_local
    fi
    
    if [ "`which git`!" != "!" ]; then
      alias tag-genocide='for tag in $(git tag | tr "\n" " "); do git tag -d $tag; done'
    fi
    
    if [ -f ~/.git-completion.sh ]; then
      . ~/.git-completion.sh
    fi
    
    function http(){
        curl http://httpcode.info/$1;
    }
    
    ### Added by the Heroku Toolbelt
    export PATH="/usr/local/heroku/bin:$PATH"
    
    
    

    public by lbottaro  4132  8  7  0

    Bin bash array set and looping

    This linux script sets a variable as array, then loops through all its items.
    #!/bin/bash
    
    my_users_list=( elem1 elem2 elem3 )
    
    for user in ${my_users_list[@]}
    do
      echo $user
    done

    public by lbottaro  7058  1  7  3

    Linux one liner bash code to detect file or directory from a given list

    This bash code shows how to detect if a given item in a list returned by a command is actually a file or a directory, without affecting the output format. In this case, xargs is used to pass the '{}' reference to a shell script executed for each line returned by the tree command.
    tree -if --noreport /home/ | xargs -I '{}' sh -c 'if [ -d {} ]; then echo "Dir {}"; else echo "File {}"; fi'  

    public by lbottaro  3589  1  7  0

    Bash one-liner to remove clearcase views in parallel

    This bash one liner script allows to remove all the Clearcase views that match some criteria in parallel. In this case views are listed by 'lsview -s' cleartool command, filtering with grep on specific . Note the '-s' option to get view name in short format. Once each view is returned, xargs command executes the cleartool 'rmview' command,
    cleartool lsview -s | grep <WORD> | xargs -I '{}' sh -c 'cleartool rmview -tag {} &'     

    public by maholtz  2190  1  6  3

    bash: loop over directory

    #!/bin/bash
    # rsync --progress -a -h --stats /example/folder/ /backup/
    FILES=/example/folder/*
    for f in $FILES
    do
        echo "Backup $(basename "$f")"
        # one folder after another
        rsync --progress -a -h --stats "$f/" "/backup/$(basename "$f")/"
    done
       

    public by TheMetaphysicalCrook  2427  1  5  0

    .dotfiles

    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif) [xquartz.sh](/kevinelliott/.dotfiles/blob/master/xquartz.sh) [I guess output is not really necessary here](/kevinelliott/.dotfiles/commit/cfecaff9f0a4af157e29712923ebd788768b7fdb) Jul 14, 2012 ### README.md # .dotfiles Dotfiles for your unix-like system. I've created thi
    From <https://github.com/kevinelliott/.dotfiles>:
    
    Skip to content
    
    [ ](https://github.com/)
    
    [Sign up](/join) [Sign in](/login?return_to=%2Fkevinelliott%2F.dotfiles)
    
    This repository
    
      * [Explore](/explore)
      * [Features](/features)
      * [Enterprise](https://enterprise.github.com/)
      * [Pricing](/pricing)
    
      * [ Watch ](/login?return_to=%2Fkevinelliott%2F.dotfiles) [ 2 ](/kevinelliott/.dotfiles/watchers)
      * [ Star ](/login?return_to=%2Fkevinelliott%2F.dotfiles) [ 13 ](/kevinelliott/.dotfiles/stargazers)
      * [ Fork ](/login?return_to=%2Fkevinelliott%2F.dotfiles) [ 8 ](/kevinelliott/.dotfiles/network)
    
    #  [kevinelliott](/kevinelliott)/**[.dotfiles](/kevinelliott/.dotfiles)** ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    
      * [ Code ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif) ](/kevinelliott/.dotfiles)
      * [ Issues ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif) ](/kevinelliott/.dotfiles/issues)
      * [ Pull requests ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif) ](/kevinelliott/.dotfiles/pulls)
    
      * [ Pulse ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif) ](/kevinelliott/.dotfiles/pulse)
      * [ Graphs ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif) ](/kevinelliott/.dotfiles/graphs)
    
    ### HTTPS clone URL
    
    ### Subversion checkout URL
    
    You can clone with 
    
    HTTPS or 
    
    Subversion. [ ](https://help.github.com/articles/which-remote-url-should-i-use)
    
    [ Download ZIP ](/kevinelliott/.dotfiles/archive/master.zip)
    
    My Unix-like dot files for my shells 
    
      * [ 52  commits ](/kevinelliott/.dotfiles/commits/master)
      * [ 1  branch ](/kevinelliott/.dotfiles/branches)
      * [ 0  releases ](/kevinelliott/.dotfiles/releases)
      * [ Fetching contributors ](/kevinelliott/.dotfiles/graphs/contributors)
    
      1. [ Shell 100.0% ](/kevinelliott/.dotfiles/search?l=bash)
    
    Shell
    
    [ ](/kevinelliott/.dotfiles/find/master) [ ](/kevinelliott/.dotfiles/compare)
    
    _Branch:_ master
    
    Switch branches/tags
    
      * Branches
      * Tags
    
    [ master  ](/kevinelliott/.dotfiles/tree/master)
    
    Nothing to show
    
    Nothing to show
    
    [.dotfiles](/kevinelliott/.dotfiles)/
    
    Latest commit [ 1691986 ](/kevinelliott/.dotfiles/commit/1691986eb0b25e58f304952b52686fcfb518f710) May 20, 2015 ![@kevinelliott](https://avatars1.githubusercontent.com/u/123112?v=3&s=40) [kevinelliott](/kevinelliott) [Stuff and things.](/kevinelliott/.dotfiles/commit/1691986eb0b25e58f304952b52686fcfb518f710)
    
    [Permalink](/kevinelliott/.dotfiles/tree/1691986eb0b25e58f304952b52686fcfb518f710)
    
    Failed to load latest commit information.
    
    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    [bin](/kevinelliott/.dotfiles/tree/master/bin)
    [Modify which service runs for redis.](/kevinelliott/.dotfiles/commit/7b21aaa3deedb103c4f84e8e0e830e79bac9ce9d)
    Nov 20, 2013
    
    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    [etc](/kevinelliott/.dotfiles/tree/master/etc)
    [Move to more modern bundle no-document, as well as some other little …](/kevinelliott/.dotfiles/commit/27a1845bc0182c46bfcb6776a033f6c3d68f1994)
    Dec 18, 2014
    
    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    [.gitmodules](/kevinelliott/.dotfiles/blob/master/.gitmodules)
    [added seinfeld for showing my last public github commit](/kevinelliott/.dotfiles/commit/f19f7005936211299ac7d5086e2bb2037dc61cfb)
    Nov 17, 2011
    
    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    [README.md](/kevinelliott/.dotfiles/blob/master/README.md)
    [updated readme](/kevinelliott/.dotfiles/commit/fe075f11280d33a9fb599bba34e6b86fd517aa79)
    Nov 17, 2011
    
    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    [aliases.sh](/kevinelliott/.dotfiles/blob/master/aliases.sh)
    [Stuff and things.](/kevinelliott/.dotfiles/commit/1691986eb0b25e58f304952b52686fcfb518f710)
    May 20, 2015
    
    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    [autojump.sh](/kevinelliott/.dotfiles/blob/master/autojump.sh)
    [Added autojump.](/kevinelliott/.dotfiles/commit/098717c8994bdb22b6fa03fbbfab8fc384565117)
    Jan 24, 2013
    
    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    [base.sh](/kevinelliott/.dotfiles/blob/master/base.sh)
    [Stuff and things.](/kevinelliott/.dotfiles/commit/1691986eb0b25e58f304952b52686fcfb518f710)
    May 20, 2015
    
    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    [bash_colors.sh](/kevinelliott/.dotfiles/blob/master/bash_colors.sh)
    [* Add node.js environment configuration](/kevinelliott/.dotfiles/commit/f366a165834ed0362ee9de57dda82d5ccf699c78)
    Jul 13, 2012
    
    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    [bash_completion.sh](/kevinelliott/.dotfiles/blob/master/bash_completion.sh)
    [Add support for git 2.1.x's bash completion and prompt support.](/kevinelliott/.dotfiles/commit/9589d4f36e6c8fb44e3089a2ff23baa8c975bc22)
    Oct 20, 2014
    
    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    [bash_path.sh](/kevinelliott/.dotfiles/blob/master/bash_path.sh)
    [Added /usr/local/sbin to the PATH for Homebrew.](/kevinelliott/.dotfiles/commit/0295513d7ff8f375094aea225f4bc35dcf4549c4)
    Aug 8, 2012
    
    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    [bash_prompt.sh](/kevinelliott/.dotfiles/blob/master/bash_prompt.sh)
    [Work to move to chruby instead of rvm. Unfortunately chruby auto chan…](/kevinelliott/.dotfiles/commit/d01505606cdc97c9f540cbf10aeff6f6584dc3db)
    Jul 21, 2013
    
    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    [control.sh](/kevinelliott/.dotfiles/blob/master/control.sh)
    [Add control script and initialization in order to be able to start/st…](/kevinelliott/.dotfiles/commit/06453d3247d85dd97b50a39dcfa8501a16b6b985)
    Jul 18, 2012
    
    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    [docker.sh](/kevinelliott/.dotfiles/blob/master/docker.sh)
    [Add docker script.](/kevinelliott/.dotfiles/commit/48464bbc395a298ec9bce647f0e39a43a92d46a3)
    Jul 30, 2014
    
    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    [editor.sh](/kevinelliott/.dotfiles/blob/master/editor.sh)
    [Add control script and initialization in order to be able to start/st…](/kevinelliott/.dotfiles/commit/06453d3247d85dd97b50a39dcfa8501a16b6b985)
    Jul 18, 2012
    
    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    [git.sh](/kevinelliott/.dotfiles/blob/master/git.sh)
    [Work to move to chruby instead of rvm. Unfortunately chruby auto chan…](/kevinelliott/.dotfiles/commit/d01505606cdc97c9f540cbf10aeff6f6584dc3db)
    Jul 22, 2013
    
    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    [go.sh](/kevinelliott/.dotfiles/blob/master/go.sh)
    [Stuff and things.](/kevinelliott/.dotfiles/commit/1691986eb0b25e58f304952b52686fcfb518f710)
    May 20, 2015
    
    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    [heroku.sh](/kevinelliott/.dotfiles/blob/master/heroku.sh)
    [* Add node.js environment configuration](/kevinelliott/.dotfiles/commit/f366a165834ed0362ee9de57dda82d5ccf699c78)
    Jul 13, 2012
    
    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    [install.sh](/kevinelliott/.dotfiles/blob/master/install.sh)
    [Add .gemrc file.](/kevinelliott/.dotfiles/commit/e72b9dbc4063516c08a7b4b542c53fac53da3481)
    Oct 28, 2014
    
    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    [node.sh](/kevinelliott/.dotfiles/blob/master/node.sh)
    [* Add node.js environment configuration](/kevinelliott/.dotfiles/commit/f366a165834ed0362ee9de57dda82d5ccf699c78)
    Jul 13, 2012
    
    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    [rails.sh](/kevinelliott/.dotfiles/blob/master/rails.sh)
    [Stuff and things.](/kevinelliott/.dotfiles/commit/1691986eb0b25e58f304952b52686fcfb518f710)
    May 20, 2015
    
    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    [ruby.sh](/kevinelliott/.dotfiles/blob/master/ruby.sh)
    [Comment out unnecessary RVM ruby version override. This now occurs pr…](/kevinelliott/.dotfiles/commit/6034c28f6c04d12129187c4e008af2c792cfd6cc)
    Oct 28, 2014
    
    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    [xquartz.sh](/kevinelliott/.dotfiles/blob/master/xquartz.sh)
    [I guess output is not really necessary here](/kevinelliott/.dotfiles/commit/cfecaff9f0a4af157e29712923ebd788768b7fdb)
    Jul 14, 2012
    
    ###  README.md 
    
    # .dotfiles
    
    Dotfiles for your unix-like system. I've created this little repository to setup my OSX development machine. You're free to clone this for your own use, or pull out items. Definitely fork this and make your own repository, and submit pull requests if you've made something cleaner or more useful. I love seeing what other people do to optimize their shells, and I'm constantly looking for general productivity improvements.
    
    # Install
    
    To install, you will be cloning this repository into ~/.dotfiles.
        
        cd ~
        git clone git@github.com:kevinelliott/.dotfiles.git
        
    
    Then you will activate the .dotfiles by including the following line to ~/.bash_profile
        
        source ~/.dotfiles/base.sh
        
    
    # Credits
    
    Thanks to @drnic for his own .dotfiles repository for inspiration and the idea for how to set this up. Look at his repositories if you'd like to see some other examples for how to do this.
    
    # Copyright
    
    Copyright © 2011 Kevin Elliott
    
    Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
    
    The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
    
    THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    
      * [Status](https://status.github.com/)
      * [API](https://developer.github.com)
      * [Training](https://training.github.com)
      * [Shop](https://shop.github.com)
      * [Blog](https://github.com/blog)
      * [About](https://github.com/about)
      * [Pricing](https://github.com/pricing)
    [ ](https://github.com)
    
      * (C) 2015 GitHub, Inc.
      * [Terms](https://github.com/site/terms)
      * [Privacy](https://github.com/site/privacy)
      * [Security](https://github.com/security)
      * [Contact](https://github.com/contact)
      * [Help](https://help.github.com)
    
    Something went wrong with that request. Please try again. 
    
    You signed in with another tab or window. [Reload]() to refresh your session. You signed out in another tab or window. [Reload]() to refresh your session.
    

    public by lbottaro  7125  2  8  0

    Setting a Clearcase view and run command remotely via SSH

    This bash script allows user to set a IBM Rational Clearcase view on a remote machine and run a script on it via ssh.
    #!/bin/tcsh -e
    # Script to execute a cmd or script remotely via ssh on a target machine
    
    echo Executing make script: $0
    echo Make targets: \"$*\"
    echo Working directory: $PWD
    set _CLEARCASE_VIEW = `cleartool pwv -short -setview`
    echo Set view: "$_CLEARCASE_VIEW"
    
    # check build server
    if ( $?BUILDHOST == 0 ) then
      echo "Error: variable BUILDHOST not set, build aborted."
      exit -1
    endif
    
    # check clearcase view
    if ( "$_CLEARCASE_VIEW" == "** NONE **" ) then
      echo "Error: ClearCase view not set, build aborted."
      exit -1
    endif
    
    # script parameters check...
    if ( "$1" == "" ) then
      echo "Error: missing 1st param!"
      echo "Eg: ./myscript par1 par2"
      exit -1
    endif  
    
    if ( "$1" == "" ) then
      echo "Error: missing 1st param!"
      echo "Eg: ./myscript par1 par2"
      exit -1
    endif  
    
    # create remote script
    set remote_script=$PWD/.${USER}@${HOST}-`basename $0`
    rm -rf $remote_script
    echo "myscript $1 $2" > $remote_script
    echo "rm -rf $remote_script" >> $remote_script
    chmod a+x $remote_script
    
    # exec script in the current view on the build server
    echo Executing build script: $remote_script
    echo via SSH on Host: $BUILDHOST
    echo -----
    cat $remote_script
    echo -----
    echo Starting remote build...
    ssh $BUILDHOST cleartool setview -exec $remote_script $_CLEARCASE_VIEW
    

    public by lbottaro  3246  9  7  1

    How to grep the results of find using -exec in Linux

    This Linux one line command is useful when you want to grep the output of a find. The concatenation of grep and find is done via -exec parameter.
    find . -name *.xml -exec grep -e my_grep_data {} \; -print
                            
    • Public Snippets
    • Channels Snippets