Linux - GeneralThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: open SUSE 11.0, Fedora 7 and Mandriva 2007
Posts: 1,662
Rep:
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?
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 ...
Distribution: open SUSE 11.0, Fedora 7 and Mandriva 2007
Posts: 1,662
Original Poster
Rep:
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.
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..
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
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.