2.4. Hidden Files & Config#
Files starting with a dot (.) are hidden by default. These contain crucial configuration that controls how your shell and applications behave.
2.4.1. Why Files Start with Dot#
In Unix philosophy, simplicity is key. Instead of special “hidden” file attributes, files starting with . are simply not displayed by ls by default:
# Hide files - no special marking needed
$ touch .secret.txt
# Normal listing doesn't show it
$ ls -la
total 16
drwxr-xr-x 5 user group 160 Jan 10 14:30 .
drwxr-xr-x 10 user group 320 Jan 10 14:00 ..
-rw-r--r-- 1 user group 100 Jan 10 14:30 visible.txt
# Show hidden files with -a
$ ls -la
-rw-r--r-- 1 user group 0 Jan 10 14:30 .secret.txt
-rw-r--r-- 1 user group 100 Jan 10 14:30 visible.txt
This is simple, elegant, and reduces clutter—no special attributes needed!
2.4.2. Essential Shell Configuration Files#
2.4.2.1. Bash Startup Sequence#
When Bash starts, it reads files in this order:
┌─────────────────┐
│ Terminal Opens │
└────────┬────────┘
│
├─→ System files (in order):
│ 1. /etc/profile
│ 2. /etc/bash.bashrc
│
└─→ User files (in order):
1. ~/.bash_profile (login shell, reads ~/.bashrc)
2. ~/.bashrc (interactive shell)
3. ~/.bash_logout (on exit)
2.4.2.2. ~/.bashrc — Interactive Shell Configuration#
This runs every time you open an interactive shell:
$ cat ~/.bashrc
# Aliases
alias ll='ls -la'
alias grep='grep --color=auto'
alias python=python3
# Functions
function mkcd() {
mkdir -p "$1" && cd "$1"
}
# Environment variables
export EDITOR=vim
export HISTSIZE=10000
export PS1='\u@\h:\w$ '
# Shell options
set -o ignoreeof # Require more than one Ctrl+D to exit
shopt -s histappend # Append to history rather than replace
shopt -s checkwinsize # Update LINES/COLUMNS after each command
2.4.2.3. ~/.bash_profile — Login Shell Configuration#
Only runs when you log in (SSH, terminal app startup):
$ cat ~/.bash_profile
# Source ~/.bashrc if it exists
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
# Login-specific variables
export PATH="$PATH:$HOME/.local/bin"
export LANG=en_US.UTF-8
2.4.2.4. ~/.bash_logout#
Runs when you exit a login shell:
$ cat ~/.bash_logout
# Clear screen on logout
clear
2.4.2.5. Customizing Your Shell#
Note: This section introduces where
.bashrclives and what it contains. Chapter 5 (Bash Syntax and Variables) covers how to actually write and customize aliases, functions, and variables in your.bashrc. Once you learn about functions and variables, you’ll return here to make your shell truly personal.
The examples above show common configurations, but don’t modify your .bashrc until you understand:
How to write functions
Variable syntax and expansion
Quoting and escaping
You’ll learn all of this in Part II, then you can confidently enhance your shell environment.
2.4.3. Other Important Dotfiles#
2.4.3.1. ~/.ssh/#
SSH keys and configuration:
$ ls -la ~/.ssh/
drwxr-x--- 2 user group 4096 Jan 10 14:30 .
-rw------- 1 user group 1766 Jan 10 13:00 id_rsa
-rw-r--r-- 1 user group 391 Jan 10 13:00 id_rsa.pub
-rw-r--r-- 1 user group 820 Jan 10 14:30 config
-rw-r--r-- 1 user group 1024 Jan 10 14:30 known_hosts
# ~/.ssh/config example
$ cat ~/.ssh/config
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
Host myserver
HostName myserver.com
User deploy
Port 2222
Permissions are critical: chmod 700 ~/.ssh and chmod 600 ~/.ssh/id_rsa
2.4.3.2. ~/.gitconfig#
Git configuration:
[user]
name = Your Name
email = you@example.com
[core]
editor = vim
[alias]
st = status
ci = commit
co = checkout
br = branch
2.4.3.3. ~/.config/#
Modern applications store config here (XDG Base Directory standard):
$ ls ~/.config/
nvim/ # Neovim config
fish/ # Fish shell config
kitty/ # Terminal emulator config
2.4.3.4. ~/.local/#
User-installed programs and data:
$ ls ~/.local/
bin/ # User scripts and programs
share/ # Application data
include/ # Headers for libraries
lib/ # User libraries
2.4.3.5. ~/.gitignore_global#
Git ignore patterns for all repositories:
# Configure Git to use it
$ git config --global core.excludesfile ~/.gitignore_global
# Add patterns
$ cat ~/.gitignore_global
*.swp
*.swo
.DS_Store
.vscode/
2.4.4. Managing Dotfiles#
2.4.4.1. Backup and Restore#
# Backup all dotfiles
$ tar -czf ~/dotfiles-backup.tar.gz ~/.*
# Be careful not to include . and .. and .git
$ tar -czf ~/dotfiles-backup.tar.gz \
~/.bashrc ~/.bash_profile ~/.gitconfig ~/.vimrc
# Restore
$ tar -xzf ~/dotfiles-backup.tar.gz -C ~/
2.4.4.2. Version Control with Git#
Many developers keep dotfiles in a Git repository:
$ mkdir ~/dotfiles
$ cd ~/dotfiles
$ git init
# Add symlinks from home
$ ln -s ~/dotfiles/.bashrc ~/.bashrc
$ ln -s ~/dotfiles/.vimrc ~/.vimrc
$ ln -s ~/dotfiles/.gitconfig ~/.gitconfig
# Now all changes tracked in ~/dotfiles
$ git add -A
$ git commit -m "Initial dotfiles"
2.4.4.3. Finding and Modifying Dotfiles#
# List all dotfiles in home
$ find ~ -maxdepth 1 -type f -name '.*' -not -name '.DS_Store'
# Search for a configuration
$ grep -r "set number" ~/.config/
# View what processes use which config
$ strace -e openat bash -i 2>&1 | grep -E '\.(bashrc|bash_profile)'