LinuxQuestions.org
Help answer threads with 0 replies.
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 12-10-2012, 05:58 AM   #1
danieella
LQ Newbie
 
Registered: Dec 2012
Posts: 9

Rep: Reputation: Disabled
Create and save alias


Can anyone tell me how to create an alias that count the number of lines in any file and save so when you reboot, alias is still present.

Example: alias nl='wc -l'
how do i save it permanently.

Thank you
 
Old 12-10-2012, 06:12 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403
That depends a bit on the distro you are using.

.bashrc is used and will probably always work. Some distro's use .bash_aliases.

There are probably already some aliases present in either of the two files.
 
Old 12-10-2012, 06:17 AM   #3
danieella
LQ Newbie
 
Registered: Dec 2012
Posts: 9

Original Poster
Rep: Reputation: Disabled
reply

Quote:
Originally Posted by druuna View Post
That depends a bit on the distro you are using.

.bashrc is used and will probably always work. Some distro's use .bash_aliases.

There are probably already some aliases present in either of the two files.


I used both including .bash_profile. Still not working when i reboot
 
Old 12-10-2012, 06:26 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403
Have a look at this article: Aliasing Commands

Both .bash_profile and .bashrc are mentioned.

Are you storing these aliases in the correct .bashrc/.bash_profile file? This is user specific, not global. If you want to make those aliases global then you need to store them in /etc/bash.bashrc

If that still doesn't help; please post that part of .bashrc/.bash_profile that holds the aliases.
 
Old 12-10-2012, 06:46 AM   #5
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: Slackware®
Posts: 13,862
Blog Entries: 41

Rep: Reputation: 3042Reputation: 3042Reputation: 3042Reputation: 3042Reputation: 3042Reputation: 3042Reputation: 3042Reputation: 3042Reputation: 3042Reputation: 3042Reputation: 3042
Member Response

Hi,

Welcome to LQ!
Quote:
Originally Posted by danieella View Post
Can anyone tell me how to create an alias that count the number of lines in any file and save so when you reboot, alias is still present.

Example: alias nl='wc -l'
how do i save it permanently.

Thank you
You can setup '.bashrc' and '.bash_profile' for the user within '/home/user_name';
Quote:
Code:
  sample .bash_profile;

 ~$ cat .bash_profile
 #-----------------cut-------------- 
 # .bash_profile
 #08-30-06 12:21
 #
 # Source .bashrc
 if [ -f ~/.bashrc ]; then
         . ~/.bashrc
 fi
 #-----------------cut end--------------
Code:
 sample .bashrc;
 :~$ cat .bashrc
 #-----------------cut-------------- 
 #.bashrc
 #08-30-06 12:20  
  
 # Add bin to path
 
export PATH="$PATH:/sbin:/usr/sbin:$HOME/bin"
 
#export PATH="$PATH:$HOME/bin"
 
# Dynamic resizing
 shopt -s checkwinsize
  
# Custom prompt
 #PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
 
 #08-29-06 11:40

  if [ `id -un` = root ]; then
    PS1='\[\033[1;31m\]\h:\w\$\[\033[0m\] '
  else
    PS1='\[\033[1;32m\]\h:\w\$\[\033[0m\] '
 fi
  
 #
 # Add color
 eval `dircolors -b`
  
 # User defined aliases
 alias cls='clear'
 alias clls='clear; ls'
 alias ll='ls -l'
 alias lsa='ls -A'
 alias lsg='ls | grep'
 alias lsp='ls -1 /var/log/packages/ > package-list'
 alias na='nano'
 alias web='links -g -download-dir ~/ www.google.com'
  
 #08-29-06 11:50
  
 #To clean up and cover your tracks once you log off
 #Depending on your version of BASH, you might have to use
 # the other form of this command
    trap "rm -f ~$LOGNAME/.bash_history" 0
  
 #The older KSH-style form
 #   trap 0 rm -f ~$LOGNAME/.bash_history
 #-----------------cut end--------------
The '.bashrc' and '.bash_profile' are very useful for users!
HTH!
 
Old 12-10-2012, 06:52 AM   #6
danieella
LQ Newbie
 
Registered: Dec 2012
Posts: 9

Original Poster
Rep: Reputation: Disabled
Thanks

Thanks guys. You have been very helpful
 
  


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
How to create alias in HP Unix ? manalisharmabe Other *NIX 3 08-01-2011 07:58 PM
create alias on apache 1.3 ALInux Linux - Networking 2 04-01-2006 03:20 AM
Create alias in MySQL? JockVSJock Slackware 2 02-23-2006 09:15 PM
Create alias for font? titopoquito Linux - Software 4 10-03-2005 06:17 AM
create alias ohade Mandriva 1 08-09-2005 04:12 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:13 PM.

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
Open Source Consulting | Domain Registration