PDA

View Full Version : .bashrc - aliases - For Newbies



Bruce M.
April 4th, 2008, 02:13 AM
Aliases Only
Or some easy to read links to learn from!


I've created this thread so some of you experts can share aliases with an explanations of just what they do, and new people can ask for help to create one.

I'm subscribed to: Show us your .bashrc! (http://ubuntuforums.org/showthread.php?t=679762) and Post your bash scripts and aliases! (http://ubuntuforums.org/showthread.php?t=616875) and I find I'm sinking in information written for qualified "programmers". Those threads have scripts other than bashrc, functions within bashrc, and other scripts that look like ancient Egyptian hieroglyphics to me. :)

A bash alias is something that can help new people to Linux (me) do some really useful things if only they knew what they are and exactly what they do.

Please Note:
As a result of the first few posts in response to this post I'm asking that people identity whick distribution of Linux you are using and that includes which "flavour" of Ubuntu as well, ie; Ubuntu, Xubuntu or Kubuntu

For example, when I see these:

alias ps1_short="PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\W\[\033[00m\]\$ '"
alias ps1_long="PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '"
I'm :confused: and scratching my head. ( OK, they did come with an explanation in the original post (http://ubuntuforums.org/showpost.php?p=4216630&postcount=5) but some of the stuff is just soooooo deep. :)

My .bashrc is the one that comes out of the box except for a couple of aliases that I managed to pick up and do myself by reading and guessing at things.

Ubuntu 7.10 Here is my alias section with 2 aliases, that's how new I am, just two, I had a couple more but I lost em :(

Aliases:


# my aliases
alias conke='(gedit ~/.startconky ~/.conkyscripts/conkymain ~/scripts/w-days.pl &)'
alias cia='killall conky && ./.startconky'

Explanations:


conke {conky edit} opens gedit with the three files: startconky, conkymain and w-days.pl (weather)
cia {conky in action}: kills conky and restarts it, when I am editing conky for test purposes.


So if you have something that might be interesting to a new Linux user and would like to share feel free.

If you are new and want to ask how to do something feel free too.

----- Table of Contents -----
I can't Thank mali2297 enough for his link in #4 of the TOC. - Sharing aliases is one thing, to get us newbies started, but a GREAT link is worth it weight in GOLD, and this is it. Thanks mali2297

Post #2, page 1 - Somethings for ARCH Linux
Post #7 Page 1 - Some from Post #2 revised for Ubuntu - Note: Last two revised for Ubuntu: Post #12 Page 2 (http://ubuntuforums.org/showpost.php?p=4652909&postcount=12)
Post #9 page 1 - Something for Programmers - practice and test code.
Post #17 page 2 (http://ubuntuforums.org/showpost.php?p=4653152&postcount=17) - A GREAT Link to learn commands. and Aliases in that link start here (http://www.linuxcommand.org/wss0020.php#aliases)!
Post #20 Page 2 (http://ubuntuforums.org/showpost.http://php?p=4653342&postcount=20) - some nice ones "for mounting NFS shares" and one to kill FF when it freezes.
Post #23 Page 3 (http://ubuntuforums.org/showpost.php?p=4653495&postcount=23) - Along with two others, one that makes running programs with different language settings possible.
Post #24 Page 3 (http://ubuntuforums.org/showpost.php?p=4655781&postcount=24) - Fix a compiz leak

herbster
April 4th, 2008, 03:38 AM
Some of mine:


#general aliases
alias d='cd /home/bobby/Desktop' # quick access to Desktop
alias sshb='ssh user@website.com' # quick login to my ssh web server
alias pacsearch="pacman -Sl | cut -d' ' -f2 | grep " #lets you search through all available packages simply using 'pacsearch packagename'
alias pacup="sudo pacman -Syu" # sudo pacman -Syu by typing pacup
alias pac="sudo pacman -S" # sudo pacman -S by typing pac
alias pacinfo="sudo pacman -Qi"
alias pacrm="sudo pacman -R"
alias pacaur="sudo pacman -U"
alias clr='clear' #clear screen
alias fstab='sudo gedit /etc/fstab' #quick edit of fstab
alias rclocal='sudo gedit /etc/rc.local' # quick edit of rc.local
alias rcconf='sudo gedit /etc/rc.conf' # quick edit of rc.conf

