User Tools

Site Tools


bash_profile

This is an old revision of the document!


.bash_profile

.bash_profile
#~/.bash_profile
PersonalServer=usmifmomlnxv001
Host=$(hostname -s)
#
#
# Set our time-zone;
export TZ="America/New_York"
 
# Set defaults for the history file big and per machine.
HISTTIMEFORMAT="%F+%H:%M "
# Above doesn't change how the time is stored in the history
# file, only what it looks like with the history command.
HISTSIZE=11000
HISTDIR=${HOME}/.history
mkdir -p ${HISTDIR}
# Should exist, but just to be certain.
HISTFILE=${HISTDIR}/${Host}_history
 
# And a thing to make and save logs, use like;
# <some program> | LOG
# Output goes to screen and log.
LOGFILE=${HISTDIR}/${Host}_log
LOG () {
        tee -a ${LOGFILE}
}
 
function  HistOf() {
if [ $# -eq 0 ]; then
    Q=${Host}
else
    Q=${1}
fi
if [ -e ~/.history/${Q}_history ] ; then
    while IFS= read -r Line
    do if [[ "${Line}" =~ ^#[0-9] ]]
        then date -d "${Line//#/@}" +"# %Y-%m-%d+%H:%M:%S"
        else echo "${Line}"
        fi
    done < ~/.history/${Q}_history
else echo "No history for ${Q}".
    fi
}
function KeyBackup() {
        sudo tar -czvf /tmp/$(hostname -s)-ssh.tgz /etc/ssh/ssh_host_*
        cp /tmp/$(hostname -s)-ssh.tgz ~/.HostKeys/
        sudo rm /tmp/$(hostname -s)-ssh.tgz
}
 
alias less='less -r'
# Above shows ansi colors in log files.
 
# If we're on the home machine, syncronize with OneDrive.
if [ "${Host}" == "${PersonalServer}" ] ; then
        onedrive --sync
fi
 
alias ls='ls --time-style="+%Y-%m-%d+%H:%M:%S"'
alias ll='ls -l'
alias l='ls -altr'
alias Rel='cat /etc/*ease | grep PRETTY | cut -d "=" -f 2'
alias Diary='echo "${1}" >> ~/.history/$(hostname -s)_Diary_$(date +"%Y-%m-%d").txt'
alias Disks='lsblk -i -f -o type,size,fstype,name,mountpoint'
alias IP='ip a | grep -E "inet\ |inet6\ "'
alias Free='df -lBG --output=source,fstype,itotal,iused,ipcent,size,used,pcent,target -h | grep --color=never -E "^/|^Filesystem"'
alias Last='last -F | sed -n "1,/still running/{p}"'
alias P='ping -qAc3'
alias Users='last -Fx | less'
alias Root='ssh -i ~/.ssh/rtjmp -l root'
alias Count='last -Fw | cut -d " " -f1 | grep -vE "root|reboot|shutdown|runlevel|wtmp|^$" | sort | uniq -c | sort -rn'
alias Who='for User in $(last -Fw | grep -Ev "reboot|root|wtmp|runlevel|shutdown|^$" | cut -d " " -f1 | sort | uniq) ; do getent passwd ${User}; done | cut -d : -f 1,5,7'
alias Wttr='curl wttr.in/45103'
 
cat /etc/*ease | grep PRETTY | cut -d "=" -f 2
 
if [ -d ~/bin ]
then
        PATH="~/bin:${PATH}"
fi
 
if [ -d ~/.local/bin ]
then
        PATH="~/.local/bin:${PATH}"
fi
 
echo 'Aliases available =' $(alias | grep -E '^alias [A-Z]' | cut -c 7- | cut -d "=" -f1)
 
# And, finally, if we're on the home machine, run ~/.sshrc
if [ "${Host}" == "${PersonalServer}" ]
then
        if [ -e ~/.sshrc ]
                then
                        . ~/.sshrc
        fi
fi
 
# If dealing with systemctl unit files, export vim as editor if it exists;
if [ -e /usr/bin/vim ]
        then
        export SYSTEMD_EDITOR=/usr/bin/vim
fi
 
# For a multi-line prompt that can easily be copied and pasted;
export PS1="\n## Type ↓ ↓ ↓, User \u in \w on \h ##\n"
 
# vim:ts=4:sw=4
bash_profile.1785179665.txt.gz · Last modified: by steve