The Linux Bash shell and aliases
I don’t know how many times I am in a directory that contains a huge amount of files and all I really wanted to do was just show the directories there. Since Linux isn’t my cuppa, so to speak, I always end up googling to find out what the syntax is, then perform the task and go on to forget it for the next time.
This time, I’m writing it down here so I won’t have to Google it anymore! :D
I found the idea over on another blog [ here ]. What I found more interesting was the comment section after the original post. The linux gurus really came up with all sorts of ways to do it. Some of the suggestions were even better than the original article itself!
Regardless, I decided to at least adopt something simple and easy to remember for me alone. Your mileage may vary as to what you prefer and I don’t begrudge you choosing another route.
Listing just directories:
ls -l | grep '^d'
Listing just files:
ls -l | grep -v '^d'
If you hover over the lines of code, you will be able to copy to clipboard as well as a few other things. It uses the zeroscript flash method to get around Adobe’s new flash restrictions on the clipboard contents.
The next thing is to not have to remember those commands, but to instead add them as handy alias to your bash profile. Ok, so where is my bash profile, you ask?
Edit your bash profile:
cd ~ edit .bash_profile
I found the perfect description [ here ] by username ‘jailbait’:
Different distributions use different names for the bash startup file. It could be .bash_profile, .bashrc, or .profile.
There is one of these default files for each user including root. Each user can edit his own startup file without needed root privileges. So look in /home/username and see what filename your distribution uses for a bash startup file and edit that.
Each distribution also has a universal default bash default file somewhere in /etc. In Debian it is called /etc/profile. Other distributions may give it a different name. You need to be root to edit this file. If you specify a default in both /etc/profile and your user bash startup file then the user file takes precedence.
Here is an explanation about how bash startup files work in Linux From Scratch:
Add the following lines:
alias lf="ls -l | grep -v '^d'" alias ldir="ls -l | grep '^d'"
Logout / Login and you will be good to go by using shorthand aliases of ‘ldir’ and ‘lf’ for directories and files respectively.
The llama approves :llama:
Comments are closed.