Site icon New Generation Enterprise Linux

Stop cd-ing into directories only to realize they are empty

Environment & Shell Customization (Aliases/Functions/.Bashrc)

Stop cd-ing into directories only to realize they are empty

đź§© The Challenge

Most of us get into the habit of typing cd, then immediately following it up with ls just to see what the hell is actually in there. I’ve probably done this a million times and it’s a total waste of muscle memory.

đź’ˇ The Fix

Just rewrite the cd command as a shell function so it automatically lists the contents the moment you change directories. It turns a two-step dance into a single operation.

cd() {
builtin cd "$@" && ls -F
}

⚙️ Why It Works

By wrapping the builtin cd command in a function inside your .bashrc, you’re basically hooking into the shell to execute a list command immediately after a successful directory change. The -F flag is helpful because it adds those little trailing indicators for directories and executables so you know what you’re looking at instantly.

🚀 Pro-Tip: If your directories are massive, add –group-directories-first to that ls command so the output doesn’t look like a cluttered mess.

Linux Tips & Tricks | © ngelinux.com | 12/1/2026

0 0 votes
Article Rating
Exit mobile version