Created
July 18, 2025 07:49
-
-
Save jee-r/aae00f2383b11a3f730be525892f8f44 to your computer and use it in GitHub Desktop.
My bashrc for Fedora server
This file contains hidden or 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
| # ~/.bashrc: Fedora server administration configuration | |
| # Source global definitions | |
| if [ -f /etc/bashrc ]; then | |
| . /etc/bashrc | |
| fi | |
| # User specific environment | |
| if ! [[ "$PATH" =~ "$HOME/.local/bin:$HOME/bin:" ]] | |
| then | |
| PATH="$HOME/.local/bin:$HOME/bin:$PATH" | |
| fi | |
| export PATH | |
| # Uncomment the following line if you don't like systemctl's auto-paging feature: | |
| # export SYSTEMD_PAGER= | |
| # If not running interactively, don't do anything | |
| [[ $- != *i* ]] && return | |
| # ======================================== | |
| # HISTORY - Optimized configuration | |
| # ======================================== | |
| # History size | |
| HISTSIZE=10000 | |
| HISTFILESIZE=20000 | |
| # History options | |
| shopt -s histappend # Append to history instead of overwriting | |
| shopt -s cmdhist # Multi-line commands on single line | |
| HISTCONTROL=ignoreboth:erasedups # Ignore duplicates and lines starting with space | |
| HISTIGNORE="ls:ll:la:cd:pwd:exit:clear:history" # Ignore basic commands | |
| HISTTIMEFORMAT="%F %T " # Timestamp format for history | |
| # Save history after each command | |
| PROMPT_COMMAND="history -a" | |
| # ======================================== | |
| # AUTOCOMPLETION - Advanced configuration | |
| # ======================================== | |
| # Enable bash completion | |
| 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 | |
| # Smart completion based on history | |
| bind '"\e[A": history-search-backward' | |
| bind '"\e[B": history-search-forward' | |
| # Case-insensitive completion | |
| bind "set completion-ignore-case on" | |
| # Show completion options immediately | |
| bind "set show-all-if-ambiguous on" | |
| # Cycle through possible completions | |
| bind "TAB:menu-complete" | |
| # ======================================== | |
| # COLORS - Prompt configuration | |
| # ======================================== | |
| # Enable colors | |
| force_color_prompt=yes | |
| # Color definitions | |
| RED='\033[0;31m' | |
| GREEN='\033[0;32m' | |
| YELLOW='\033[1;33m' | |
| BLUE='\033[0;34m' | |
| PURPLE='\033[0;35m' | |
| CYAN='\033[0;36m' | |
| WHITE='\033[1;37m' | |
| NC='\033[0m' # No Color | |
| # Function to get git status (optional) | |
| parse_git_branch() { | |
| git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' | |
| } | |
| # Colorized prompt with admin info | |
| if [ "$color_prompt" = yes ] || [ "$force_color_prompt" = yes ]; then | |
| # Prompt for root (red) | |
| if [ "$EUID" -eq 0 ]; then | |
| PS1="\[${RED}\][\[${WHITE}\]\u\[${RED}\]@\[${WHITE}\]\h\[${RED}\]:\[${WHITE}\]\w\[${RED}\]]\[${YELLOW}\]\$(parse_git_branch)\[${RED}\]# \[${NC}\]" | |
| else | |
| # Prompt for normal user (green/blue) | |
| PS1="\[${GREEN}\][\[${WHITE}\]\u\[${GREEN}\]@\[${WHITE}\]\h\[${GREEN}\]:\[${CYAN}\]\w\[${GREEN}\]]\[${YELLOW}\]\$(parse_git_branch)\[${GREEN}\]$ \[${NC}\]" | |
| fi | |
| else | |
| PS1='\u@\h:\w\$ ' | |
| fi | |
| # ======================================== | |
| # ALIASES - Useful commands for admin | |
| # ======================================== | |
| # Basic aliases with colors | |
| alias ls='ls --color=auto' | |
| alias ll='ls -alF --color=auto' | |
| alias la='ls -A --color=auto' | |
| alias l='ls -CF --color=auto' | |
| # Grep aliases with colors | |
| alias grep='grep --color=auto' | |
| alias fgrep='fgrep --color=auto' | |
| alias egrep='egrep --color=auto' | |
| # System monitoring aliases | |
| alias df='df -h' | |
| alias du='du -h' | |
| alias free='free -h' | |
| alias ps='ps aux' | |
| alias top='htop' | |
| alias ports='netstat -tuln' | |
| alias myip='curl -s https://ipinfo.io/ip' | |
| # User specific aliases and functions (keeping existing ones) | |
| alias rm='rm -i' | |
| alias cp='cp -i' | |
| alias mv='mv -i' | |
| # Navigation aliases | |
| alias ..='cd ..' | |
| alias ...='cd ../..' | |
| alias ....='cd ../../..' | |
| alias ~='cd ~' | |
| # Fedora-specific aliases for admin | |
| alias dnf='sudo dnf' | |
| alias dnfi='sudo dnf install' | |
| alias dnfu='sudo dnf upgrade' | |
| alias dnfs='dnf search' | |
| alias dnfinfo='dnf info' | |
| alias services='systemctl list-units --type=service' | |
| alias status='systemctl status' | |
| alias start='sudo systemctl start' | |
| alias stop='sudo systemctl stop' | |
| alias restart='sudo systemctl restart' | |
| alias enable='sudo systemctl enable' | |
| alias disable='sudo systemctl disable' | |
| alias reload='sudo systemctl reload' | |
| alias logs='journalctl -f' | |
| alias userlog='journalctl --user -f' | |
| # Log monitoring aliases | |
| alias tailf='tail -f' | |
| alias syslog='tail -f /var/log/messages' | |
| alias authlog='tail -f /var/log/secure' | |
| alias messages='tail -f /var/log/messages' | |
| # System monitoring aliases | |
| alias meminfo='cat /proc/meminfo' | |
| alias cpuinfo='cat /proc/cpuinfo' | |
| alias loadavg='cat /proc/loadavg' | |
| # ======================================== | |
| # USEFUL FUNCTIONS FOR ADMIN | |
| # ======================================== | |
| # Function to find large files | |
| findbig() { | |
| find ${1:-.} -type f -exec ls -la {} \; | sort -k5 -rn | head -10 | |
| } | |
| # Function to see processes consuming most memory | |
| psmem() { | |
| ps aux | sort -rn -k 4 | head -10 | |
| } | |
| # Function to see processes consuming most CPU | |
| pscpu() { | |
| ps aux | sort -rn -k 3 | head -10 | |
| } | |
| # Function to clean logs | |
| cleanlogs() { | |
| echo "Cleaning logs..." | |
| sudo journalctl --vacuum-time=7d | |
| sudo find /var/log -name "*.log" -type f -mtime +7 -exec rm -f {} \; | |
| } | |
| # Function for quick backup | |
| backup() { | |
| if [ $# -eq 0 ]; then | |
| echo "Usage: backup <file_or_directory>" | |
| return 1 | |
| fi | |
| tar -czf "${1%/}_$(date +%Y%m%d_%H%M%S).tar.gz" "$1" | |
| } | |
| # ======================================== | |
| # ENVIRONMENT VARIABLES | |
| # ======================================== | |
| # Default editor - nvim | |
| export EDITOR='nvim' | |
| export VISUAL='nvim' | |
| # Pagination | |
| export PAGER='less' | |
| export LESS='-R' | |
| # Security improvements | |
| export HISTCONTROL=ignoreboth | |
| umask 022 | |
| # ======================================== | |
| # ADVANCED FUNCTIONS | |
| # ======================================== | |
| # Function to update Fedora system | |
| update_system() { | |
| echo "Updating Fedora system..." | |
| sudo dnf upgrade -y | |
| sudo dnf autoremove -y | |
| sudo dnf clean all | |
| } | |
| # System information function | |
| system_info() { | |
| echo -e "${GREEN}=== System Information ===${NC}" | |
| echo -e "${YELLOW}Hostname:${NC} $(hostname)" | |
| echo -e "${YELLOW}Uptime:${NC} $(uptime | cut -d',' -f1 | cut -d' ' -f4-)" | |
| echo -e "${YELLOW}Load Average:${NC} $(uptime | cut -d',' -f3-5)" | |
| echo -e "${YELLOW}Memory Usage:${NC} $(free -h | grep Mem | awk '{print $3"/"$2}')" | |
| echo -e "${YELLOW}Disk Usage:${NC} $(df -h / | tail -1 | awk '{print $3"/"$2" ("$5" used)"}')" | |
| echo -e "${YELLOW}Users Connected:${NC} $(who | wc -l)" | |
| } | |
| # ======================================== | |
| # WELCOME MESSAGE | |
| # ======================================== | |
| # Welcome message for admin | |
| if [ "$EUID" -eq 0 ]; then | |
| echo -e "${RED}⚠️ You are logged in as ROOT! Be careful.${NC}" | |
| else | |
| echo -e "${GREEN}✅ Welcome, $(whoami)! Terminal configured for administration.${NC}" | |
| fi | |
| # Display system info on login (optional) | |
| # system_info | |
| # ======================================== | |
| # TERMINAL OPTIMIZATIONS | |
| # ======================================== | |
| # Typo correction | |
| shopt -s cdspell | |
| # Hostname completion | |
| shopt -s hostcomplete | |
| # Path expansion | |
| shopt -s expand_aliases | |
| # Job management | |
| set -o notify | |
| # Window size handling | |
| shopt -s checkwinsize | |
| echo -e "${CYAN}Admin bashrc configuration loaded successfully!${NC}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment