Intro and prolly a dumb question

wildkommander614

New Member
Joined
Sep 29, 2021
Messages
3
Reaction score
1
Credits
37
Hows it going everyone,
I'm enrolled in an intro Linux class at college and just at the beginning of my course. I am learning about making different changes to the environment and the difference between global and user changes, etc.

I have a super basic question, sorry if its retarded but I poked around everywhere and couldn't find the answer.
If for example i type the following command alias X=Y, where is this saved? I am just wanting to better understand the system, i searched everywhere. ubunutu 20.04.2 is what I am using.

Thanks
 


This sounds like a homework question!

@KGIII amirit? lol

Now. This is actually an interesting question and I'm not completely sure I have the answer (even though I've been a Linux engineer for around 25 years!)

So, the first thing I must ask is are you talking about where persistent aliases are stored, or temp / active aliases?

The reason I ask is you can set an alias (or environment variables) that are temporary or you can set them permanent. Just typing 'alias x=y' is a temporary alias. If you want to save it, you probably want to put the alias in your ~/.bash_profile. Though some distros like it to be put in other places, but .bash_profile will pretty much ensure it exists when you login. (if you're using bash shell)

That said, there are other places too and I wont' go through all of them because well. I'm a Redhat guy and that's what I generally know. (even though they can get funky at times too)

Now, an alias and an environment variable are sort of the same and different at the same time. If I just type "export myvar="KGIII is crazy!" and then type echo $myvar. That is stored in memory, but it won't be persistent. To make it persistent, I need to put that export command in my~/.bash_profile so it gets called everytime I login and bash is made my shell.

Once it's called, it's stored in memory for your shell. You can find your shell's pid (numeric ID) and go into /proc/<numeric pid id> and then cat the file called environ and you will see it.

That said, you are asking about alias and I don't believe aliases are stored here. Going back to my first sentence in this post. I don't actually know where they are stored. It's possible it reads it from a file each time, but I suspect it's stored in memory like the environment variables are. I just don't know where that is.

This is likely to piss me off and I will figure it out. Tonight, I don't know.

1632882528882.png
 
Ubuntu bash generally puts it in a .bashrc file that is in the home directory.
 
I went and took a bunch of tests shortly after I retired. I am not crazy.

This is unfortunate, because this means I have no excuses for my behavior!
 
G'day @wildkommander614 and welcome to linux.org :)

Have you Googled

linux where are aliases saved

If not, you haven't tried very hard.



Nope

Cheers

Chris Turner
wizardfromoz



I think you are confusing my friend and co-staffer with me ... I am the one who is certifiably crazy, and they made me an Admin ... go figure.

So dcbrown73 understands my question, I guess I worded it poorly. Yes I have googled quite a bit I assure you, I've got good googlefu and this is truly a last resort asking the forums.

Yes I understand that I can place an alias in .bashrc and have it work, I could then visibly see it in the file and all would be good. I could also put it in the /etc and have it global.

Specifically, I am asking if from terminal, I input command alias X=Y where is this alias being stored? What file does this go to? I would think that it would be stored in .bashrc, or maybe .profile. This isn't the case. I know its an arbitrary question but I am just wanting to better understand how the system works.

I think it would be easy to find the answer to this, I haven't learned yet how to conduct a search of the directories for a particular word but tried anyway with no success. I'm thinking couldn't someone who has grep skills just begin by:

Alias veryobscureword=A
grep for veryobscureword everywhere
location of veryobscureword

I appreciate everyone's response and patience, I'm just tinkering and its a lot of fun and im just learning. BTW this isn't a homework question lol this is just me being super curious.:)

Thanks everyone
 
So, when you type "alias x=y" at the command line, the alias you created is not persistent. Meaning, if you log out. It will be lost. It is only stored in memory in your session.

I've dug around a little, but I did not locate it in the procfs which is where you usually find environmental variables. That said, it might be under a different pid that is owned by the user within procfs, but I don't have time to go searching all the different pids owned by my specific user.

As I believe I noted above. If you type "env" at the command prompt, it will show you all your environment variables and aliased commands are not a part of that list. Though if you go to your shell's pid and cat the environ file, it won't show all the variables that env shows. This is because some of them are owned by different processes, but all of those processes are owned by your user.

I have zero idea where to find aliases stored in memory. The procfs seemed to me the most logical place since a ton of stuff in memory is mapped to this virtual filesystem.
 
So, when you type "alias x=y" at the command line, the alias you created is not persistent. Meaning, if you log out. It will be lost. It is only stored in memory in your session.

I've dug around a little, but I did not locate it in the procfs which is where you usually find environmental variables. That said, it might be under a different pid that is owned by the user within procfs, but I don't have time to go searching all the different pids owned by my specific user.

As I believe I noted above. If you type "env" at the command prompt, it will show you all your environment variables and aliased commands are not a part of that list. Though if you go to your shell's pid and cat the environ file, it won't show all the variables that env shows. This is because some of them are owned by different processes, but all of those processes are owned by your user.

I have zero idea where to find aliases stored in memory. The procfs seemed to me the most logical place since a ton of stuff in memory is mapped to this virtual filesystem.
Thank you kindly, for now it shall remain a mystery to me. I know it’s kinda pointless I was just curious. Basically i wanted to see my additions occur “real-time” ie create an alias using aforementioned method and go to the file and see it worked.It was strange to me that I couldn’t do this.
Thanks again
 
I suspect it's stored in RAM, perhaps in the kernel's paging section of RAM. I doubt that it's stored in a file.

Unfortunately, I read a great bit about kernel memory and have since forgotten pretty much all of it 'cause I'm not a kernel dev and have zero real-world reasons to keep that stored in my own volatile memory.
 
.
This link below seems to explain it quite well. If I open a terminal and declare an alias "alias x=y" I can turn around and see the alias exists. If I close the terminal window and open another the alias is gone. Likewise if I sudo to another user I no longer see it. However as long as I do not close the terminal window I can return to user that I declared the alias with and it is still there. Basically looks to me like a variable local to the user interaction with bash.

 
@jpnilson - I am going to move this to Command Line, where scripting and alias queries are best handled.

There, you might get some more good input from @JasKinasis , too.

So hang on to your hats, buckle up your seatbelts, and we'll take Wizard's magic carpet ride over there.

Wiz
 
We have landed at Command Line, please disembark and proceed to Baggage Claims.

Thank you for flying Air Wizard and we hope to see you again soon.

Good Luck.
 
I don't think I have anything of value to add.
I think the others who have responded here have pretty much got it all covered!
 

Members online


Latest posts

Top