Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
59
rated 0 times [  59] [ 0]  / answers: 1 / hits: 78603  / 3 Years ago, sun, august 8, 2021, 9:14:22

during my work I need to constantly add alias commands to bashrc, most of those commands needs to be runed by other users. is there any way I could add alias commands to a bashrc from external source?


More From » bash

 Answers
2

Many config files in users home directory just override/add to ones in the /etc - for example the settings for GIMP in the users home are in ~/.gimp-2.*, which adds to the system-wide config /etc/gimp/2.0.


So for ~/.bashrc, you could edit the system wide config files /etc/bash.bashrc (for functions/aliases) or /etc/profile (for environment stuff) - you can the full list from man bash:


FILES
/bin/bash
The bash executable
/etc/profile
The systemwide initialization file, executed for login shells
/etc/bash.bash_logout
The systemwide login shell cleanup file, executed when a login shell exits
~/.bash_profile
The personal initialization file, executed for login shells
~/.bashrc
The individual per-interactive-shell startup file
~/.bash_logout
The individual login shell cleanup file, executed when a login shell exits
~/.inputrc
Individual readline initialization file

This warning is given for a few Linux systems in the files:


# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.

So you could edit those files, you may want to back them up first (cp /etc/bash.bashrc /etc/bash.bashrc-backup for example), or create a shell script in /etc/profile.d - for example you can create one with these commands (with sudo/as root):


touch /etc/profile.d/custom.sh
chmod +x /etc/profile.d/custom.sh

Then open it with nano /etc/profile.d/custom.sh


#!/bin/sh
alias ls='ls -lah'

And check whether it works by seeing if it appears in the output of alias - Note that you may need to logout/login or reboot to see any changes (if you don't want to, running source /etc/profile after any changes might work)


[#23957] Monday, August 9, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
farnic

Total Points: 409
Total Questions: 117
Total Answers: 125

Location: Andorra
Member since Sat, May 27, 2023
1 Year ago
;