lsdir - A Shell Alias for Only Listing Directories
The Problem
When working in the terminal, you sometimes need to list only the directories in the current location. The standard ls
command shows both files and directories, which can be overwhelming in cluttered directories.
The command for listing only directories in the current location is ls -d */
(source) which is not simple to remember, especially if it’s not something that you do often.
The Solution: lsdir
lsdir
, an alias for only listing directories, which hopefully is easier to remember.
1. Open your .zshrc
or .bashrc
file:
For Zsh:
vim ~/.zshrc
For Bash:
vim ~/.bashrc
2. Click i
on your keyboard to go into editing mode in vim
3. Add the following line:
alias lsdir='ls -d */'
4. Save the file and reload your shell configuration:
For Zsh:
source ~/.zshrc
For Bash:
source ~/.bashrc
5. Try it
You’re done; Happy coding! 👾
Like what you're seeing? Subscribe below to recieve notifications of new posts ⬇️
Promise not to send more than 1 email per month (not counting subscription confirmation email) 👨💻
Updated: 27 October, 2024
Created: 13 September, 2024