#backup
alias archbackup='sudo rsync -avzp --progress --delete --exclude=/root --exclude=/var/tmp/kde* --exclude=/proc --exclude=/home --exclude=/media --exclude=/var/cache/pacman --exclude=/tmp/* --exclude=/lost+found --exclude=/var/backup --exclude=/mnt --exclude=/usr/man --exclude=/var/abs --exclude=/sys / /media/extra/backup/archbackup/'
alias homebackup='rsync -avz --progress --delete /home/bobby/ /media/extra/backup/bobby/'
alias serverbackup='rsync -avz --progress --delete /home/bobby/ user@website.com:backup/'

Bruce M.
April 4th, 2008, 03:42 PM
Some of mine:

Some you have I don't understand:

alias pacsearch="pacman -Sl | cut -d' ' -f2 | grep " #lets you search through all available packages simply using 'pacsearch packagename'
alias pacup="sudo pacman -Syu" # sudo pacman -Syu by typing pacup
alias pac="sudo pacman -S" # sudo pacman -S by typing pac
alias pacinfo="sudo pacman -Qi"
alias pacrm="sudo pacman -R"
alias pacaur="sudo pacman -U"

I did a
man pacmanand got nothing.

So I looked in Synaptic and sure enough Pacman was there and NOT what I was hoping for. :confused:


Pacman
Chase Monsters in a Labyrinth
You are Pacman, and you are supposed to eat all the small dots to get to the next level. You are also supposed to keep away from the ghosts, if they take you, you lose one life, unless you have eaten a large dot, then you can, for a limited amount of time, chase and eat the ghosts.
There is also bonus available, for a limited amount of time.
An X gives just points, but a little pacman gives an extra life.

Care to enlighten us newbies here. :rolleyes: Are you chasing ghosts or packages? :-\"

DrOlaf
April 4th, 2008, 03:45 PM
Pacman is the package manager on Arch linux.

mali2297
April 4th, 2008, 03:48 PM
Care to enlighten us newbies here. :rolleyes: Are you chasing ghosts or packages? :-\"

Herbster is an Arch User, pacman is the package manager in Arch. It corresponds to apt-get in Debian/Ubuntu.

ice60
April 4th, 2008, 04:31 PM
i think you spelt .bashrc wrong.

herbster
April 4th, 2008, 05:10 PM
Yeah, my bad Bruce, I should've explained that :) As others have stated, Pacman is the package manager for Arch linux, the distro I use-- the equivalent of apt-get/aptitude on your Ubuntu install. Those aliases for pacman I have are basically quick shortcuts to doing a system upgrade, installing a package, searching the package database, etc. You could easily tweak apt-get/aptitude to your liking in a similar way, something maybe like this:


alias aptup="sudo apt-get update && sudo apt-get upgrade"
alias aptget="sudo apt-get install"
alias aptrm="sudo apt-get remove"
alias aptsearch="sudo apt-get search"
alias aptinfo="sudo apt-get policy"

You've got the upgrade, install a package, remove a package, search for a package and show info of a package. Someone correct 'em if they're wrong, I'm a bit off on my Debanese ;)

ghindo
April 4th, 2008, 05:53 PM
i think you spelt .bashrc wrong.1+

LaRoza
April 4th, 2008, 05:57 PM
I define them as I go, recent ones:



alias code='cd /media/STORAGE/code/'
alias py='cd /media/STORAGE/code/pythonCode/'
alias compile='gcc p.c'
alias ncompile='gcc p.c -lncurses'


"p.c" or any file named p.* is a source file for practicing and testing. They are in my home directory, and are always there, but their content changes. It allows me to run and test code in many language easily.


p.c p.cpp p.cs p.d p.hi p.hs p.o p.php p.pl p.pp p.py p.rb p.sh

Bruce M.
April 4th, 2008, 08:37 PM
Pacman is the package manager on Arch linux.

Thanks for the head up, DrOlaf.


Herbster is an Arch User, pacman is the package manager in Arch. It corresponds to apt-get in Debian/Ubuntu.

And to you too mali2297, Thanks

Well, it is my fault after all I did say:

A bash alias is something that can help new people to Linux (me) do some really useful things if only they knew what they are and exactly what they do.

But to limit it to Ubuntu wouldn't be correct. :)

And to think I went looking for the man pages for pacman :oops:

I'll add an edit to post #1 asking that people identify their distros of Linux, or even if it's Ubuntu, Xubuntu, Kubuntu as things might be different. ie: calls for gedit, mousepad and kate, or gnome-terminal, xfce4-terminal or konsol. Yea, that makes sense to me.

Bruce M.
April 4th, 2008, 08:52 PM
:oops:
i think you spelt .bashrc wrong. :oops:

Not true! [-X teh keys on my keybored move around on purpose just to confuse me. I'm a perfect speler! :lolflag:
I've put in a call to a mod to see it it can be changed.

How embarrassing! :roll: Did I really do that?

Have a great day
Bruce

p_quarles
April 4th, 2008, 08:57 PM
You could easily tweak apt-get/aptitude to your liking in a similar way, something maybe like this:


alias aptup="sudo apt-get update && sudo apt-get upgrade"
alias aptget="sudo apt-get install"
alias aptrm="sudo apt-get remove"
alias aptsearch="sudo apt-get search"
alias aptinfo="sudo apt-get policy"
Close. The last two will return an "invalid operation" error, and do not require root privileges. They can be replaced with:

alias aptsearch='apt-cache search'
alias aptinfo='apt-cache policy'

Bruce M.
April 4th, 2008, 08:58 PM
Yeah, my bad Bruce, I should've explained that :) As others have stated, Pacman is the package manager for Arch linux, the distro I use-- the equivalent of apt-get/aptitude on your Ubuntu install. Those aliases for pacman I have are basically quick shortcuts to doing a system upgrade, installing a package, searching the package database, etc. You could easily tweak apt-get/aptitude to your liking in a similar way, something maybe like this:

We all make boo-boos take a look at the two I made; bascrc for goodness sake and then looking for packman.



alias aptup="sudo apt-get update && sudo apt-get upgrade"
alias aptget="sudo apt-get install"
alias aptrm="sudo apt-get remove"
alias aptsearch="sudo apt-get search"
alias aptinfo="sudo apt-get policy"

You've got the upgrade, install a package, remove a package, search for a package and show info of a package. Someone correct 'em if they're wrong, I'm a bit off on my Debanese ;)

Hey, Thanks for the updates, lets see if anyone says anything about your Debanese. :)

Bruce M.
April 4th, 2008, 09:04 PM
I define them as I go, recent ones:



alias code='cd /media/STORAGE/code/'
alias py='cd /media/STORAGE/code/pythonCode/'
alias compile='gcc p.c'
alias ncompile='gcc p.c -lncurses'


"p.c" or any file named p.* is a source file for practicing and testing. They are in my home directory, and are always there, but their content changes. It allows me to run and test code in many language easily.


p.c p.cpp p.cs p.d p.hi p.hs p.o p.php p.pl p.pp p.py p.rb p.sh


I don't program, and being new to Linux, Ubuntu is my first; I've told myself I'll stick to what's in the repositories for a while. Even though I have seen things that say they need compiling on the net, I steer clear until I learn more.

But thanks for the input, someone will find them useful I'm sure.

Bruce M.
April 4th, 2008, 09:06 PM
Close. The last two will return an "invalid operation" error, and do not require root privileges. They can be replaced with:

alias aptsearch='apt-cache search'
alias aptinfo='apt-cache policy'

Perfect you are always around to help.
Thanks, p_quarles.

Bruce M.
April 4th, 2008, 09:28 PM
alias aptsearch="sudo apt-get search"
alias aptinfo="sudo apt-get policy"
Someone correct 'em if they're wrong, I'm a bit off on my Debanese ;)


Close. The last two will return an "invalid operation" error, and do not require root privileges. They can be replaced with:

alias aptsearch='apt-cache search'
alias aptinfo='apt-cache policy'

I've noticed that with ARCH Linux there is a double quote (") and in Debanese you are using a single quote (').

Does it make a difference?

mali2297
April 4th, 2008, 09:42 PM
I've noticed that with ARCH Linux there is a double quote (") and in Debanese you are using a single quote (').

Does it make a difference?

Not in these cases. If you want to learn about quoting, see here:
http://www.linuxcommand.org/wss0060.php

herbster
April 4th, 2008, 09:51 PM
Take note that the .bashrc is a distro-indifferent file.

herbster
April 4th, 2008, 09:52 PM
Close. The last two will return an "invalid operation" error, and do not require root privileges. They can be replaced with:

alias aptsearch='apt-cache search'
alias aptinfo='apt-cache policy'

Ah yes, apt-cache. Me Debanese stands corrected! :D Good stuff.

bobbocanfly
April 4th, 2008, 10:15 PM
Here are some of mine, mainly for mounting my NFS shares. 'kff' i dont use in Hardy any more as FF3b4/5 is much stabler than 2.x in Gutsy, which would lock up *loads*.


alias mnt-mp3="sudo mount -t nfs penguin:/media/Media ~/Media"
alias mnt-www="sudo mount -t nfs penguin:/var/www ~/www"
alias mnt-docs="sudo mount -t nfs penguin:/home/bobbo ~/Documents"
alias mnt="mnt-docs; mnt-www; mnt-mp3"
alias kff="killall firefox-bin"

Bruce M.
April 4th, 2008, 10:26 PM
Not in these cases. If you want to learn about quoting, see here:
http://www.linuxcommand.org/wss0060.php

WoW! Even I understood that! Great link. Thanks mali2297
And the "Learning the Shell" is good too, easy to read and understand. I especially like the comment:

Welcome to Computer Literacy 101. Now let's get to work.

EDIT: I've just spent the last half hour reading stuff in that link.
What a GEM it is. Thanks again, Bruce

Bruce M.
April 4th, 2008, 10:35 PM
Here are some of mine, mainly for mounting my NFS shares. 'kff' i dont use in Hardy any more as FF3b4/5 is much stabler than 2.x in Gutsy, which would lock up *loads*.


alias mnt-mp3="sudo mount -t nfs penguin:/media/Media ~/Media"
alias mnt-www="sudo mount -t nfs penguin:/var/www ~/www"
alias mnt-docs="sudo mount -t nfs penguin:/home/bobbo ~/Documents"
alias mnt="mnt-docs; mnt-www; mnt-mp3"
alias kff="killall firefox-bin"

So I take it that kff kills Firefox when hitting the [X] button on FF does nothing.
Every now and then I watch FF eat up 100% of my CPU resorces and "FREEZE" :(
[Ctrl]+[Alt]+[Backspace] doesn't seem to work always as FF "saves the session"

erginemr
April 4th, 2008, 10:40 PM
Here are mine:

alias cd..='cd ..'
alias ls='ls -F --color=auto'
alias totem='env LC_CTYPE="en_US.utf-8" totem'

1st one eliminates the need to put a space between cd and ..

2nd one colorizes the text screen and adds symbols as suffixes to different files types and folders. (See the attachment.)

3rd one makes running programs with different language settings possible. I needed this as Totem in Gutsy refused to run in Turkish LANG setting.

il-luzhin
April 5th, 2008, 07:04 AM
alias damn-leak='compiz --replace --indirect-rendering'

Don't use this one as much since I switched to fluxbox

Bruce M.
April 5th, 2008, 01:39 PM
alias damn-leak='compiz --replace --indirect-rendering'

Don't use this one as much since I switched to fluxbox

I don't use compiz (did the replace --metacity thing) as it won't work here. I take it by leak you mean a memory leak?

Bruce M.
April 5th, 2008, 03:09 PM
Found something that *I* think is important for people new to Linux, and the .bashrc ...

It's the (bash) Reserved Word Index (http://info2html.sourceforge.net/cgi-bin/info2html-demo/info2html?(bash)Reserved%2520Word%2520Index), words & symbols we can not use in aliases.

Bruce M.
April 5th, 2008, 04:16 PM
I've noticed that with ARCH Linux there is a double quote (") and in Debanese you are using a single quote (').

Does it make a difference?


Not in these cases. If you want to learn about quoting, see here:
http://www.linuxcommand.org/wss0060.php

yes... I found it:


bruloo@bruloo:~$ echo "My host name is $HOSTNAME."
My host name is bruloo.
bruloo@bruloo:~$ echo 'My host name is $HOSTNAME.'
My host name is $HOSTNAME.
bruloo@bruloo:~$

If you "imbed" a variable inside a command it needs a double-quote. There may be other reasons, but this is a start.

Have to try that in an alias. :)

herbster
April 5th, 2008, 07:54 PM
Few more:


alias bg="sh /home/bobby/ulscript"

I use this all the time, I basically do "bg file.jpg" and it uploads whatever file to my web server via SSH in a jippy to share if needed quickly (screenshot of an error or what have you) :D


alias tarmake="tar czf"

Quick way to make a .tar.gz. Substitute the "z" with "j" for bzip2 compression if you like. Can also make another alias that would do it or replace that one with j.


alias lsh="ls -sh"

List all with human-readable sizes (M instead of bytes, etc.).

alienexplorers
June 18th, 2008, 03:27 PM
My alias list looks like this:

alias aai='sudo aptitude install'
alias aau='sudo aptitude update'
alias search='sudo aptitude search'
alias show='sudo aptitude show'
alias aar='sudo aptitude remove'
alias aap='sudo aptitude purge'
alias asu='sudo aptitude safe-upgrade'
alias clean='sudo aptitude clean'
alias autoclean='sudo aptitude autoclean'
alias orphan='sudo gtkorphan'
alias alsa='sudo alsamixergui'
alias id='sudo vol_id'
alias clr='clear'
alias ll='ls -l'
#alias la='ls -A'

I like aptitude better than apt-get as you can see from my alias list.

alienexplorers
June 18th, 2008, 03:47 PM
Is there a way of making aliases for the root gnome-terminal. I know its a .bashrc file, but I'm not sure where it is?

RiceMonster
June 18th, 2008, 03:53 PM
right now I have these:

alias obmenu='vim ~/.config/openbox/menu.xml'
alias obrc='vim ~/.config/openbox/rc.xml'
alias obstart='vim ~/.config/openbox/autostart.sh'
alias progfiles='cd ~/.wine/drive_c/Program\ Files/'
alias cdrive='cd ~/.wine/drive_c/'

I'll probably make a few more

Stefanie
June 19th, 2008, 12:47 PM
alias apt='sudo apt-get install'
alias aptup='sudo apt-get update'
alias aptupgr='sudo apt-get upgrade'
alias apti='sudo aptitude install'
alias se='synce-sync-engine'
alias sy='msynctool --sync hhsync'
alias suge='gksudo gedit'
alias pac='cd /home/username/Documents/packages'
alias networkrestart='sudo /etc/init.d/networking restart'
# extract tarballs etc met 1 command
extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) rar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}

the last one is to extract packages with a single command: instead of typing tar sjf, xzf, etc all the time i just type "extract package.rar/tgz/tar" . i didn't write this myself , i just copied it from someone in the cool-applications thread :-)

Dr Small
June 19th, 2008, 01:27 PM
Here is a list of GPG Alias I just wrote up last night:


#GPG Aliases
alias gpgen='gpg -e -r $1 $2'
alias gpgde='gpg -d $1'
alias gpgretr='gpg --keyserver keyserver.ubuntu.com --recv-keys $1'
alias gpgcl='gpg --clearsign $1'
alias gpgfp='gpg --fingerprint $1'
alias gpgsk='gpg --send-keys --keyserver keyserver.ubuntu.com $1'

But here is one that is very important, and that I use alot. It is very easy to type if on Dvorak, and is a Vim shortcut key:

alias :q="exit"

It saves me alot of typing :)

RedSquirrel
June 21st, 2008, 03:30 AM
Is there a way of making aliases for the root gnome-terminal. I know its a .bashrc file, but I'm not sure where it is?
Look in /root.


Some of mine:


alias l='ls -lh'
alias lrt='l -rt'
alias grepn="grep -n --color=auto"

monstermudder78
June 21st, 2008, 05:13 AM
alias upd='sudo aptitude update'
alias upg='sudo aptitude safe-upgrade'
alias install='sudo aptitude install'
alias purge='sudo aptitude purge'
alias clean='sudo aptitude autoclean'

I think they are self explanatory. Great thread tho:KS.