Bash Startup Time: Find and Fix Slow Linux Shell Startup

Quick Linux Tip #125:

Question: Why does my bash shell take 3 seconds to start?

Try: PS4='+ $EPOCHREALTIME\011 ' bash -x -lic exit 2>&1 | awk '/^\+/{if (prev) print $2-prev, cmd; prev=$2; cmd=$3" "$4" "$5}' | sort -rn | head -10

Info: Times and sorts bash startup commands to isolate performance bottlenecks.

Examples:

  • $ time bash -lic exit  # Measure total shell startup duration
  • $ bash -lx 2>startup.log  # Output a complete startup execution trace to a file
  • $ bash --noprofile --norc  # Launch a clean shell bypassing all initialization files

Note: Common performance bottlenecks include heavy framework plugins, version managers (like NVM/RVM), and large completion scripts. Use lazy-loading functions or lightweight prompt engines to optimize load times.




LinuxTeck.com
linuxteck:~$ PS4='+ $EPOCHREALTIME\011 ' bash -x -lic exit 2>&1 | awk '/^\+/{if (prev) print $2-prev, cmd; prev=$2; cmd=$3" "$4" "$5}' | sort -rn | head -10
0.892341 source /etc/bash_completion.d/git
0.456234 /usr/bin/fasd --init auto
0.345123 nvm use default
0.234012 source /home/linuxteck/.rvm/scripts/rvm
0.123890 source /etc/bash_completion.d/docker
0.089234 export PATH=/usr/local/bin:/usr/bin
0.045123 alias ll='ls -la'
0.023456 source /etc/profile.d/colors.sh
0.012345 shopt -s checkwinsize
0.008901 HISTFILESIZE=10000
linuxteck:~$

PREVIOUS ARTICLE Quick Linux Tip #124: Linux Scheduled Tasks: Find Every Cron Job and Timer NEXT ARTICLE Quick Linux Tip #126: Linux Immutable File Attribute: Fix Files That Won't Delete
About John Britto

John Britto Founder & Chief-Editor @LinuxTeck. A Computer Geek and Linux Intellectual having more than 20+ years of experience in Linux and Open Source technologies.

View all posts by John Britto →

Leave a Reply

Your email address will not be published.