Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum. |
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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
 |
05-10-2006, 04:25 AM
|
#1
|
Member
Registered: May 2006
Location: India
Distribution: RedHat Enterprise Linux (Kernel 2.6)
Posts: 42
Rep:
|
user defined shell commands
hello friends..
i am working on red hat linux (kernal 2.6). Although it has a GUI to work upon but still i wish to work on its shell and be perfect in that too.
Can anybody tell how to create our own shell commands.
i mean that supposedly if some one has to access the cdrom and he does not remember all those shell commands to mount the cd-rom and all that, then i define a command in such a way that it contains all those things required to access the cdrom and the other person just writes the command and he can access the cdrom well..
Hope you people are able to understand my problem..
Please help me out if possible.
|
|
|
05-10-2006, 04:37 AM
|
#2
|
Senior Member
Registered: Dec 2003
Location: Brasil
Distribution: Arch
Posts: 1,037
Rep:
|
hi there,
you are looking for an alias or maybe a shell script.
you should start looking for /etc/profile for aliases.
regards,
slackie1000
|
|
|
05-10-2006, 04:42 AM
|
#3
|
Member
Registered: Mar 2006
Distribution: BackTrack, RHEL, FC, CentOS, IPCop, Ubuntu, 64Studio, Elive, Dream Linux, Trix Box
Posts: 310
Rep:
|
Try this
Hi ashley,
Write following in a file suppose mnt.sh
file mnt.sh starts
--------------------------------------------
#!/bin/bash
mount -t iso9660 /dev/cdrom /mountpoint
----------------------------------------------
file ended--------------
another commnad
chmod +x mnt.sh
to make it useful for other users you will have to do one more thing:- set suid to the mnt.sh script check this link for that
http://www.linuxquestions.org/linux/...dia/SUID_HOWTO
|
|
|
05-10-2006, 05:34 AM
|
#4
|
Member
Registered: May 2006
Location: India
Distribution: RedHat Enterprise Linux (Kernel 2.6)
Posts: 42
Original Poster
Rep:
|
hey thanks imaineers,,
u always help me out.. i'll try this and let u know.
|
|
|
05-10-2006, 05:58 AM
|
#5
|
Member
Registered: May 2006
Location: India
Distribution: RedHat Enterprise Linux (Kernel 2.6)
Posts: 42
Original Poster
Rep:
|
is it better to use an 'alias' command as ----->> alias open mount -t iso9660 /dev/cdrom /mountpoint
for this purpose or should i create a shell script just as u said??
and please tell me the basic difference between the two things.
|
|
|
05-10-2006, 10:06 PM
|
#6
|
Senior Member
Registered: Sep 2003
Posts: 3,171
Rep: 
|
You can also set aliases in your .bashrc file. This is where I usually do it. For instance, being an old amiga user, I prefer to copy rather than cp, del rather than rm, and dir rather than ls. So I set these in .bashrc.
Further, I find ps ax | grep commandname to be tedious to enter when I need to get a PID in the task list, so I set an alias called gettask in my .bashrc file to do it for me.
The only downside to this is that I find myself working on computers all over the globe and I either have to copy my .bashrc to whatever machine I am accessing via ssh, or I have to cp and rm and ls except when I am on my home system. Oh well.
Here is my list of aliases that I commonly use:
alias del='rm -dfr'
alias copy='cp'
alias up='cd..'
alias dir='ls -al'
alias dvd='ogle /dev/cdrom1'
alias viewrpm='rpm -qpl'
alias boomer="totem http://asx.abacast.com/boomerradio-cafe-20.asx"
alias gettask="ps ax|grep"
|
|
|
05-11-2006, 12:42 AM
|
#7
|
Member
Registered: Mar 2006
Distribution: BackTrack, RHEL, FC, CentOS, IPCop, Ubuntu, 64Studio, Elive, Dream Linux, Trix Box
Posts: 310
Rep:
|
Hi ashley,
Aliases do work faster as they are bash env. variables and are in RAM
but as of with commands we do have more and better control over the script, paths and also every command used in the script.
Security concerns:- If you have a totally customized linux box so that no cracker who has made it to get log in the system would be able to use some commands(such as rm, mv, chattr , passwd, and every sbin cmd) which can mess up things. We can do this by simply renaming the commands, changing the paths and now as everything has differrent names. Our scripts have some names which only the users who are physically there in lab or have told the new commands can use the system. Advantage:-- one added layer of security which still can be overrun.
But what we can do is add more and more layers in such a way that we can sleep without nightmares:java: . Although world is not filled with evils but still if its your job to protect you have to keep up2date with latest weapons!
Last edited by imagineers7; 05-11-2006 at 12:46 AM.
|
|
|
05-15-2006, 01:24 AM
|
#8
|
Member
Registered: May 2006
Location: India
Distribution: RedHat Enterprise Linux (Kernel 2.6)
Posts: 42
Original Poster
Rep:
|
Quote:
Originally Posted by jiml8
You can also set aliases in your .bashrc file. This is where I usually do it.
Here is my list of aliases that I commonly use:
alias del='rm -dfr'
alias copy='cp'
alias up='cd..'
alias gettask="ps ax|grep"
|
hey.. i have created alias commands.. But where is this .bashrc file where i have to write them.
I have some files like bash_profiles and bashr and i have even added my alias command in these files but still when i run the command,it says:"command not found."
I have also restarted the computer but still it isnt working.
Please help me out.
|
|
|
05-15-2006, 02:22 AM
|
#9
|
LQ Newbie
Registered: Sep 2005
Location: Sydney, Australia
Distribution: Vector Linux
Posts: 26
Rep:
|
Quote:
Originally Posted by ashley_31
hey.. i have created alias commands.. But where is this .bashrc file where i have to write them.
I have some files like bash_profiles and bashr and i have even added my alias command in these files but still when i run the command,it says:"command not found."
I have also restarted the computer but still it isnt working.
Please help me out.
|
.bashrc should be in your home directory ($HOME/.bashrc or ~/.bashrc). Use "ls -a" to view it as it is considered a hidden file. If you're using an explorer type program to view the system then try check view hidden files.
|
|
|
05-15-2006, 02:23 AM
|
#10
|
Member
Registered: Feb 2005
Location: Bangalore
Distribution: FC3
Posts: 137
Rep:
|
hi,
.bashrc file will be in your home. if you dont find one, you can create a newone with this name.. it should work after you start the shell again..
|
|
|
05-15-2006, 02:32 AM
|
#11
|
Member
Registered: Nov 2005
Distribution: xubuntu, grml
Posts: 451
Rep:
|
You can put .bashrc in your home/<your_user>/ directory. If it's not there create it.
Find it like so with a console:
Code:
ls -al ~/.bashrc
OR
ls -al ~
(by default ls does not list files beginning with a dot (.) so use the -al option to list those).
Test it by sourcing it:
Now the aliases you put into .bashrc should work. Test it.
Normally .bashrc is run when you open a console window so you don't have to logout/login linux, just open a new console and that should automatically source (run) your .bashrc
Note: i could be wrong here because the name for .bashrc sometimes differs per system/distro.
I see you are using red hat, maybe update your forum profile to display that you are using red hat?
|
|
|
05-15-2006, 03:27 AM
|
#12
|
Member
Registered: May 2006
Location: India
Distribution: RedHat Enterprise Linux (Kernel 2.6)
Posts: 42
Original Poster
Rep:
|
hey people...
thank u all so much...Its done..
|
|
|
All times are GMT -5. The time now is 06:43 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|