`
metaphy
  • 浏览: 344531 次
  • 性别: Icon_minigender_1
  • 来自: 大西洋底
社区版块
存档分类
最新评论

OS X bash profile

 
阅读更多
from: https://natelandau.com/my-mac-osx-bash_profile/
#  ---------------------------------------------------------------------------
#
#  Description:  This file holds all my BASH configurations and aliases
#
#  Sections:
#  1.  Environment Configuration
#  2.  Make Terminal Better (remapping defaults and adding functionality)
#  3.  File and Folder Management
#  4.  Searching
#  5.  Process Management
#  6.  Networking
#  7.  System Operations & Information
#  8.  Web Development
#  9.  Reminders & Notes
#
#  ---------------------------------------------------------------------------

#   -------------------------------
#   1. ENVIRONMENT CONFIGURATION
#   -------------------------------

#   Change Prompt
#   ------------------------------------------------------------
    export PS1="________________________________________________________________________________\n| \w @ \h (\u) \n| => "
    export PS2="| => "

#   Set Paths
#   ------------------------------------------------------------
    export PATH="$PATH:/usr/local/bin/"
    export PATH="/usr/local/git/bin:/sw/bin/:/usr/local/bin:/usr/local/:/usr/local/sbin:/usr/local/mysql/bin:$PATH"

#   Set Default Editor (change 'Nano' to the editor of your choice)
#   ------------------------------------------------------------
    export EDITOR=/usr/bin/nano

#   Set default blocksize for ls, df, du
#   from this: http://hints.macworld.com/comment.php?mode=view&cid=24491
#   ------------------------------------------------------------
    export BLOCKSIZE=1k

#   Add color to terminal
#   (this is all commented out as I use Mac Terminal Profiles)
#   from http://osxdaily.com/2012/02/21/add-color-to-the-terminal-in-mac-os-x/
#   ------------------------------------------------------------
#   export CLICOLOR=1
#   export LSCOLORS=ExFxBxDxCxegedabagacad


#   -----------------------------
#   2. MAKE TERMINAL BETTER
#   -----------------------------

alias cp='cp -iv'                           # Preferred 'cp' implementation
alias mv='mv -iv'                           # Preferred 'mv' implementation
alias mkdir='mkdir -pv'                     # Preferred 'mkdir' implementation
alias ll='ls -FGlAhp'                       # Preferred 'ls' implementation
alias less='less -FSRXc'                    # Preferred 'less' implementation
cd() { builtin cd "$@"; ll; }               # Always list directory contents upon 'cd'
alias cd..='cd ../'                         # Go back 1 directory level (for fast typers)
alias ..='cd ../'                           # Go back 1 directory level
alias ...='cd ../../'                       # Go back 2 directory levels
alias .3='cd ../../../'                     # Go back 3 directory levels
alias .4='cd ../../../../'                  # Go back 4 directory levels
alias .5='cd ../../../../../'               # Go back 5 directory levels
alias .6='cd ../../../../../../'            # Go back 6 directory levels
alias edit='subl'                           # edit:         Opens any file in sublime editor
alias f='open -a Finder ./'                 # f:            Opens current directory in MacOS Finder
alias ~="cd ~"                              # ~:            Go Home
alias c='clear'                             # c:            Clear terminal display
alias which='type -all'                     # which:        Find executables
alias path='echo -e ${PATH//:/\\n}'         # path:         Echo all executable Paths
alias show_options='shopt'                  # Show_options: display bash options settings
alias fix_stty='stty sane'                  # fix_stty:     Restore terminal settings when screwed up
alias cic='set completion-ignore-case On'   # cic:          Make tab-completion case-insensitive
mcd () { mkdir -p "$1" && cd "$1"; }        # mcd:          Makes new Dir and jumps inside
trash () { command mv "$@" ~/.Trash ; }     # trash:        Moves a file to the MacOS trash
ql () { qlmanage -p "$*" >& /dev/null; }    # ql:           Opens any file in MacOS Quicklook Preview
alias DT='tee ~/Desktop/terminalOut.txt'    # DT:           Pipe content to file on MacOS Desktop

#   lr:  Full Recursive Directory Listing
#   ------------------------------------------
alias lr='ls -R | grep ":$" | sed -e '\''s/:$//'\'' -e '\''s/[^-][^\/]*\//--/g'\'' -e '\''s/^/   /'\'' -e '\''s/-/|/'\'' | less'

#   mans:   Search manpage given in agument '1' for term given in argument '2' (case insensitive)
#           displays paginated result with colored search terms and two lines surrounding each hit.            Example: mans mplayer codec
#   --------------------------------------------------------------------
    mans () {
        man $1 | grep -iC2 --color=always $2 | less
    }

#   showa: to remind yourself of an alias (given some part of it)
#   ------------------------------------------------------------
    showa () { /usr/bin/grep --color=always -i -a1 $@ ~/Library/init/bash/aliases.bash | grep -v '^\s*$' | less -FSRXc ; }


#   -------------------------------
#   3. FILE AND FOLDER MANAGEMENT
#   -------------------------------

zipf () { zip -r "$1".zip "$1" ; }          # zipf:         To create a ZIP archive of a folder
alias numFiles='echo $(ls -1 | wc -l)'      # numFiles:     Count of non-hidden files in current dir
alias make1mb='mkfile 1m ./1MB.dat'         # make1mb:      Creates a file of 1mb size (all zeros)
alias make5mb='mkfile 5m ./5MB.dat'         # make5mb:      Creates a file of 5mb size (all zeros)
alias make10mb='mkfile 10m ./10MB.dat'      # make10mb:     Creates a file of 10mb size (all zeros)

#   cdf:  'Cd's to frontmost window of MacOS Finder
#   ------------------------------------------------------
    cdf () {
        currFolderPath=$( /usr/bin/osascript <<EOT
            tell application "Finder"
                try
            set currFolder to (folder of the front window as alias)
                on error
            set currFolder to (path to desktop folder as alias)
                end try
                POSIX path of currFolder
            end tell
EOT
        )
        echo "cd to \"$currFolderPath\""
        cd "$currFolderPath"
    }

#   extract:  Extract most know archives with one command
#   ---------------------------------------------------------
    extract () {
        if [ -f $1 ] ; then
          case $1 in
            *.tar.bz2)   tar xjf $1     ;;
            *.tar.gz)    tar xzf $1     ;;
            *.bz2)       bunzip2 $1     ;;
            *.rar)       unrar e $1     ;;
            *.gz)        gunzip $1      ;;
            *.tar)       tar xf $1      ;;
            *.tbz2)      tar xjf $1     ;;
            *.tgz)       tar xzf $1     ;;
            *.zip)       unzip $1       ;;
            *.Z)         uncompress $1  ;;
            *.7z)        7z x $1        ;;
            *)     echo "'$1' cannot be extracted via extract()" ;;
             esac
         else
             echo "'$1' is not a valid file"
         fi
    }


#   ---------------------------
#   4. SEARCHING
#   ---------------------------

alias qfind="find . -name "                 # qfind:    Quickly search for file
ff () { /usr/bin/find . -name "$@" ; }      # ff:       Find file under the current directory
ffs () { /usr/bin/find . -name "$@"'*' ; }  # ffs:      Find file whose name starts with a given string
ffe () { /usr/bin/find . -name '*'"$@" ; }  # ffe:      Find file whose name ends with a given string

#   spotlight: Search for a file using MacOS Spotlight's metadata
#   -----------------------------------------------------------
    spotlight () { mdfind "kMDItemDisplayName == '$@'wc"; }


#   ---------------------------
#   5. PROCESS MANAGEMENT
#   ---------------------------

#   findPid: find out the pid of a specified process
#   -----------------------------------------------------
#       Note that the command name can be specified via a regex
#       E.g. findPid '/d$/' finds pids of all processes with names ending in 'd'
#       Without the 'sudo' it will only find processes of the current user
#   -----------------------------------------------------
    findPid () { lsof -t -c "$@" ; }

#   memHogsTop, memHogsPs:  Find memory hogs
#   -----------------------------------------------------
    alias memHogsTop='top -l 1 -o rsize | head -20'
    alias memHogsPs='ps wwaxm -o pid,stat,vsize,rss,time,command | head -10'

#   cpuHogs:  Find CPU hogs
#   -----------------------------------------------------
    alias cpu_hogs='ps wwaxr -o pid,stat,%cpu,time,command | head -10'

#   topForever:  Continual 'top' listing (every 10 seconds)
#   -----------------------------------------------------
    alias topForever='top -l 9999999 -s 10 -o cpu'

#   ttop:  Recommended 'top' invocation to minimize resources
#   ------------------------------------------------------------
#       Taken from this macosxhints article
#       http://www.macosxhints.com/article.php?story=20060816123853639
#   ------------------------------------------------------------
    alias ttop="top -R -F -s 10 -o rsize"

#   my_ps: List processes owned by my user:
#   ------------------------------------------------------------
    my_ps() { ps $@ -u $USER -o pid,%cpu,%mem,start,time,bsdtime,command ; }


#   ---------------------------
#   6. NETWORKING
#   ---------------------------

alias myip='curl ip.appspot.com'                    # myip:         Public facing IP Address
alias netCons='lsof -i'                             # netCons:      Show all open TCP/IP sockets
alias flushDNS='dscacheutil -flushcache'            # flushDNS:     Flush out the DNS Cache
alias lsock='sudo /usr/sbin/lsof -i -P'             # lsock:        Display open sockets
alias lsockU='sudo /usr/sbin/lsof -nP | grep UDP'   # lsockU:       Display only open UDP sockets
alias lsockT='sudo /usr/sbin/lsof -nP | grep TCP'   # lsockT:       Display only open TCP sockets
alias ipInfo0='ipconfig getpacket en0'              # ipInfo0:      Get info on connections for en0
alias ipInfo1='ipconfig getpacket en1'              # ipInfo1:      Get info on connections for en1
alias openPorts='sudo lsof -i | grep LISTEN'        # openPorts:    All listening connections
alias showBlocked='sudo ipfw list'                  # showBlocked:  All ipfw rules inc/ blocked IPs

#   ii:  display useful host related informaton
#   -------------------------------------------------------------------
    ii() {
        echo -e "\nYou are logged on ${RED}$HOST"
        echo -e "\nAdditionnal information:$NC " ; uname -a
        echo -e "\n${RED}Users logged on:$NC " ; w -h
        echo -e "\n${RED}Current date :$NC " ; date
        echo -e "\n${RED}Machine stats :$NC " ; uptime
        echo -e "\n${RED}Current network location :$NC " ; scselect
        echo -e "\n${RED}Public facing IP Address :$NC " ;myip
        #echo -e "\n${RED}DNS Configuration:$NC " ; scutil --dns
        echo
    }


#   ---------------------------------------
#   7. SYSTEMS OPERATIONS & INFORMATION
#   ---------------------------------------

alias mountReadWrite='/sbin/mount -uw /'    # mountReadWrite:   For use when booted into single-user

#   cleanupDS:  Recursively delete .DS_Store files
#   -------------------------------------------------------------------
    alias cleanupDS="find . -type f -name '*.DS_Store' -ls -delete"

#   finderShowHidden:   Show hidden files in Finder
#   finderHideHidden:   Hide hidden files in Finder
#   -------------------------------------------------------------------
    alias finderShowHidden='defaults write com.apple.finder ShowAllFiles TRUE'
    alias finderHideHidden='defaults write com.apple.finder ShowAllFiles FALSE'

#   cleanupLS:  Clean up LaunchServices to remove duplicates in the "Open With" menu
#   -----------------------------------------------------------------------------------
    alias cleanupLS="/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user && killall Finder"

#    screensaverDesktop: Run a screensaver on the Desktop
#   -----------------------------------------------------------------------------------
    alias screensaverDesktop='/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine -background'

#   ---------------------------------------
#   8. WEB DEVELOPMENT
#   ---------------------------------------

alias apacheEdit='sudo edit /etc/httpd/httpd.conf'      # apacheEdit:       Edit httpd.conf
alias apacheRestart='sudo apachectl graceful'           # apacheRestart:    Restart Apache
alias editHosts='sudo edit /etc/hosts'                  # editHosts:        Edit /etc/hosts file
alias herr='tail /var/log/httpd/error_log'              # herr:             Tails HTTP error logs
alias apacheLogs="less +F /var/log/apache2/error_log"   # Apachelogs:   Shows apache error logs
httpHeaders () { /usr/bin/curl -I -L $@ ; }             # httpHeaders:      Grabs headers from web page

#   httpDebug:  Download a web page and show info on what took time
#   -------------------------------------------------------------------
    httpDebug () { /usr/bin/curl $@ -o /dev/null -w "dns: %{time_namelookup} connect: %{time_connect} pretransfer: %{time_pretransfer} starttransfer: %{time_starttransfer} total: %{time_total}\n" ; }


#   ---------------------------------------
#   9. REMINDERS & NOTES
#   ---------------------------------------

#   remove_disk: spin down unneeded disk
#   ---------------------------------------
#   diskutil eject /dev/disk1s3

#   to change the password on an encrypted disk image:
#   ---------------------------------------
#   hdiutil chpass /path/to/the/diskimage

#   to mount a read-only disk image as read-write:
#   ---------------------------------------
#   hdiutil attach example.dmg -shadow /tmp/example.shadow -noverify

#   mounting a removable drive (of type msdos or hfs)
#   ---------------------------------------
#   mkdir /Volumes/Foo
#   ls /dev/disk*   to find out the device to use in the mount command)
#   mount -t msdos /dev/disk1s1 /Volumes/Foo
#   mount -t hfs /dev/disk1s1 /Volumes/Foo

#   to create a file of a given size: /usr/sbin/mkfile or /usr/bin/hdiutil
#   ---------------------------------------
#   e.g.: mkfile 10m 10MB.dat
#   e.g.: hdiutil create -size 10m 10MB.dmg
#   the above create files that are almost all zeros - if random bytes are desired
#   then use: ~/Dev/Perl/randBytes 1048576 > 10MB.dat

分享到:
评论

相关推荐

    bash_profile:Mac OS X 的 .bash_profile 中有用的东西

    在Mac OS X系统中,`.bash_profile`是一个非常重要的配置文件,它位于用户的Home目录下(通常是`~/.bash_profile`)。这个文件是Bash shell启动时读取的配置脚本,用于设置环境变量、别名、路径以及执行一些自定义的...

    Mac OS X Terminal Basics v2.1.2

    用户可以通过修改`.bash_profile`或`.profile`等配置文件来定制shell环境,如设置路径、别名、提示符等,以提高工作效率。 #### 权限管理 权限管理是Unix系统安全的重要组成部分,通过设置文件和目录的所有权、...

    恢复MAC OS X的藏文件

    在Mac OS X中,隐藏文件是那些在Finder中不显示的文件,它们通常以"."开头,例如".bash_profile"。这些文件通常包含系统设置或用户配置信息,不应轻易修改。 **恢复隐藏文件的方法:** 1. **命令行恢复:** 使用...

    Bash的特性介绍BashInfo

    Bash是大多数Linux发行版默认的shell环境,同时也是Mac OS X等操作系统中的重要组成部分之一。本文将详细介绍Bash的一些关键特性和实用命令,帮助读者更好地理解和掌握Bash的使用方法。 #### 二、Bash与其它Shell的...

    os-x-power-user-guide:适用于高级用户的Mac OS X入门

    基于Unix的OS X具有bash shell,可通过Terminal应用程序进行访问 我建议切换到“ Pro”主题(“ Terminal &gt; Preference &gt; Profiles ) 您甚至可以设置~/.bash_profile (等效于.bashrc ) 文件系统也非常类似于...

    VsCode-AspNet5-OsX:在 Mac OS X 上使用 Visual Studio Code 和 ASP.NET 5

    对于 Mac OS X 上的 ASP.NET 5 下载并安装Visual Studio Code 说明: : 导航到根目录: cd ~/ 要创建 .bash_profile 文件: touch .bash_profile 要编辑现有的 .bash_profile 文件: open -e .bash_profile 还...

    TinyOS问题解决方法

    如果TinyOS的工具路径不在输出中,你可以通过编辑`~/.bashrc`或`~/.bash_profile`(取决于你的Shell)文件来添加。例如,如果TinyOS安装在`/usr/local/tinyos-2.x`,添加以下行: ```bash export PATH=$PATH:/usr/...

    Mac OS X下搭建nRF52832开发环境使用(GCC和Eclipse)

    ### Mac OS X 下搭建 nRF52832 开发环境使用 (GCC 和 Eclipse) #### 简介 本文档旨在指导如何在 Mac OS X 平台上为 nRF52832 芯片搭建一个高效且免费的开发环境。nRF52832 是一款基于 ARM Cortex-M4F 的高性能蓝牙...

    Mac OS X 下有关Android adb用法详解

    Mac OS X 下有关Android adb用法详解 一、什么是adb?  ADB的全称是Android Debug Bridge,用来调试Android程序的,白话点就是debug工具!  位置:一般下载Android的SDK时候在platform-tools中有adb程序。  二、...

    Mac OS系统安装golang教程

    go1.4.darwin-amd64-osx10.8.pkg go1.4 Mac OS X (x86 64-bit) PKG installer 设置环境变量 配置 GOROOT 和 GOPATH: 代码如下: 创建目录下的go文件夹: mkdir ~/go 下面的东西放到.bash_rc(也可能是.bash_profile...

    Mac OS jdk1.8安装包

    提供的文件名为`jdk-8u131-macosx-x64.dmg`,这是Oracle公司为Mac OS X 64位系统发布的JDK 1.8的一个具体版本。通常,你可以从Oracle官方网站的Java SE下载页面获取最新版本的JDK,但在这里我们已经有了特定版本的...

    dotfiles:Dotfiles-一组Mac OS X配置文件-专门设计为适合您的外壳寿命

    4. **bash**:Bourne-Again SHell,是一种广泛使用的Unix/Linux命令行解释器,也是Mac OS X的默认Shell。`.bash_profile`或`.bashrc`通常被用来定制Bash的启动行为。 5. **homebrew**:Homebrew是Mac OS X上的一个...

    jdk-7u80-macosx-x64.dmg 安装后的应用文件,只适用 Mac OS 系统

    标题“jdk-7u80-macosx-x64.dmg”指的是Oracle公司发布的Java Development Kit(JDK)的7u80版本,适用于Mac OS X 64位操作系统。JDK是用于开发和运行Java应用程序的重要工具集,它包含编译器、调试器、Java虚拟机...

    linux下安装tinyos 2.0

    在你的`.bashrc`或`.bash_profile`文件中添加以下行(根据你的TinyOS安装路径可能需要调整): ```bash export TOSROOT=/usr/local/tinyos-2.x export PATH=$PATH:$TOSROOT/tools/tinyos-2.x/tools ``` 保存并关闭...

    ros-install-osx:在OS X上安装ROS

    在OS X系统上安装ROS需要遵循特定的步骤,本文将详细介绍如何使用homebrew和rosdep工具来完成这个过程。 首先,我们需要了解homebrew。Homebrew是OS X上的一个包管理器,它允许用户轻松地安装命令行工具,包括许多...

    mac os jdk 最新版

    在Mac OS上,这通常涉及修改`~/.bash_profile`或`~/.zshrc`文件,添加对JDK目录的PATH引用。例如,添加以下行: ```bash export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk_version_here.jdk/Contents/Home ...

    Git-Beautify-For-MacOS终端:一套易于使用的配置文件,用于美化MacOS或OS X终端中的Git。 如果您发现很难在命令行上解析单色类型的杂物,则此设置可以帮助您驯服丑陋的bash野兽

    `Git-Beautify-For-MacOS`是一个专为MacOS(也兼容OS X)用户设计的解决方案,它提供了一套配置文件,旨在美化终端中的Git输出,使其更易读、更美观。 该工具的核心在于调整`Bash Shell`的设置,特别是通过修改`....

    Cent OS6.5 安装nodeJS(分分钟搞定)

    ### Cent OS6.5安装Node.js详解 #### 标题:Cent OS6.5 安装nodeJS(分分钟搞定) #### 描述:本文将详细介绍如何在Cent OS6.5系统上快速安装Node.js。 #### 标签:node npm #### 内容概述 在本文中,我们将...

    dotfiles:我的点文件 (OS X)

    在Mac OS X系统中,预设的shell是Bash,但用户可以选择切换到更现代化的Zsh,特别是自从macOS Catalina之后,Zsh成为了默认的shell。 压缩包文件名"dotfiles-master"暗示这是一个Git仓库的主分支,通常包含了一系列...

Global site tag (gtag.js) - Google Analytics