So, it just goes to show that a simple google search could turn up an answer to most things. In this case, a shell function I felt was missing.
That is, I wanted to be able to cd into a directory, and then have the files listed automatically. I had attempted to try this myself. First thinking of trying an alias, then trying to write a shell script for it.
As I found out , and a forum poster pointed out, a shell script would print out the ls of the target directory, but the cd function would actually change the current working directory of the shell script, not the terminal that ran it. It might be possible to write a script to change the calling terminal's current working directory, but it is beyond my scripting skills.
So, after googling here is what I found.
Add to your ~/.bashrc ( or if you have one, ~/.bash_aliases ) file the line:
lcd() { cd ${1} ; ls ; }
To get a basic ls after a cd. Then restart your terminal, if you had one running, and give it a try.
Or if you are like me, you might want a more detailed ls after cd, so I implemented:
lcd() { cd ${1} ; ls -hl; }
Which has it list details about the directory with filesize listed in k, M or G sizes.
So, the googled idea is very elegant, and works well.
Good night, and good luck.
No comments:
Post a Comment