LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to make alias peranent? or how to search all files for a string? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-make-alias-peranent-or-how-to-search-all-files-for-a-string-663291/)

john test 08-16-2008 05:15 PM

How to make alias peranent? or how to search all files for a string?
 
Running gOS/GNU/Ubuntu linux 7.10

if I type "alias" at the cli I get

alias ls='ls --color=auto'
I would like to add additional alias entries.
I have looked in profile .bashrc and .bash.aliases with no success
How can I search all files for the string above so that I can find the file that I need to modify to add some of the aliases found here in this forum?
Thanks for any help

Uncle_Theodore 08-16-2008 05:29 PM

Quote:

Originally Posted by john test (Post 3250046)
Running gOS/GNU/Ubuntu linux 7.10

if I type "alias" at the cli I get

alias ls='ls --color=auto'
I would like to add additional alias entries.
I have looked in profile .bashrc and .bash.aliases with no success
How can I search all files for the string above so that I can find the file that I need to modify to add some of the aliases found here in this forum?
Thanks for any help

To search files for a string, you can try using

grep "alias ls='ls --color=auto'" /etc/*

But, here's a link to a similar question

http://ubuntuforums.org/archive/index.php/t-206080.html

john test 08-16-2008 05:59 PM

Quote:

Originally Posted by Uncle_Theodore (Post 3250056)
To search files for a string, you can try using

grep "alias ls='ls --color=auto'" /etc/*

But, here's a link to a similar question

http://ubuntuforums.org/archive/index.php/t-206080.html

Seems like the command string above is incomplete. executed at the cli it just comes back to the command line with no error annd no output

I tried
# locate profile | cat | grep "alias ls='ls --color=auto'"
and

# locate bash | cat | grep "alias ls='ls --color=auto'"
with no results
Any help appreciated

Uncle_Theodore 08-16-2008 06:02 PM

Quote:

Originally Posted by john test (Post 3250082)
Seems like the command string above is incomplete. executed at the cli it just comes back to the command line with no error annd no output

I tried
# locate profile | cat | grep "alias ls='ls --color=auto'"
and

# locate bash | cat | grep "alias ls='ls --color=auto'"
with no results
Any help appreciated

The command is complete. It just doesn't find anything. The only other place I can think of is .bash_aliases (with an underscore) in your home directory.

john test 08-16-2008 06:21 PM

Sorry did not intend to be rude. it looks like it looks for the string in all files in the /etc directory. How do I make it recursive to go down through all the subdirectories including the .dirs

I'm a newbie and am still feeling my way around the command structure :-)

bashyow 08-16-2008 06:25 PM

you can put aliases in your '~/.bashrc' file.

then everytime you open a terminal emulator (like xterm), your alias will be available.

an alias in the bashrc file should (I think) override any system wide alias

the bashrc is read for subsequent shells.
the bash_profile is read on log-in

if you want the alias to also be available in the console on login, you do the above, but also edit the '~/.bash_profile' and put this

Code:

source .bashrc
this executes all the commands in the bash.rc file.

john test 08-16-2008 06:41 PM

Stronger apologies! figured out how to test the command and of course you are exactly right. So what I need is a way to make it recursive from / --
The existing permanent alias is part of the distro and comes with a new install So. there has to be a file somewhere that executes on boot up that initializes this variable. If I can find that file I can add all the aliases that I have been collecting
Thanks again for your help

john test 08-19-2008 04:50 PM

Finally got it. You not only have to modify .basrc in /home/user you have to do the same in /root to make it work as user and root.

john test 08-19-2008 05:43 PM

Working it out
No bash_profile but there is a .profile that does an include .bashrc
no bash_aliases
found a /etc/skel/.bashrc and I added the aliases there and then created a new user which low and behold the aliases are in the new users .bashrc

so to make aliases permanent it would appear that I need to edit each user .bashrc including /root/.bashrc

Hey guys there needs to be a better way! ;-)

Mr. C. 08-19-2008 06:02 PM

Spend some time reading the bash man page, at this section: INVOCATION. Your frustration comes from lack of understanding.

Bash reads one of many startup profiles, depending upon how the shell was started. Key things to know. Is the shell a) a login shell, b) interactive.

The (b) is easy - you're typing at the shell, so its interactive. Shell scripts that don't have STDIN are not interactive.

The (a) is more complex, because different distros do things differently. But, either the user's ~/.bash_profile or ~/.bashrc is read upon shell startup. Try first ~/.bash_profile.

All the various bash startup files in /etc will be for all users, or default values. Again, this is all distro dependent, but follows the rules specified in the man page under INVOCATION.

john test 08-19-2008 09:08 PM

Thanks for the response.
What I was hoping for was something like alias l= "ls -l" -perm
but what I get is gedit .bashrc and manually add aliases for each user and the SKEL
Seems to work
Do you happen to know the derivation of /etc/skel?

edit Sorry if the above sounds rude or unappreciative. I've got a working solution and I'm a happy camper

Mr. C. 08-19-2008 10:41 PM

Your "--perm" option can be implemented as:

echo 'alias l="ls -l" >> ~/.bash_profile

You'll get used to customizing your configuration. Consider creating your own file, perhaps named ".aliases", where you store aliases you accumulate over the years. Then, in your .bashrc or .bash_profile, add:
Code:

. ~/.aliases
to source the file upon shell startup. Add new aliases at will (perhaps you'll learn to create yourself a function that not only defines an alias for you, but also adds it to your .aliases file for you!).

Linux/Unix systems give you a great number of tools. You'll become more skilled with practice.

Files in /etc/skel are "skeleton" files, essentially templates used by programs such as useradd. On a single user system, there's not a lot of value. But on a system with hundreds of user's created, a set of templates allowing common new user setup is very useful.

john test 08-21-2008 11:08 AM

Its more like I need a"Global" "perm" function.

I am running ubuntu which appears to be somewhat different than the distro you reference

In any event. per your suggestion I did echo 'alias ipconfig="ip rout" >> /etc/profile and it added the needed alias to the bottom of /etc/profile and when I puttied back in and did alias, there is was! Good Stuff! but shen I did su and became root, it disappeared.
So, that looks like /etc/profile is sort of semi-global

Looks like I need a script to take an input parameter and append that parameter as an alias to /root/.bashrc, /home/john/.bashrc, /home/fred/.bashrc and /etc/skel/.bashrc

Since I have both .bashrc and .profile in each /home/user directory, is it better to append the new alias to the .bashrc or to the .profile?
bTW I have an /etc/rc.local could I add aliases to that file and expect them to be global?


All times are GMT -5. The time now is 03:05 AM.