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.
Indeed, the file .cshrc is used by the C-shells upon login. If your default shell is /bin/bash you must add the alias to .bashrc. Some Linux distributions use a file named .alias, that in turn is sourced by .bashrc. For example, in my OpenSuSE box I have:
Code:
test -s ~/.alias && . ~/.alias || true
in my .bashrc, so that I can put the aliases in .alias and they will be available to my login shell as well. Notice that in bash the . (dot) is a built-in command which is the same as the source command, whereas the C-shells have source only.
The difference between sourcing and executing a script is that in the former the statements inside the script run in the current shell, so that all the variable, function and alias definitions are retained. In the latter the script starts (forks) its own process (subshell), all the definitions are local to the new process and they are lost upon exiting. This is the reason why all the configuration files like .cshrc or .bashrc are sourced and not executed.
I don't have a .alias file, or at least it doesn't appear when I type "ls -a" in the shell, so that I suppose that I have to add a line directly to the .baschrc file, but (sorry for the stupid question) how can I do that?
If I understood correctly, when I modify the .baschrc file, the change will apply every time that I start a shell, is that right?
I don't have a .alias file, or at least it doesn't appear when I type "ls -a" in the shell, so that I suppose that I have to add a line directly to the .baschrc file
Well, you can create it and add the suggested line, or check the content of your current .bashrc and see if there is something similar. Anyway, yes - the simplest thing is to add the alias definition in .bashrc itself.
Quote:
Originally Posted by Ashotti
but (sorry for the stupid question) how can I do that?
Not a stupid question (an answer can be stupid): if you sit in front of your computer and it's running a desktop manager (usually GNOME in ubuntu) you can open a terminal and issue:
Code:
gedit $HOME/.bashrc
This will open a simple editor in its own window, you can make the changes, save and quit. Directly in the terminal (I mean without a graphical user interface) you can try the vi editor, but sincerely it's not something a novice is supposed to do.
Quote:
Originally Posted by Ashotti
If I understood correctly, when I modify the .baschrc file, the change will apply every time that I start a shell, is that right?
Yes. Actually the login process is something more complicated. You may check the bash reference guide (here is the direct link to the Bash Startup Files paragraph) or the bash man page under the section INVOCATION for more details.
Take in mind that every change you make in a shell (defining an alias, a shell function or changing the value of an environment variable) is local to the current shell and it's lost when you close the shell session. In other words, settings made in a terminal don't reflect in other terminals. This is the reason why you need a file whose content is executed (actually sourced) every time you start a new shell session (that is every time you open a new terminal). Hope it's a bit more clear now!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.