{"id":1820,"date":"2014-01-07T16:26:14","date_gmt":"2014-01-08T00:26:14","guid":{"rendered":"http:\/\/www.wellgolly.com\/?p=1820"},"modified":"2015-06-25T10:17:21","modified_gmt":"2015-06-25T17:17:21","slug":"bash","status":"publish","type":"post","link":"https:\/\/www.wellgolly.com\/?p=1820","title":{"rendered":"bash"},"content":{"rendered":"<p>I\u2019m playing around with bash and trying to understand how it thinks. I manage a bunch of servers so I wrote some aliases and functions to help me manage them. In my .profile or my .bash_profile I added a line to run the shell script that helps me do things. The last line is:<br \/>\n<code><br \/>\n    . ~\/.bash_config<br \/>\n<\/code><\/p>\n<p>If you make changes to this file, you can reload your profile and see the changes by running:<br \/>\n<code><br \/>\n    source ~\/.profile<br \/>\n<\/code><\/p>\n<p>I found a bunch of .bash_profile\u2019s online and used some of the ideas from them. The best one is from <a href=\"http:\/\/natelandau.com\/my-mac-osx-bash_profile\/\">Nathaniel Landau<\/a>. I kept his basic structure and lots of his aliases. I also added a bunch of stuff people might be interested in. I left in a lot of stuff that I later rewrote so people learning bash can see my thought process as I developed the script.<\/p>\n<p><code class='smaller'><br \/>\n#  ---------------------------------------------------------------------------<br \/>\n#  .bash_config<br \/>\n#  Description:  BASH configurations and aliases<br \/>\n#  Called from .profile or .bash_profile with . ~\/.bash_config<br \/>\n#  Sections:<br \/>\n#  1.   Environment Configuration<br \/>\n#  2.   Make Terminal Better (remapping defaults and adding functionality)<br \/>\n#  3.   File and Folder Management<br \/>\n#  4.   Searching<br \/>\n#  5.   Process Management<br \/>\n#  6.   Networking<br \/>\n#  7.   System Operations & Information<br \/>\n#  8.   Web Development<br \/>\n#  9.   Reminders & Notes<br \/>\n#<br \/>\n# Source: http:\/\/natelandau.com\/my-mac-osx-bash_profile\/<br \/>\n# Modified extensively - January 2014<br \/>\n#  ---------------------------------------------------------------------------<\/p>\n<p>#   -------------------------------<br \/>\n#   1.  ENVIRONMENT CONFIGURATION<br \/>\n#   -------------------------------<\/p>\n<p>#   Change Prompt<br \/>\n#   ------------------------------------------------------------<br \/>\n#   export PS1=\"________________________________________________________________________________<br \/>\n     \\n| \\w @ \\h (\\u) \\n| => \"<br \/>\n#   export PS2=\"| => \"<br \/>\n#\t\\e[ - Indicates the beginning of color prompt<br \/>\n#\tx;ym - Indicates color code. Use the color code values mentioned below.<br \/>\n#\t\\e[m - indicates the end of color prompt<br \/>\n#   \\e works on Ubuntu and in the OSX prompt, but not in echo commands on OSX use \\033 instead<br \/>\n# Normal Colors<br \/>\nBLACK='\\033[0;30m'        # Black<br \/>\nRED='\\033[0;31m'          # Red<br \/>\nGREEN='\\033[0;32m'        # Green<br \/>\nYELLOW='\\033[0;33m'       # Yellow<br \/>\nBLUE='\\033[0;34m'         # Blue<br \/>\nPURPLE='\\033[0;35m'       # Purple<br \/>\nCYAN='\\033[0;36m'         # Cyan<br \/>\nWHITE='\\033[0;37m'        # White<\/p>\n<p># Bold - Change 0; to 1;<br \/>\nB_BLACK='\\033[1;30m'      # Black<br \/>\nB_RED='\\033[1;31m'        # Red<br \/>\nB_GREEN='\\033[1;32m'      # Green<br \/>\nB_YELLOW='\\033[1;33m'     # Yellow<br \/>\nB_BLUE='\\033[1;34m'       # Blue<br \/>\nB_PURPLE='\\033[1;35m'     # Purple<br \/>\nB_CYAN='\\033[1;36m'       # Cyan<br \/>\nB_WHITE='\\033[1;37m'      # White<\/p>\n<p>NC='\\033[m'               # No Color - Reset color prompt<\/p>\n<p>#   Make it clear in the prompt which system I\u2019m on<br \/>\n#   localName=$(echo $HOSTNAME | cut -d.  -f 2); # Pull out the local part of the HOSTNAME<br \/>\nif [ \"$HOSTNAME\" = \"server\" ]; then<br \/>\n    hostColor=$B_RED;<br \/>\nelif [ \"$HOSTNAME\" = \"dave\" ]; then<br \/>\n    hostColor=$B_PURPLE;<br \/>\nelif [ \"$HOSTNAME\" = \"don\" ]; then<br \/>\n    hostColor=$B_CYAN;<br \/>\n# Mac $HOSTNAME has .local appended, cut it out<br \/>\nelif [ $(echo $HOSTNAME | cut -d.  -f 2) = \"local\" ]; then<br \/>\n    hostColor=$B_BLACK;<br \/>\nelse<br \/>\n    hostColor=$B_GREEN;<br \/>\nfi<br \/>\n    # Colors are in {} just to be clear, even though \\ is not a valid variable character.<br \/>\n    # NC doesn\u2019t need to be in {} since it is followed by a space.<br \/>\n    export PS1=\"${B_BLUE}\\u@${hostColor}\\h: ${B_GREEN}\\w$NC $ \"<\/p>\n<p>#   Set Paths<br \/>\n#   ------------------------------------------------------------<br \/>\n#    export PATH=\"$PATH:\/usr\/local\/bin\/\"<br \/>\n#    export PATH=\"$PATH:\/usr\/local\/git\/bin:\/sw\/bin\/:\/usr\/local\/bin:\/usr\/local\/:\/usr\/local\/sbin:\/usr\/local\/mysql\/bin\"<\/p>\n<p>#   Set Default Editor (change 'Nano' to the editor of your choice)<br \/>\n#   ------------------------------------------------------------<br \/>\n    export EDITOR=\/usr\/bin\/vim<br \/>\n    if [ \"$HOSTNAME\" = \"Dave\" ]<br \/>\n    then<br \/>\n        export EDITOR=\/usr\/bin\/nano<br \/>\n    fi<\/p>\n<p>#   Keep the history file around forever<br \/>\n    export HISTSIZE=10000<br \/>\n    export HISTFILESIZE=1000000000<\/p>\n<p>#   Set default blocksize for ls, df, du<br \/>\n#   from this: http:\/\/hints.macworld.com\/comment.php?mode=view&cid=24491<br \/>\n#   ------------------------------------------------------------<br \/>\n    export BLOCKSIZE=1k<\/p>\n<p>#   Add color to terminal<br \/>\n#   from http:\/\/osxdaily.com\/2012\/02\/21\/add-color-to-the-terminal-in-mac-os-x\/<br \/>\n#   ------------------------------------------------------------<br \/>\n    export CLICOLOR=1<br \/>\n#   export LSCOLORS=ExFxBxDxCxegedabagacad<\/p>\n<p>    export TZ=America\/Los_Angeles<\/p>\n<p>#   -----------------------------<br \/>\n#   2.  MAKE TERMINAL BETTER<br \/>\n#   -----------------------------<br \/>\n#   Override an alias with command e.g. command cp file1 file2<br \/>\n#   -i is the interactive flag, -v is the verbose flag<br \/>\nalias cp='cp -iv'                           # -i warns before overwriting<br \/>\nalias mv='mv -iv'                           # -i warns before overwriting<br \/>\nalias mkdir='mkdir -pv'                     # -p Create intermediate directories as required<br \/>\nmcd () { mkdir -p \"$1\" && cd \"$1\"; }        # Makes new Dir and jumps inside<\/p>\n<p>alias ll='ls -FGlAhp'                       #<br \/>\nalias less='less -FSRXc'                    # Preferred 'less' implementation<\/p>\n<p>cd() { builtin cd \"$@\"; ll; }               # Always list directory contents upon 'cd'<br \/>\nalias cd..='cd ..\/'                         # Go back 1 directory level (for fast typers)<br \/>\nalias ..='cd ..\/'                           # Go back 1 directory level<br \/>\nalias ...='cd ..\/..\/'                       # Go back 2 directory levels<br \/>\nalias .3='cd ..\/..\/..\/'                     # Go back 3 directory levels<br \/>\nalias .4='cd ..\/..\/..\/..\/'                  # Go back 4 directory levels<br \/>\nalias .5='cd ..\/..\/..\/..\/..\/'               # Go back 5 directory levels<br \/>\nalias .6='cd ..\/..\/..\/..\/..\/..\/'            # Go back 6 directory levels<br \/>\nalias ~=\"cd ~\"                              # Go Home<\/p>\n<p>alias which='type -all'                     # Find executables<br \/>\nalias path='echo -e ${PATH\/\/:\/\\\\n}'         # Echo all executable Paths<\/p>\n<p>#<br \/>\n#   OSX specific aliases and commands<br \/>\n#<br \/>\nalias f='open -a Finder .\/'                 # Opens current directory in OSX Finder<\/p>\n<p>trash () { command mv \"$@\" ~\/.Trash ; }     # Moves a file to the OSX trash<br \/>\nql () { qlmanage -p \"$*\" >& \/dev\/null; }    # Opens any file in OSX Quicklook Preview<br \/>\nalias DT='tee ~\/Desktop\/terminalOut.txt'    # Pipe content to file on OSX Desktop<\/p>\n<p>#   lr:  Full Recursive Directory Listing<br \/>\n#   ------------------------------------------<br \/>\nalias lr='ls -R | grep \":$\" | sed -e '\\''s\/:$\/\/'\\'' -e '\\''s\/[^-][^\\\/]*\\\/\/--\/g'\\'' -e '\\''s\/^\/   \/'\\'' -e '\\''s\/-\/|\/'\\'' | less'<\/p>\n<p>#   mans:   Search manpage given in agument '1' for term given in argument '2' (case insensitive)<br \/>\n#           displays paginated result with colored search terms and two lines surrounding each hit.<br \/>\n#           Example: mans mplayer codec<br \/>\n#   --------------------------------------------------------------------<br \/>\n    mans () {<br \/>\n        man $1 | grep -iC2 --color=always $2 | less<br \/>\n    }<br \/>\nalias mansearch='mans'<br \/>\n#   showa: to remind yourself of an alias (given some part of it)<br \/>\n#   ------------------------------------------------------------<br \/>\n    showa () { \/usr\/bin\/grep --color=always -i -a1 $@ ~\/Library\/init\/bash\/aliases.bash | grep -v '^\\s*$' | less -FSRXc ; }<\/p>\n<p>#   -------------------------------<br \/>\n#   3.  FILE AND FOLDER MANAGEMENT<br \/>\n#   -------------------------------<\/p>\n<p>zipf () { zip -r \"$1\".zip \"$1\" ; }          # Create a ZIP archive of a folder<br \/>\nalias numFiles='echo $(ls -1 | wc -l)'      # Count of non-hidden files in current dir<br \/>\nalias make1mb='mkfile 1m .\/1MB.dat'         # Creates a file of 1mb size (all zeros)<br \/>\nalias make5mb='mkfile 5m .\/5MB.dat'         # Creates a file of 5mb size (all zeros)<br \/>\nalias make10mb='mkfile 10m .\/10MB.dat'      # Creates a file of 10mb size (all zeros)<\/p>\n<p>#   extract:  Extract most known archives with one command<br \/>\n#   ---------------------------------------------------------<br \/>\n    extract () {<br \/>\n        if [ -f $1 ] ; then<br \/>\n          case $1 in<br \/>\n            *.tar.bz2)   tar xjf $1     ;;<br \/>\n            *.tar.gz)    tar xzf $1     ;;<br \/>\n            *.bz2)       bunzip2 $1     ;;<br \/>\n            *.rar)       unrar e $1     ;;<br \/>\n            *.gz)        gunzip $1      ;;<br \/>\n            *.tar)       tar xf $1      ;;<br \/>\n            *.tbz2)      tar xjf $1     ;;<br \/>\n            *.tgz)       tar xzf $1     ;;<br \/>\n            *.zip)       unzip $1       ;;<br \/>\n            *.Z)         uncompress $1  ;;<br \/>\n            *.7z)        7z x $1        ;;<br \/>\n            *)     echo \"'$1' cannot be extracted via extract()\" ;;<br \/>\n             esac<br \/>\n         else<br \/>\n             echo \"'$1' is not a valid file\"<br \/>\n         fi<br \/>\n    }<\/p>\n<p>#   ---------------------------<br \/>\n#   4.  SEARCHING<br \/>\n#   ---------------------------<\/p>\n<p>alias qfind=\"find . -name \"                 # qfind:    Quickly search for file<br \/>\nff () { \/usr\/bin\/find . -name \"$@\" ; }      # ff:       Find file under the current directory<br \/>\nffs () { \/usr\/bin\/find . -name \"$@\"'*' ; }  # ffs:      Find file whose name starts with a given string<br \/>\nffe () { \/usr\/bin\/find . -name '*'\"$@\" ; }  # ffe:      Find file whose name ends with a given string<\/p>\n<p>#   spotlight: Search for a file using MacOS Spotlight's metadata<br \/>\n#   -----------------------------------------------------------<br \/>\n    spotlight () { mdfind \"kMDItemDisplayName == '$@'wc\"; }<\/p>\n<p>#<br \/>\nalias h='history'                           # Shortcut for history<br \/>\nhist() { history | grep $1; }               # Find a command in the history, e.g hist man<\/p>\n<p>#   ---------------------------<br \/>\n#   5.  PROCESS MANAGEMENT<br \/>\n#   ---------------------------<\/p>\n<p>#   findPid: find out the pid of a specified process<br \/>\n#   -----------------------------------------------------<br \/>\n#       Note that the command name can be specified via a regex<br \/>\n#       E.g. findPid '\/d$\/' finds pids of all processes with names ending in 'd'<br \/>\n#       Without the 'sudo' it will only find processes of the current user<br \/>\n#   -----------------------------------------------------<br \/>\n    findPid () { lsof -t -c \"$@\" ; }<\/p>\n<p>#   memHogsTop, memHogsPs:  Find memory hogs<br \/>\n#   -----------------------------------------------------<br \/>\n    alias memHogsTop='top -l 1 -o rsize | head -20'<br \/>\n    alias memHogsPs='ps wwaxm -o pid,stat,vsize,rss,time,command | head -10'<\/p>\n<p>#   cpuHogs:  Find CPU hogs<br \/>\n#   -----------------------------------------------------<br \/>\n    alias cpu_hogs='ps wwaxr -o pid,stat,%cpu,time,command | head -10'<\/p>\n<p>#   topForever:  Continual 'top' listing (every 10 seconds)<br \/>\n#   -----------------------------------------------------<br \/>\n    alias topForever='top -l 9999999 -s 10 -o cpu'<\/p>\n<p>#   ttop:  Recommended 'top' invocation to minimize resources<br \/>\n#   ------------------------------------------------------------<br \/>\n#       Taken from this macosxhints article<br \/>\n#       http:\/\/www.macosxhints.com\/article.php?story=20060816123853639<br \/>\n#   ------------------------------------------------------------<br \/>\n    alias ttop=\"top -R -F -s 10 -o rsize\"<\/p>\n<p>#   my_ps: List processes owned by my user:<br \/>\n#   ------------------------------------------------------------<br \/>\n    my_ps() { ps $@ -u $USER -o pid,%cpu,%mem,start,time,bsdtime,command ; }<\/p>\n<p>#   ---------------------------<br \/>\n#   6.  NETWORKING<br \/>\n#   ---------------------------<\/p>\n<p>#   Log in to other systems<\/p>\n<p>id=$(who am i | cut -d\\  -f 1)<br \/>\nserver='192.168.194.220'<br \/>\ndave='192.168.201.11'<br \/>\ndon='192.168.102.113'<br \/>\npurple='purple.aserver.com'<\/p>\n<p># Update the list of servers if you add one. It is used on connect and scp functions<br \/>\nservers=(server dave don purple)<\/p>\n<p>#   The commented out aliases and functions are experiments with different ways to use aliases and functions<\/p>\n<p>#   With the id placed in the alias, not generalizable<br \/>\n#   alias server='ssh myloginid@192.168.194.220'<\/p>\n<p>#   Find the userID from login info<br \/>\n#   alias server='ssh $(who am i | cut -d\\  -f 1)@192.168.194.220'<\/p>\n<p>#   Make the userID an alias<br \/>\n#   alias myID='who am i | cut -d\\  -f 1'<br \/>\n#   alias server='ssh \"echo $(myID)\"@192.168.194.220'<br \/>\n#   alias server='ssh $(myID)@192.168.194.220'<\/p>\n<p>#   Make the userID a variable and use it later in the function<br \/>\n#   server() { id=$(who am i | cut -d\\  -f 1); ssh $id@192.168.194.220; }<\/p>\n<p>#   Make the userID a variable in the shell script and use it in an alias or function<br \/>\n#   $id can\u2019t be local since isn\u2019t called until the alias or function is invoked.<br \/>\n#   id=$(who am i | cut -d\\  -f 1)<br \/>\n#   alias server='ssh $id@192.168.194.220'<br \/>\n#   server()  { ssh $(myID)@192.168.194.220 ; }<\/p>\n<p># Using the select conditional to pick a server<br \/>\n# This example shows how a case statement and $REPLY can be used<br \/>\n# It can be generalized so that answers aren\u2019t hard coded<br \/>\nwhichserver() {<br \/>\n    # We don\u2019t need the list outside this function. Making it local assures that we don\u2019t clobber a previous alias with the same name<br \/>\n    local serverlist=(server dave don purple)<br \/>\n    PS3='Select a server. '<\/p>\n<p>    select srv in ${serverlist[@]} \"Quit\"; do     # the @ expands all the elements of the array into separate words<\/p>\n<p>        case \"$REPLY\" in<br \/>\n            # It would be nice if you could do this, but you can\u2019t put anything in a case statement that isn\u2019t one of the cases<br \/>\n            # arrayitem=$(( ${#serverlist[@]}+1 ))<br \/>\n            1 )<br \/>\n                echo \"Connecting to ${serverlist[$REPLY-1]}\"; ssh \"$id@$server\" ;;<br \/>\n            2 )<br \/>\n                echo \"Connecting to ${serverlist[$REPLY-1]}\"; ssh \"$id@$dane\" ;;<br \/>\n            3 )<br \/>\n                echo \"Connecting to ${serverlist[$REPLY-1]}\"; ssh \"$id@$dane\" ;;<\/p>\n<p>            # The last option is quit. (( )) is arithmetic evaluation. # counts the number of items in the array.<br \/>\n            $(( ${#serverlist[@]}+1 )) )<br \/>\n                echo \"No server selected.\";<br \/>\n        esac<\/p>\n<p>        break<\/p>\n<p>    done<br \/>\n}<\/p>\n<p>#   Here's the same code using an eval to run the alias<\/p>\n<p>connect() {<br \/>\n    # Requires an array called servers that has IP addresses or domain names.<br \/>\n    # It is defined when aliases are defined at the beginning of this script.<br \/>\n    if [ -z \"$1\" ]; then<\/p>\n<p>        PS3='Select a server. '<br \/>\n        select srv in ${servers[@]} \"Quit\"; do     # the @ expands all the elements of the array into separate words<\/p>\n<p>            if [ \"$REPLY\" -lt $(( ${#servers[@]}+1 )) ]; then<br \/>\n                    echo \"Connecting to ${servers[$REPLY-1]}\"<br \/>\n                    ssh ${!servers[$REPLY-1]}<br \/>\n             else<br \/>\n                    echo \"No server selected.\";<br \/>\n            fi<\/p>\n<p>            break<\/p>\n<p>        done<br \/>\n    else<br \/>\n        echo \"Connecting to $1\"<br \/>\n        ssh ${!1}<br \/>\n    fi<br \/>\n}<\/p>\n<p># Share .bash_config. Requires . ~\/.bash_config in .bash_profile<br \/>\nshare() {<\/p>\n<p>    # This works if you want to list out each server<br \/>\n    # scp .bash_config ${id}@${server}:.bash_config<br \/>\n    # scp .bash_config ${id}@${dane}:.bash_config<br \/>\n    # scp .bash_config ${id}@${dan}:.bash_config<\/p>\n<p>    for serv in \"${servers[@]}\"; do<br \/>\n        echo \"Connecting to $serv\"<br \/>\n        scp .bash_config ${id}@${!serv}:.bash_config<br \/>\n    done<br \/>\n}<\/p>\n<p>alias myip='curl ip.appspot.com'                    # Use Google\u2019s AppSpot site to find this machine\u2019s public facing IP Address<br \/>\nalias netCons='lsof -i'                             # Show all open TCP\/IP sockets<br \/>\nalias flushDNS='dscacheutil -flushcache'            # Flush out the DNS Cache<br \/>\nalias lsock='sudo \/usr\/sbin\/lsof -i -P'             # Display open sockets<br \/>\nalias lsockU='sudo \/usr\/sbin\/lsof -nP | grep UDP'   # Display only open UDP sockets<br \/>\nalias lsockT='sudo \/usr\/sbin\/lsof -nP | grep TCP'   # Display only open TCP sockets<br \/>\nalias ipInfo0='ipconfig getpacket en0'              # Get info on connections for en0<br \/>\nalias ipInfo1='ipconfig getpacket en1'              # Get info on connections for en1<br \/>\nalias openPorts='sudo lsof -i | grep LISTEN'        # All listening connections<br \/>\nalias showBlocked='sudo ipfw list'                  # All ipfw rules inc\/ blocked IPs<\/p>\n<p>#   ii:  display useful host related informaton<br \/>\n#   -------------------------------------------------------------------<br \/>\n#   -e     enable interpretation of backslash escapes<\/p>\n<p>    ii() {<br \/>\n        ## \\e works on Ubuntu but not recognized on OSX, must use \\033<br \/>\n        ## Didn\u2019t work since colors weren\u2019t defined. Now they are.<br \/>\n        ## local RED='\\033[0;31m'          # Red<br \/>\n        ## local NC=\"\\033[0m\"              # Color Reset<br \/>\n        echo -e \"\\nYou are logged on to $HOST\"<br \/>\n        echo -e \"\\nAdditional information: \" ; uname -a<br \/>\n        echo -e \"\\n${RED}Users logged on:${NC} \" ; w -h<br \/>\n        echo -e \"\\n${RED}Current date :${NC} \" ; date<br \/>\n        echo -e \"\\n${RED}Machine stats :${NC} \" ; uptime<br \/>\n        echo -e \"\\n${RED}Current network location :${NC} \" ; scselect<br \/>\n        echo -e \"\\n${RED}Public facing IP Address :${NC} \" ;myip<br \/>\n        #echo -e \"\\n${RED}DNS Configuration:${NC} \" ; scutil --dns<br \/>\n        echo<br \/>\n    }<\/p>\n<p>#   ---------------------------------------<br \/>\n#   7.  SYSTEMS OPERATIONS & INFORMATION<br \/>\n#   ---------------------------------------<\/p>\n<p>alias mountReadWrite='\/sbin\/mount -uw \/'    # mountReadWrite:   For use when booted into single-user<\/p>\n<p>#   cleanupDS:  Recursively delete .DS_Store files<br \/>\n#   -------------------------------------------------------------------<br \/>\n    alias cleanupDS=\"find . -type f -name '*.DS_Store' -ls -delete\"<\/p>\n<p>#   finderShowHidden:   Show hidden files in Finder<br \/>\n#   finderHideHidden:   Hide hidden files in Finder<br \/>\n#   -------------------------------------------------------------------<br \/>\n    alias finderShowHidden='defaults write com.apple.finder ShowAllFiles TRUE'<br \/>\n    alias finderHideHidden='defaults write com.apple.finder ShowAllFiles FALSE'<\/p>\n<p>#   cleanupLS:  Clean up LaunchServices to remove duplicates in the \"Open With\" menu<br \/>\n#   -----------------------------------------------------------------------------------<br \/>\n    alias cleanupLS=\"\/System\/Library\/Frameworks\/CoreServices.framework\/Frameworks\/LaunchServices.framework\/Support\/lsregister -kill -r -domain local -domain system -domain user && killall Finder\"<\/p>\n<p>#    screensaverDesktop: Run a screensaver on the Desktop<br \/>\n#   -----------------------------------------------------------------------------------<br \/>\n    alias screensaverDesktop='\/System\/Library\/Frameworks\/ScreenSaver.framework\/Resources\/ScreenSaverEngine.app\/Contents\/MacOS\/ScreenSaverEngine -background'<\/p>\n<p>#   ---------------------------------------<br \/>\n#   8.  WEB DEVELOPMENT<br \/>\n#   ---------------------------------------<\/p>\n<p>alias apacheEdit='sudo $EDITOR \/etc\/httpd\/httpd.conf'   # Edit httpd.conf<br \/>\nalias apacheRestart='sudo service apache2 restart'      # Restart Apache<br \/>\nalias mySQLRestart='sudo service mySQL restart'         # Restart mySQL<br \/>\nalias editHosts='sudo $EDITOR \/etc\/hosts'               # Edit \/etc\/hosts file<br \/>\nalias taile='tail -f \/var\/log\/php_error.log'            # Tails PHP error logs<br \/>\nalias apacheLogs=\"less +F \/var\/log\/apache2\/error_log\"   # Shows apache error logs<br \/>\nhttpHeaders () { \/usr\/bin\/curl -I -L $@ ; }             # httpHeaders:      Grabs headers from web page<\/p>\n<p>#   httpDebug:  Download a web page and show info on what took time<br \/>\n#   -------------------------------------------------------------------<br \/>\n    httpDebug () { \/usr\/bin\/curl $@ -o \/dev\/null -w \"dns: %{time_namelookup} connect: %{time_connect} pretransfer: %{time_pretransfer} starttransfer: %{time_starttransfer} total: %{time_total}\\n\" ; }<\/p>\n<p>#   ---------------------------------------<br \/>\n#   9.  REMINDERS & NOTES<br \/>\n#   ---------------------------------------<\/p>\n<p># Things I Can\u2019t Remember<br \/>\nticr() {<br \/>\n    echo -e \"\\n${B_PURPLE}Things I Can\u2019t Remember$NC\"<br \/>\n#   Ubuntu update commands<br \/>\n    echo -e \"\\n${B_BLACK}safe-upgrade is preferred$NC\"<br \/>\n    echo -e \"sudo aptitude safe-upgrade\"<\/p>\n<p>    echo -e \"\\n${B_BLACK}If safe-upgrade doesn\u2019t work you can do it manually$NC\"<br \/>\n    echo -e \"sudo apt-get update\"<br \/>\n    echo -e \"sudo apt-get upgrade\"<\/p>\n<p>    echo -e \"\\n${B_BLACK}Sometimes a reboot is required after an update$NC\"<br \/>\n    echo -e \"sudo reboot\"<\/p>\n<p>    echo -e \"\\n${B_BLACK}scp a file e.g public key$NC\"<br \/>\n    echo -e \"scp .\/.ssh\/RSA_KEY.pub myloginid@198.199.102.113:\/home\/myloginid\/.ssh\/authorized_keys\"<br \/>\n}<\/p>\n<p><\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I\u2019m playing around with bash and trying to understand how it thinks. I manage a bunch of servers so I wrote some aliases and functions to help me manage them. In my .profile or my .bash_profile I added a line to run the shell script that helps me do things. The last line is: . &hellip; <a href=\"https:\/\/www.wellgolly.com\/?p=1820\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">bash<\/span><\/a><\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-1820","post","type-post","status-publish","format-standard","hentry","category-coding"],"_links":{"self":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/1820","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1820"}],"version-history":[{"count":0,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/1820\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1820"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1820"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1820"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}