I am trying to create a permanent alias by either inserting it into the .bashrc directly (although it is just called bashrc in Fedora) located in /etc/ to the lowest part of bashrc using gedit. OR, by creating a .bash_aliases file, chmod to 755, and using the code below into bashrc.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
But nothing is working, because of Set document metadata failed: Setting attribute metadata::gedit-encoding not supported Set document metadata failed: Setting attribute metadata::gedit-spell-language not supported
You donāt want to edit it. If youāve mangled it and donāt know what to undo, please say what version of Fedora youāre on (36, 37, or 38) and Iāll point you to the original.
~/.bashrc is your user bashrc.
Feel free to edit it; add your aliases directly, or source ~/.bash_aliases here. If youāve mangled it, you can copy the template from /etc/skel/.bashrc to ~/.bashrc
There should be no need to chmod files in your home dir, so Iām not sure where you created your .bash_aliases file. If you created /etc/.bash_aliases, youāll want to remove it.
FYI, ~ refers to your home directory, i.e. /home/$USER (where $USER is your username).
Not true.
There is /etc/bashrc which is a system wide bashrc that applies to every user.
There is also /home/USER/.bashrc which provides user specific configurations and would normally be where the user adds their own specific customizations.
I prefer adding my profile customization to /etc/profile.d to make it work system-wide, avoid modifying configurations owned by packages, and save time merging configurations on system upgrade.
Oh ****. Iād edit out the changes Iād made into it (even rm the .bash_aliases), although I think I had messed up. The warning Set document metadata failed::gedit- keep on appearing even when I exit gedit. And an interesting thing I just discovered, my VMās snapshot (the one before I toy with the bashrc file), doesnāt seem to work properly. Nothing change when I restore it, as I can see the same browser pages and apps.
Should I reinstall gedit? Did that etc/bashrc edit cause this?
I found it, and now Iām trying to find .bashrc.d where I think it kept the aliases. Didnāt find it at home directory using ls -a.
User specific aliases and functions
if [ -d ~/.bashrc.d ]; then
for rc in ~/.bashrc.d/*; do
if [ -f ā$rcā ]; then
. ā$rcā
fi
done
fi
You would need to create that directory then put any files you want in there. Those files will not be modified during any system updates so you can consider them as static files.
You donāt have to use the ~/.bashrc.d/ folder, itās just a different way to organise things. You can also do it the typical way with sourcing your own ~/.bash_aliases.
If you want to use ~/.bashrc.d/, just create the folder, and put any shell scripts in there that you want to be sourced. The included snippet in the default ~/.bashrc loops through every file in ~/.bashrc.d/ and sources it for you.
You can organise the files any way you like. For example you could have 1 file for aliases like ~/.bashrc.d/aliases.sh and 1 file for environment variables ~/.bashrc.d/env.sh. Or you could have separate files for different programs/contexts.
/etc/profile.d is like the system-wide equivalent of this concept. If you manage a multi-user system and want to set things for everyone, you could use it, but for a single user it doesnāt really have any advantages over doing things in your home dir, and is less convenient as you need root permissions to edit. Also, packages may install files in /etc/profile.d so itās a lot more crowded (you probably already have dozens of files in there).
I donāt know what causes your gedit errors. Were you using it with sudo? Generally you should not use GUI apps with sudo.
I have no idea where I got wrong again. It should be a simple matter of either adding the aliases directly into .bashrc. Or, creating a separate aliases file by including the below code too. But nothing happen.
# My custom aliases
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
##shortcut aliases
alias dnfuu=sudo dnf update -y && sudo dnf upgrade -y
alias ooo=cd ~/XXX
alias kkk=cd ../../..
As for sudo gedit, I did actually. Guess I forgot adding sudo is pointless.
This should be alias dnfuu="sudo dnf update -y && sudo dnf upgrade -y"
Although that command is doing exactly the same thing twice. With dnf the āupdateā command is an alias for the āupgradeā command.
@vgaetera@computersavvy
Still doesnāt work, either with " or '. I saw some alias ignored the ", but I guessed that is because it only use 1 specific command like sudo reboot, or not.
dnf automatically refreshes the cache on a timer, and also when itās used if the cache is stale. So there is no need to update the cache manually like apt update.
For more information on common apt vs dnf commands, see:
Yep,
.bashrc only gets read when the terminal session is opened. We all have hit that roadblock in the past so donāt feel bad. Just remember it for the future.
You can also make an alias to execute : source ~/.bashrc && source ~/.bash_profile (Of course you would also to source your alias file if external) this will reread your personal bash files.