LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-04-2005, 12:37 PM   #1
Gins
Senior Member
 
Registered: Jul 2004
Location: Germany
Distribution: open SUSE 11.0, Fedora 7 and Mandriva 2007
Posts: 1,662

Rep: Reputation: 47
How to make an alias?


I tried to create an alias for a 'grep' command. It didn't work.
Could you help me, please?
I have file called ' testing1004' . The following grep command work properly.

[ka@c83-250-89-26 ka]$ grep '^[T-W]' testing1004

Then I wrote an alias. The name of my alias is ' crook1' .

I tried the following and it didn't work.

[ka@c83-250-89-26 ka]$ alias crook1 'grep '^[T-W]' testing1004'
bash: alias: crook1: not found


This was my maiden attempt to creat an alias. I would like to save the alias somewhere on the system so I could use it next time too. Where do I save it?

I am using Mandrake Linux 10.0 version
 
Old 06-04-2005, 12:42 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
alias blah='a command with options in single quotemarks'

store in ~/.bashrc for your use only. /etc/bashrc for system wide.
 
Old 06-04-2005, 12:44 PM   #3
DrOzz
Senior Member
 
Registered: May 2003
Location: Sydney, Nova Scotia, Canada
Distribution: slackware
Posts: 4,185

Rep: Reputation: 60
go into your home directory and edit the file called .bashrc (notice the leading dot).
add the alias in there such as this example to list only directorys :
Code:
alias lsD='ls -l | grep "^d"'
When looking at the above the "lsD" would be the alias ...

oh, and here is the alias usage arguments :
Code:
alias: usage: alias [-p] [name[=value] ... ]
so you can use either of the above examples
 
Old 06-04-2005, 01:02 PM   #4
Gins
Senior Member
 
Registered: Jul 2004
Location: Germany
Distribution: open SUSE 11.0, Fedora 7 and Mandriva 2007
Posts: 1,662

Original Poster
Rep: Reputation: 47
Thanks everybody. So I have to log on as a root user and do some editing. That is a tall order.

What is the meaning of the following command?
[ka@c83-250-89-26 ka]$ ls -l | grep "^d"

It showed some folders.

If I only wrote the following command, it shows folders and files.

[ka@c83-250-89-26 ka]$ ls -l

---------------------
What is the meaning of the following command?
[ka@c83-250-89-26 ka]$ ls -l | grep "^d"

I believe it directs the output of the ' ls -l ' command to a grep command.
I believe the pipe [ | ] has some kind of a redirection function. Please tell me what it is doing.
 
Old 06-04-2005, 10:54 PM   #5
DrOzz
Senior Member
 
Registered: May 2003
Location: Sydney, Nova Scotia, Canada
Distribution: slackware
Posts: 4,185

Rep: Reputation: 60
no you don't have to be root to edit this stuff, unless you are editing it
globally in /etc/bashrc... if you just want if for your particular user, then
edit their .bashrc file in their home directory.
And your just piping the results of ls -l to grep where grep's argument is
telling to only display results which are directorys..
 
Old 06-05-2005, 10:04 AM   #6
Gins
Senior Member
 
Registered: Jul 2004
Location: Germany
Distribution: open SUSE 11.0, Fedora 7 and Mandriva 2007
Posts: 1,662

Original Poster
Rep: Reputation: 47
Thanks DrOzz for your reply.

Is it possible to edit without logging on as a root user?

I think if you want to edit a file on a Linux system one should log on as a root user.
What is the meaning of .bashrc ?

Is it different from bashrc?



----------------------------------------------------
The following is my default:

[ka@c83-250-94-241 ka]$ pwd
/home/ka
[ka@c83-250-94-241 ka]$


--------------------------------------------

The following is my bashrc file:
[ka@c83-250-94-241 etc]$ more bashrc
# /etc/bashrc

# System wide functions and aliases
# Environment stuff goes in /etc/profile

# by default, we want this to get set.
# Even for non-interactive, non-login shells.
if [ "`id -gn`" = "`id -un`" -a `id -u` -gt 99 ]; then
umask 002
else
umask 022
fi

# are we an interactive shell?
if [ "$PS1" ]; then
case $TERM in
xterm*)
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'
;;
*)
;;
esac
[ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ "

if [ -z "$loginsh" ]; then # We're not a login shell
for i in /etc/profile.d/*.sh; do
if [ -x $i ]; then
. $i
fi
done
fi
fi

unset loginsh
[ka@c83-250-94-241 etc]$
 
Old 06-06-2005, 07:13 PM   #7
DrOzz
Senior Member
 
Registered: May 2003
Location: Sydney, Nova Scotia, Canada
Distribution: slackware
Posts: 4,185

Rep: Reputation: 60
that bashrc file located in /etc is the global file ... So if you make
the changes in that file, all system users will be affected by the change.

If you go into your /home/ka folder and edit the .bashrc file
the changes you make will only affect the ka user.

So, yes if you wanted to edit the /etc/bashrc, then you will have to be root,
but if you just wanted these changes for aliases to be for your regular system
user ka then you can simply edit the .bashrc file in your home folder.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I make an alias? quintan Linux - Software 2 11-25-2005 03:44 AM
How to make alias of 'ls' in winxp/dos servnov General 4 11-04-2004 08:39 PM
make an alias in winXP zchoyt Linux - General 2 09-14-2004 08:33 AM
Make symbolic link or alias gubak Linux - Newbie 5 08-20-2004 12:50 PM
How do i make an alias on my webserver? meluser Linux - Software 14 03-13-2003 03:11 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:38 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