Created
January 26, 2024 06:53
-
-
Save CHERTS/1927ad30e28e48ba900c4e905ad2baf8 to your computer and use it in GitHub Desktop.
My .bachrc file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# If not running interactively, don't do anything | |
case $- in | |
*i*) ;; | |
*) return;; | |
esac | |
# Default editor | |
export EDITOR=vim | |
# Enable programmable completion features (you don't need to enable | |
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile | |
# sources /etc/bash.bashrc). | |
if ! shopt -oq posix; then | |
if [ -f /usr/share/bash-completion/bash_completion ]; then | |
. /usr/share/bash-completion/bash_completion | |
elif [ -f /etc/bash_completion ]; then | |
. /etc/bash_completion | |
fi | |
fi | |
# History settings | |
export HISTSIZE=10000 | |
export HISTFILESIZE=10000 | |
export HISTCONTROL=ignoreboth:erasedups | |
PROMPT_COMMAND='history -a' | |
export HISTIGNORE='ls:ps:rmhist*:history*' | |
export HISTTIMEFORMAT='%d.%m.%Y %H:%M:%S: ' | |
# User specific aliases and functions | |
alias rm='rm -i' | |
alias cp='cp -i' | |
alias mv='mv -i' | |
alias ll='ls -alF' | |
alias lr='ls -ltr' | |
alias l='ls -CF' | |
alias vi='vim' | |
alias pwg='pwgen -cnB 12 10 | while read PASS; do echo -n -e "$PASS\t"; echo -n "$PASS" | md5sum | cut -f1 -d" "; done' | |
# Custom cmd | |
PS1='\n\[\e[0;33m\][\D{%d.%m.%Y %H:%M:%S}] \[\e[01;31m\]\u@\h \[\e[1;34m\]\w\n\$ \[\e[0;32m\]\[\e[0m\]' | |
# 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 | |
# Show path (line by line). | |
path() { | |
old=$IFS | |
IFS=: | |
printf "%s\n" $PATH | |
IFS=$old | |
} | |
# Show all crontab task with collored output | |
allcrontab() { | |
for user in $(cut -d':' -f1 /etc/passwd); do | |
usercrontab=$(crontab -l -u ${user} 2>/dev/null) | |
if [ -n "${usercrontab}" ]; then | |
echo -e "${RED}====== Start crontab for user ${NC}${GREEN}${user}${NC} ${RED}======${NC}" | |
crontab -l -u ${user} | sed '/ *#/d; /^ *$/d' | |
echo -e "${RED}====== End crontab for user ${NC}${GREEN}${user}${NC} ${RED}========${NC}\n" | |
fi | |
done | |
for crond in $(ls -L1 /etc/cron.d); do | |
crondtab=$(cat "/etc/cron.d/${crond}" 2>/dev/null | egrep -Ev "^\s*(;|#|$)") | |
if [ -n "${crondtab}" ]; then | |
echo -e "${RED}====== Start cron.d ${NC}${GREEN}/etc/cron.d/${crond}${NC} ${RED}======${NC}" | |
echo "${crondtab}" | |
echo -e "${RED}====== End cron.d ${NC}${GREEN}/etc/cron.d/${crond}${NC} ${RED}======${NC}\n" | |
fi | |
done | |
} | |
# Show file content without comments | |
qcat() { | |
[[ $1 = '' ]] || [[ $1 = '-h' ]] || [[ $1 = '--help' ]] && echo "usage: qcat <filename>" && return 1 | |
if [ -f "$1" ]; then | |
cat "$1" | egrep -Ev "^\s*(;|#|$)" | |
else | |
echo "Error: File '"$1"' not found." | |
fi | |
} | |
my_ip() { | |
MY_IP=( $(ip addr 2>/dev/null | grep 'state UP' | awk -F':' '{print $2}' | sed 's/^[ \t]*//;s/[ \t]*$//') ) | |
for ((i=0; i<${#MY_IP[@]}; i++)); do | |
MY_ETH_IP=$(ip address show dev ${MY_IP[$i]} 2>/dev/null | grep 'inet' | grep -v 'inet6' | sed 's/^[ \t]*//;s/[ \t]*$//' | awk '{print $2}' | cut -f1 -d'/') | |
MY_ETH_INT=${MY_IP[$i]} | |
echo ${MY_ETH_INT}": "${MY_ETH_IP} | |
done | |
} | |
ii() { | |
echo -e "\nYou are on server ${RED}$HOSTNAME ($(hostname -f))" | |
echo -e "\nAdditional information:${NC}" ; uname -a | |
echo -e "\n${RED}Users work in this system:${NC}" ; w -h | |
echo -e "\n${RED}Date:${NC}" ; date '+%d.%m.%Y %H:%M:%S' | |
echo -e "\n${RED}Time elapsed since last reboot:${NC}" ; uptime| sed 's/^[ \t]*//;s/[ \t]*$//' | |
echo -e "\n${RED}RAM:${NC}" ; free | |
GW=$(ip route 2>/dev/null | awk '/default/ { print $3 }') | |
echo -e "\n${RED}Gateway:${NC}" ; echo ${GW} | |
echo -e "\n${RED}IP addresses on interfaces:${NC}" ; my_ip | |
echo | |
} | |
# Alias definitions | |
if [ -f ~/.bash_aliases ]; then | |
. ~/.bash_aliases | |
fi | |
# Source DBS definitions | |
if [ -f ~/.bashrc_dbs ]; then | |
. ~/.bashrc_dbs | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment