Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
on a previous linux system i was able to write this little "alias/script"
Code:
alias ll='ls -alhF'
change_dir_and_list
{
cd "$1" && ll
}
alias cd='change_dir_and_list'
and it worked perfectly, now the little "alias/script" doesn't work. if i remember right before i was running redhat enterprise 7. now my linux box is running centOS linux 6.7
can somebody tell me what i missed or if there's another way to do this?
my goal is so that everytime i cd a listing of all the files in that directory is shown
What exactly doesn't work? I had to change the first line as ll is already defined on my F25 system
Quote:
[tim@comedian ~]$ cat elias
alias lll='ls -alhF'
change_dir_and_list
{
cd "$1" && lll
}
alias cd='change_dir_and_list'
[tim@comedian ~]$ ./elias Downloads/
./elias: line 2: change_dir_and_list: command not found
./elias: line 4: lll: command not found
on a previous linux system i was able to write this little "alias/script"
Code:
alias ll='ls -alhF'
change_dir_and_list
{
cd "$1" && ll
}
alias cd='change_dir_and_list'
How are you using this "alias/script?"
If you are using it as a script, why are you even using an alias in it? That alias goes out of scope when the script completes.
If you want to use the alias or included function from the shell prompt, you must put in a startup file or at the least source it before trying to use it, or the shell will not no about it.
Before use, or add it somewhere to your shell's startup files:
Code:
source aliasfile
or
Code:
. aliasfile
The period is a synonym for the source builtin. I prefer using the more verbose source as it's obvious (I hate going through my distro's stock startup files to find stuff, as searching for a period is a PITA).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.