Results 1 to 10 of 11
Hi all, i saw how possible it was to make custom commands for your console, for example, if you wanted to open a file or program instead of typing the ...
- 06-10-2008 #1Just Joined!
- Join Date
- Dec 2007
- Posts
- 52
Custom commands
Hi all, i saw how possible it was to make custom commands for your console, for example, if you wanted to open a file or program instead of typing the full version you would type something shorter and easier to remember. Something like this:
user@shell~: open firefox
How would i go about accomplishing this? Thanx in advance!
- 06-10-2008 #2
- 06-10-2008 #3Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513
As Geeth said, read about "alias" in the bash man page.
Its usage is pretty much straightforward for the most part, some examples taken from my own ~/.bashrc:
Put them into ~/.bashrc and/or ~/.bash_profile.Code:alias cp='cp -i' alias df='pydf' alias dvdplay='mount /mnt/dvd; mplayer /mnt/dvd/*; umount /mnt/dvd' alias emerge='emerge -Dv' alias grep='grep --colour=auto' alias h='history' alias ls='ls -h' alias mc='mc -x' alias mv='mv -i' alias nano='nano -w' alias nwn='cd ~/games/nwn; ./nwn' alias rm='rm -i' alias startx='startx \"$@\" & exit' alias undying='winerun ".wine/drive_c/Archivos de programa/EA Games/undying/System/" "../Undying.exe"' alias vbox='sudo /sbin/modprobe vboxdrv; VirtualBox; sudo /sbin/rmmod vboxdrv'
- 06-10-2008 #4Just Joined!
- Join Date
- Dec 2007
- Posts
- 52
Thanx for you reply i92guboj, very helpful and educational. But i cant find the file bash_profile on my system. Im using Fedora 7 btw. As root im in /root dir. And i cant find those two files you mentioned. Any suggestions?
- 06-10-2008 #5Linux User
- Join Date
- Jun 2007
- Posts
- 318
Did you include a period in front of the filename. In other words the filename is .bash_profile and .bashrc
Also these files are known as 'hidden' files so they won't show up in a 'ls -l' command. Use the command 'ls -la'.
- 06-10-2008 #6Just Joined!
- Join Date
- Dec 2007
- Posts
- 52
Well i added this to .bashrc
And got an error that the command doesnt existCode:alias mydir='pwd'
What did i do wrong?bash: mydir: command not found
- 06-10-2008 #7Linux User
- Join Date
- Jun 2007
- Posts
- 318
The file .bashrc is a script that's executed when you log in. So the new alias won't be created until you log off and back on. That or manually execute the script with the command:
Code:. ./.bashrc
- 06-10-2008 #8
You dont have to log off/on after editing .bashrc file. Just source it.
Code:source .bashrc
It is amazing what you can accomplish if you do not care who gets the credit.
New Users: Read This First
- 06-10-2008 #9Just Joined!
- Join Date
- Dec 2007
- Posts
- 52
HAH! Thanx devil casper, that worked
- 06-10-2008 #10Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513
I know it's kind of an overkill, but even if it's just for the sake of not having to write the dot-file name, I often just do "exec bash", whichi just exit this shell and runs a new one. That, indeed, emulates closing the terminal and opening a new one (forcing in the way the sourcing of the rc file).
.bashrc and .bash_profile can be created if they don't exist. For the details you can check the bash man page. Basically, ~/.bash_profile is read on login shells, and ~/.bashrc is read on non-login shells (for example, when you open a terminal).



