User Tools

Site Tools


tutorials:bash

This is an old revision of the document!


Bash

Sample configuration files and useful commands.

Sample Configuration Files

.bash_profile

# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

.bashrc (Mac OS X)

# .bashrc
# User specific aliases and functions
# set prompt, format = 'user@host[pwd]$ ', for example: 'chkuo@oak[~]$ '
PS1='\[\e[1;34m\]\u\[\e[0m\]\[\e[1;33m\]@\[\e[0m\]\[\e[1;31m\]\h\[\e[0m\][\w]\[\e[1;32m\]\$\[\e[0m\] '

# User specific environment and startup programs
export PATH="${PATH}:/usr/local/bin:~/bin:~/script"

# enable color support 
alias grep='grep --color=auto'

# shell command alias
alias .='pwd'
alias ..='cd ..'
alias cd..='cd ..'
alias l='ls -lFG'
alias lm='ls -lFG | more'
alias ll='ls -alFG | more'

.bashrc (Ubuntu)

# .bashrc
# User specific aliases and functions
# set prompt, format = 'user@host[pwd]$ ', for example: 'chkuo@oak[~]$ '
PS1='\[\e[1;34m\]\u\[\e[0m\]\[\e[1;33m\]@\[\e[0m\]\[\e[1;31m\]\h\[\e[0m\][\w]\[\e[1;32m\]\$\[\e[0m\] '

# User specific environment and startup programs
export PATH="${PATH}:/usr/local/bin:~/bin:~/script"

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    alias ls='ls --color=auto'
    #alias dir='dir --color=auto'
    #alias vdir='vdir --color=auto'

    alias grep='grep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias egrep='egrep --color=auto'
fi

# shell command alias
alias .='pwd'
alias ..='cd ..'
alias cd..='cd ..'
alias l='ls -lF'
alias lm='ls -lF | more'
alias ll='ls -alF | more'

Secure Shell (SSH)

Remote Access

To login:

$ ssh username@host.ip.address

To logout:

$ exit

Remote Reboot

In the case that you need to reboot a machine remotely, login through ssh and use the following command:

sudo shutdown -r now

SSH key

Generate key-pairs

ssh-keygen -t 'rsa' -b 2048

Auto-authentication

Append '~/.ssh/id_rsa.pub' to remote host '~/.ssh/authorized_keys'

Shell Scripts

Pack Up Directories

#!/bin/sh
for x
do
	echo "$x"
	tar -cf "$x.tar" "$x"
	gzip "$x.tar"
done

Disk permissions

Useful for checking eternal hard drive (in Mac OS X)

Check

sudo vsdbutil -c /Volumes/MyDrive

Enable

sudo vsdbutil -a /Volumes/MyDrive
tutorials/bash.1294678853.txt.gz · Last modified: 2011/01/11 01:00 by chkuo