{"id":28311841,"url":"https://github.com/meibraransari/bash_profile","last_synced_at":"2025-07-30T00:37:15.343Z","repository":{"id":293577292,"uuid":"971078710","full_name":"meibraransari/bash_profile","owner":"meibraransari","description":"🚀 Powertools of bash snippets/aliases that will save your time on the terminal","archived":false,"fork":false,"pushed_at":"2025-05-19T03:27:14.000Z","size":17,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-23T09:47:22.241Z","etag":null,"topics":["bash","bash-completion","bash-profile","linux","shell-script"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/meibraransari.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-23T01:38:27.000Z","updated_at":"2025-05-20T01:41:39.000Z","dependencies_parsed_at":"2025-05-16T03:39:27.291Z","dependency_job_id":null,"html_url":"https://github.com/meibraransari/bash_profile","commit_stats":null,"previous_names":["meibraransari/bash_profile"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/meibraransari/bash_profile","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meibraransari%2Fbash_profile","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meibraransari%2Fbash_profile/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meibraransari%2Fbash_profile/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meibraransari%2Fbash_profile/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/meibraransari","download_url":"https://codeload.github.com/meibraransari/bash_profile/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meibraransari%2Fbash_profile/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267785955,"owners_count":24144124,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-29T02:00:12.549Z","response_time":2574,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash","bash-completion","bash-profile","linux","shell-script"],"created_at":"2025-05-24T14:17:38.184Z","updated_at":"2025-07-30T00:37:15.330Z","avatar_url":"https://github.com/meibraransari.png","language":"Shell","readme":"## 🎬 Video Demonstration\n[![Watch on Youtube](https://i.ytimg.com/vi/hPpfOEnI470/maxresdefault.jpg)](https://youtu.be/hPpfOEnI470)\n\n\n# 🚀 Understanding Bash Profile and Linux Startup\n\n## What is a Bash Profile? 🖥️\n\nA **Bash profile** is a configuration file that customizes your Bash shell environment when you start a terminal. It defines:\n- **Environment variables** (e.g., `PATH`, `HOME`).\n- **Aliases** (e.g., `alias ll='ls -la'`).\n- **Functions** or scripts for automation.\n- **Shell settings** (e.g., prompt colors, history size).\n\nThe key files are `~/.bash_profile` and `~/.bashrc`, and their use depends on the shell session type (login vs. non-login).\n\n## 🆚 .bashrc vs .bash_profile\n\nHere’s how they differ:\n\n| **Aspect**            | **.bashrc**                                  | **.bash_profile**                          |\n|-----------------------|----------------------------------------------|--------------------------------------------|\n| **Path**              | `~/.bashrc`                                  | `~/.bash_profile`                          |\n| **Purpose**           | Configures **non-login shells** (e.g., new terminal tab). | Configures **login shells** (e.g., SSH login). |\n| **When it Runs**      | Interactive, non-login sessions (e.g., terminal window). | Login sessions (e.g., GUI login, SSH).     |\n| **Typical Content**   | Aliases, functions, shell options (e.g., `PS1`). | Environment variables (`PATH`), startup scripts. |\n| **Example**           | `alias k='kubectl'`                          | `export PATH=\"$HOME/bin:$PATH\"`            |\n\n**Notes**:\n- Many users source `.bashrc` in `.bash_profile` to unify settings:\n  ```bash\n  # In ~/.bash_profile\n  if [ -f ~/.bashrc ]; then\n      source ~/.bashrc\n  fi\n  ```\n- If `.bash_profile` exists, Bash skips `.bashrc` in login shells unless sourced.\n- Some distros (e.g., Ubuntu) use `.profile` instead of `.bash_profile` if it’s absent.\n\n## 🥾 How Linux Loads Bash Files at Startup\n\nLinux loads Bash configs based on the shell session type. Here’s the process:\n\n1. **System-Wide Configs** 📜\n   - Loads `/etc/profile` (login shells) and `/etc/bash.bashrc` (non-login shells, if present).\n   - Sets system-wide defaults (e.g., `PATH`).\n\n2. **Login Shell Startup** 🔑\n   - For login sessions (e.g., SSH, GUI login, `bash --login`), Bash checks:\n     1. `~/.bash_profile` (if present).\n     2. `~/.bash_login` (if no `.bash_profile`).\n     3. `~/.profile` (if neither exists).\n   - `.bash_profile` typically sets environment variables and sources `.bashrc`.\n\n3. **Non-Login Shell Startup** 💻\n   - For new terminal windows or `bash` (non-login), Bash loads `~/.bashrc`.\n   - Applies aliases, functions, and prompt settings.\n\n4. **Graphical Environments** 🖼️\n   - GUI terminals (e.g., GNOME Terminal) often start non-login shells, loading only `.bashrc`.\n   - Some distros source `.profile` during GUI login for environment variables.\n\n5. **Custom Behavior** 🛠️\n   - Users can source files (e.g., `.bash_profile` sourcing `.bashrc`).\n   - Distro quirks (e.g., Ubuntu’s `.profile`) may change behavior.\n\n## 🛑 Common Gotchas\n- **No `.bash_profile`**: Bash falls back to `.profile`, which may not source `.bashrc`.\n- **PATH Overwrites**: Avoid duplicating `PATH` in both files.\n- **Terminal Settings**: Some terminals (e.g., VS Code) skip `.bash_profile`.\n\n## 🎉 Example Setup\nUnify settings across shells:\n- **~/.bash_profile**:\n  ```bash\n  # Environment variables\n  export PATH=\"$HOME/bin:$PATH\"\n  export EDITOR=\"vim\"\n\n  # Load .bashrc\n  if [ -f ~/.bashrc ]; then\n      source ~/.bashrc\n  fi\n  ```\n- **~/.bashrc**:\n  ```bash\n  # Aliases\n  alias ll='ls -la'\n  alias g='git'\n\n  # Custom prompt\n  PS1='\\u@\\h:\\w\\$ '\n  ```\n\n## 📝 Some Examples\n\n```bash\n#!/bin/bash\n###################################\n# Author: Ibrar Ansari\n# Date: 15-05-2025\n# Version: 1\n#\n# This is my profile script\n###################################\n\n########################\n## Installation steps ##\n########################\n# nano ~/.bash_profile\n# source ~/.bash_profile\nalias reload='source ~/.bash_profile \u0026\u0026 source ~/.bashrc'\n\n# Get ip info without typing\nipinfo(){\ncurl http://ipinfo.io/$1\n}\n\n# Install App just typing install appname\ninstall() {\n    sudo apt install \"$@\" -y\n}\n\n# Install basic app\ninstall_basic() {\n    sudo apt install -y vim nano tldr zip unzip vim jq screen htop atop iotop sysstat ioping tcptrack traceroute dnsutils pinfo speedtest-cli net-tools iptraf iptraf-ng ncdu gdu aptitude\n}\n\n\n# Get basic info without typing multiple commands, you can add or remove according to your need.\n\ninfo() {\n    echo \"Check Failed Login Attempts\"\n    sudo cat /var/log/auth.log | grep \"Failed password\"\n    \n    echo -e \"\\nSystem-related Error and Information Messages:\"\n    sudo cat /var/log/syslog | grep -E \"error|warning|info\"\n\n    echo -e \"\\nSystem Information:\"\n    last -n 5  # Show last 5 logins\n    uptime     # Display system uptime\n    df -h      # Show disk space usage\n}\n\n# Get basic info without typing multiple commands, you can add or remove according to your need.\n\nalias home='clear \u0026\u0026 cd /home/user \u0026\u0026 ls -alsh'  \nalias topcpu='ps -eo pcpu,args --sort=-pcpu | head -n 50 | awk '\"'\"'{printf(\"%13.2f%%\\t\", $1); print $2}'\"'\"''\nalias topmem='ps -eo \"rss,args\" --sort=-rss | head -n 50 | awk \"{hr=\\$1/1024; printf(\\\"%13.2fM\\t\\\", hr); print \\$2}\"'\n\n# Extract any type of compressed file\nextract () {\n    if [ -f $1 ] ; then\n      case $1 in\n        *.tar.bz2)   tar xjf $1     ;;\n        *.tar.gz)    tar xzf $1     ;;\n        *.bz2)       bunzip2 $1     ;;\n        *.rar)       unrar e $1     ;;\n        *.gz)        gunzip $1      ;;\n        *.tar)       tar xf $1      ;;\n        *.tbz2)      tar xjf $1     ;;\n        *.tgz)       tar xzf $1     ;;\n        *.zip)       unzip $1       ;;\n        *.Z)         uncompress $1  ;;\n        *.7z)        7z x $1        ;;\n        *)     echo \"'$1' cannot be extracted via extract()\" ;;\n         esac\n     else\n         echo \"'$1' is not a valid file\"\n     fi\n}\n\n# Restart Nginx after validating of it, it will print information of action.\nnt(){\n# Perform Nginx configuration test\nsudo nginx -t \u003e /dev/null 2\u003e\u00261\n# Check if the Nginx test failed\nif [ $? -ne 0 ]; then\n    echo \"Nginx test failed. Exiting script.\"\n    exit 1\nfi\necho \"Nginx test Passed.\"\n# If the test passed, reload Nginx\nsudo service nginx reload\n# Check if Nginx reload was successful\nif [ $? -eq 0 ]; then\n    echo \"Nginx service reloaded successfully.\"\nelse\n    echo \"Failed to reload Nginx service.\"\nfi\n}\n```\n\n## 🐳 Bash Profile to Manage Docker in anywhere\n\nHere are the my customized commands to manage docker in production, have a look and customize it if required.\n\n[👉 My Bash Profile](./bash_profile_examples/bash_profile)\n\n##### 🧠 Bash Profile Alias Notes\n\n\u003e ⚠️ **Note:** I will add more aliases in this bash profile based on my YouTube video topics.  \n\u003e Keeping this file updated will help automate repetitive terminal tasks and keep my workflow efficient! 🚀\n\n\n### 💼 Connect with me 👇👇 😊\n\n- 🔥 [**Youtube**](https://www.youtube.com/@DevOpsinAction?sub_confirmation=1)\n- ✍ [**Blog**](https://ibraransari.blogspot.com/)\n- 💼 [**LinkedIn**](https://www.linkedin.com/in/ansariibrar/)\n- 👨‍💻 [**Github**](https://github.com/meibraransari?tab=repositories)\n- 💬 [**Telegram**](https://t.me/DevOpsinActionTelegram)\n- 🐳 [**Docker**](https://hub.docker.com/u/ibraransaridocker)\n\n# Hit the Star! ⭐\n***If you are planning to use this repo for learning, please hit the star. Thanks!***\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeibraransari%2Fbash_profile","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmeibraransari%2Fbash_profile","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeibraransari%2Fbash_profile/lists"}