LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 08-16-2008, 06:15 PM   #1
john test
Member
 
Registered: Jul 2008
Distribution: ubuntu 9.10
Posts: 527
Blog Entries: 1

Rep: Reputation: 35
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
 
Old 08-16-2008, 06:29 PM   #2
Uncle_Theodore
Member
 
Registered: Dec 2007
Location: Charleston WV, USA
Distribution: Slackware 12.2, Arch Linux Amd64
Posts: 896

Rep: Reputation: 60
Quote:
Originally Posted by john test View Post
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
 
Old 08-16-2008, 06:59 PM   #3
john test
Member
 
Registered: Jul 2008
Distribution: ubuntu 9.10
Posts: 527
Blog Entries: 1

Original Poster
Rep: Reputation: 35
Quote:
Originally Posted by Uncle_Theodore View Post
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
 
Old 08-16-2008, 07:02 PM   #4
Uncle_Theodore
Member
 
Registered: Dec 2007
Location: Charleston WV, USA
Distribution: Slackware 12.2, Arch Linux Amd64
Posts: 896

Rep: Reputation: 60
Quote:
Originally Posted by john test View Post
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.
 
Old 08-16-2008, 07:21 PM   #5
john test
Member
 
Registered: Jul 2008
Distribution: ubuntu 9.10
Posts: 527
Blog Entries: 1

Original Poster
Rep: Reputation: 35
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 :-)
 
Old 08-16-2008, 07:25 PM   #6
bashyow
Member
 
Registered: Jun 2008
Location: uk
Distribution: Slackware 12.1, AND IM LOVIN EVERY MINUTE OF IT, JERRY! :D
Posts: 122

Rep: Reputation: 15
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.

Last edited by bashyow; 08-16-2008 at 07:38 PM.
 
Old 08-16-2008, 07:41 PM   #7
john test
Member
 
Registered: Jul 2008
Distribution: ubuntu 9.10
Posts: 527
Blog Entries: 1

Original Poster
Rep: Reputation: 35
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
 
Old 08-19-2008, 05:50 PM   #8
john test
Member
 
Registered: Jul 2008
Distribution: ubuntu 9.10
Posts: 527
Blog Entries: 1

Original Poster
Rep: Reputation: 35
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.
 
Old 08-19-2008, 06:43 PM   #9
john test
Member
 
Registered: Jul 2008
Distribution: ubuntu 9.10
Posts: 527
Blog Entries: 1

Original Poster
Rep: Reputation: 35
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! ;-)
 
Old 08-19-2008, 07:02 PM   #10
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 61
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.
 
Old 08-19-2008, 10:08 PM   #11
john test
Member
 
Registered: Jul 2008
Distribution: ubuntu 9.10
Posts: 527
Blog Entries: 1

Original Poster
Rep: Reputation: 35
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

Last edited by john test; 08-19-2008 at 10:11 PM.
 
Old 08-19-2008, 11:41 PM   #12
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 61
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.

Last edited by Mr. C.; 08-21-2008 at 06:03 PM.
 
Old 08-21-2008, 12:08 PM   #13
john test
Member
 
Registered: Jul 2008
Distribution: ubuntu 9.10
Posts: 527
Blog Entries: 1

Original Poster
Rep: Reputation: 35
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?

Last edited by john test; 08-21-2008 at 12:13 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can you make search ...search a string in a link....a url...a web address aus9 LQ Suggestions & Feedback 4 04-16-2008 10:37 AM
Need to search all files for string - strings command? jmur Programming 4 03-28-2008 03:35 PM
Search and replace string in executable files aalex77 Programming 2 05-26-2006 07:32 PM
Is it possible to search for a string from all the files on the harddisk? Akhran Linux - Newbie 8 09-13-2005 07:09 AM
how do i search files for a particular string? darkpark Linux - Newbie 4 07-05-2005 06:46 PM


All times are GMT -5. The time now is 11:36 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration