LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 01-18-2007, 01:07 PM   #1
exit3219
Member
 
Registered: May 2005
Location: Moldova
Distribution: Kubuntu
Posts: 199

Rep: Reputation: 30
Thumbs up Useful shell aliases


I spend a lot of time in the command line. Bash is my shell of choice.
Here are the aliases I use (most of them are stolen from The Bash Beginner's Guide)
Code:
alias ls='ls --color'
alias ll='ls -l'
alias l='ls -CF'
alias la='ls -A'
alias lla='ll -A'
alias dir='ls -ba'
alias lh='ll -h'

alias dh='df -h'
alias md='mkdir'
alias c='clear'
alias p='pstree -pl'
alias j='jobs'
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias e='nano'
alias m='less'
alias a='cat'
alias h='history 30'
alias hh='history'

alias gh='history |grep $1'
alias ii='dpkg -l |grep $1'
alias ir='ps aux |head -n 1 && ps aux |grep $1' # this one outputs some garbage at the end.
                                                # can't find an easy way to avoid it.

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

alias rmprog='rm -vf *.o *.e *.bak *~ *.out *.class *.gcov *.gcda *.gcno'

# alias xwpe='xwpe -font 9x15'
# when I used to use xwpe
# alias hibernate='kdesktop_lock --forcelock &  sudo hibernate'
# when I used to use swsusp2
I'm using 'ii basket' to see if basket is installed, for example, and not the awkward 'dpkg -l |grep basket'. The ones I use most are c for clear, a for cat, m for less, and .. for 'cd ..'. And sometimes I get frustrated when I boot off a live-cd and these aliases aren't there :P

What shell shortcuts do you use (and want to share)?
 
Old 01-18-2007, 01:30 PM   #2
asommer
Member
 
Registered: Mar 2003
Location: North Carolina
Distribution: Gentoo
Posts: 168

Rep: Reputation: 30
Here's one that you don't have:

alias grep="grep --color=auto"

It'll highlight any matches.

Lot of those are interesting thanks for the post.
 
Old 01-18-2007, 02:59 PM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,394
Blog Entries: 55

Rep: Reputation: 3565Reputation: 3565Reputation: 3565Reputation: 3565Reputation: 3565Reputation: 3565Reputation: 3565Reputation: 3565Reputation: 3565Reputation: 3565Reputation: 3565
I don't use much aliases in bash, most of what I need is stuffed in resource files and those are mostly functions like
Code:
sslEncFile() { openssl enc -e -bf -in "$1" -out "$1".ssl_enc; }
# or
functioncount() { fc=($(declare -F|wc -l)); echo "${FUNCNAME}: ${fc[0]} loaded."; }
# but
some are nested ones which load/unload sets of functions and aliases for specific tasks like auditing, network diagnosis, package management, etc, etc.
 
Old 01-20-2007, 08:29 AM   #4
exit3219
Member
 
Registered: May 2005
Location: Moldova
Distribution: Kubuntu
Posts: 199

Original Poster
Rep: Reputation: 30
Great suggestions, got into my .bashrc.
asommer: I didn't even know grep can highlight. Thanks!
Some new ones (I'm still thinking of better names for them):
alias push='pushd .'
alias pop='popd'

Amarok can't play over smb:// so I have to mount the remote partition manually:
alias smbx='sudo mount -t smbfs -o username=exit //desktop/x$ /media/samba/'
alias unsmbx='sudo umount /media/samba/'

There's another nice list on http://www.novell.com/coolsolutions/tools/17142.html

Happy bashing!
 
Old 01-21-2007, 12:13 AM   #5
lurko
Member
 
Registered: Jun 2006
Location: Ontario, Canada
Distribution: Debian
Posts: 448

Rep: Reputation: 35
just might have to adopt a couple of those myself, thanks for posting. here's a couple more:

Code:
alias dvdb="growisofs -dvd-compat -Z"
alias dumd1="du -h --max-depth=1 $1"
I wanted to include the "/dev/dvd=" part of the growisofs command so I could just enter "dvdb dvd.iso" but I could never get it to work. My own fault for not reading more than I have I guess.

I suppose this is as good a time as any to ask what the gurus think, would this work?
Code:
alias "dvdb\ "=growisofs -dvd-compat -Z /dev/dvd=$1"
I guess I'll try it and see...

edit: it does not work. for starters, the alias definition is missing it's opening ". Fixed that, and tried mulitple variations on my idea of putting a space in the alias name, but bash is having none of it. woe. well, not really because since I've been using gnome, I tend to just right click on isos and select "write to disc". I think I've highlighted my ineptitude enough for one day now.

Last edited by lurko; 01-21-2007 at 12:28 AM.
 
Old 01-21-2007, 04:45 AM   #6
exit3219
Member
 
Registered: May 2005
Location: Moldova
Distribution: Kubuntu
Posts: 199

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by lurko
Code:
alias "dvdb\ "=growisofs -dvd-compat -Z /dev/dvd=$1"
Functions seem to work for that:
Code:
function dvdb()
{
   growisofs -dvd-compat -Z /dev/dvd=$1;
}

dvdb test.iso
You can see exactly what bash expands stuff into by doing
Code:
set -x
This will activate the debug mode. You will see exactly what is going on. To disable it use
Code:
set +x
Edit: corrected the set commands

Last edited by exit3219; 01-21-2007 at 11:45 AM.
 
Old 01-21-2007, 07:43 AM   #7
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,394
Blog Entries: 55

Rep: Reputation: 3565Reputation: 3565Reputation: 3565Reputation: 3565Reputation: 3565Reputation: 3565Reputation: 3565Reputation: 3565Reputation: 3565Reputation: 3565Reputation: 3565
More in ye aulde LQ Tips and Tricks thread...
 
Old 01-21-2007, 11:21 AM   #8
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Tribblix, Ubuntu/WSL
Posts: 9,760

Rep: Reputation: 459Reputation: 459Reputation: 459Reputation: 459Reputation: 459
Quote:
Originally Posted by exit3219
Code:
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
Although being widespread and commonly advertised, these three are unfortunately the dumbest and most dangerous aliases ever ...
 
Old 01-21-2007, 11:39 AM   #9
exit3219
Member
 
Registered: May 2005
Location: Moldova
Distribution: Kubuntu
Posts: 199

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by jlliagre
Although being widespread and commonly advertised, these three are unfortunately the dumbest and most dangerous aliases ever ...
Why? because they delude users to "trust the system" and not read the commands they type before hitting RETURN?

The thread unSpawn recommended was a real eye-opener. Here's what I liked most (credits go to the initial posters)
  • If I knew Ctrl+L clears the terminal I'd never resort to alias c='clear'
  • splitvt is amazing. I'm just beginning to realize it's power (for programming mostly).
  • $ > /var/log/messages to "null" (truncate) a file without removing it. Wow! I used rm file && touch file, and programs using the file at the time really didn't like it. This is a much more elegant solution.

And one more humble tip from myself. Here's how I watch my wireless connection from the CLI:
Code:
watch -n 0.5 iwconfig wlan0
 
Old 01-21-2007, 12:29 PM   #10
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Tribblix, Ubuntu/WSL
Posts: 9,760

Rep: Reputation: 459Reputation: 459Reputation: 459Reputation: 459Reputation: 459
Quote:
Originally Posted by exit3219
Why? because they delude users to "trust the system" and not read the commands they type before hitting RETURN?
Not exactly. The danger is they change these commands semantics.

When you use these aliases, you became accostumed to their behaviour about asking you for confirmation before doing nasty things.

Sooner or later, you'll log in as root on a machine where these aliases are not set, start some housekeeping waiting for the prompts (eg. rm *) , and bingo ...

My advice: create aliases with a different name than the original commands, say "rmi, mvi, cpi", and use the aliases.

Last edited by jlliagre; 01-21-2007 at 12:30 PM.
 
Old 01-21-2007, 12:54 PM   #11
exit3219
Member
 
Registered: May 2005
Location: Moldova
Distribution: Kubuntu
Posts: 199

Original Poster
Rep: Reputation: 30
I haven't thought of that (I'm root only on my home PC), but you got me convinced. I've found these aliases in Kubuntu (either in ~/.bashrc or in /etc/bash.bashrc) and thought they were harmless. But now I see they could indeed cause trouble.
I learn so much from this thread
 
Old 01-22-2007, 06:57 AM   #12
lurko
Member
 
Registered: Jun 2006
Location: Ontario, Canada
Distribution: Debian
Posts: 448

Rep: Reputation: 35
Quote:
Originally Posted by exit3219
Functions seem to work for that:
hey! they certainly do - thanks for the tip, that was pretty simple.
 
Old 02-04-2007, 10:31 AM   #13
exit3219
Member
 
Registered: May 2005
Location: Moldova
Distribution: Kubuntu
Posts: 199

Original Poster
Rep: Reputation: 30
I've found this (pretty old) page today. What I didn't know is that Ctrl+R can be used multiple times, to scan backwards through the matches. The comments are pretty insightful as well - did you know about ESC-period?
That same page led me to this site, which sends tips daily by e-mail. Looks pretty good, so I subscribed.

Last edited by exit3219; 02-04-2007 at 10:33 AM.
 
Old 02-04-2007, 07:01 PM   #14
pdw_hu
Member
 
Registered: Nov 2005
Location: Budapest, Hungary
Distribution: Slackware, Gentoo
Posts: 346

Rep: Reputation: Disabled
alias sshname='ssh -p x user@host.com'
alias blankcd='cdrecord -dev=/dev/hdc -blank=fast'
alias writecd='cdrecord -dev=/dev/hdc -v -dao -eject driveropts=burnfree'
 
Old 03-16-2007, 05:18 AM   #15
fvu
LQ Newbie
 
Registered: Nov 2006
Distribution: Ubuntu 7.10
Posts: 28

Rep: Reputation: 15
Ssh to current working dir on server

Problem

When you're on an NFS share or a Subversion checkout, you may find yourself wanting to connect to the server, but to the same directory as you're currently in. By default, ssh just goes to your $HOME directory, as specified in your server shell startup script:

Code:
   client                             server
+--------------+                   +-----------+
| /mnt/proj/x  |<====== NFS ======>| ~/proj/x  |
+--------------+                   +-----------+
+--------------+                   +-----------+
| ~/proj/y     |<== SUBVERSION ===>| ~/proj/y  |
+--------------+                   +-----------+
      -----                            -----
        |                                |
        +------>------ SSH ------>-------+
          problem: SSH connects you to ~
Solution

Within bash, define this alias s to connect to your server replace hostname with yours:

Code:
    # Ssh to server
    # If directory [/mnt]$PWD exists on server as [$HOME]$PWD, cd to it
alias s='ssh -t hostname "test -d \"${PWD/#\/mnt/$HOME}\" && cd \"${PWD/#\/mnt/$HOME}\"; bash -login"'
See also: http://www.fvue.nl/wiki/Ssh_to_curre..._dir_on_server

Freddy Vulto
http://www.fvue.nl
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
aliases and the 'sh' shell koodoo Linux - Newbie 14 08-05-2006 05:19 AM
sendmail and NIS databases (aliases, mail.aliases) - what kind of databases? cotton213 Linux - Software 0 03-14-2006 06:57 PM
See aliases gubak Linux - Newbie 0 08-04-2004 07:13 AM
Comparison of shell functions and aliases? slakmagik Programming 3 02-07-2004 06:12 AM
aliases depaul Linux - Software 23 07-30-2003 07:49 PM

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

All times are GMT -5. The time now is 05:18 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration