Comments

Unix tip: Useful Unix aliases

Unix aliases provide an easy way to customize your working environment. Let's look at some especially useful aliases that you might like.

View full article »
Chatter

Aliases etc.

Thanks - there were some useful aliases in your latest article. You might like this function, which I find very useful when looking for permission errors:

lsdup() {
here=$(pwd)
while true
do
print "$(ls -ld) $PWD"
cd ..
[ $PWD = "/" ] && break
done
cd $here
}

| reply

moving to previous directory

To go back to the previous directory I just use "cd -". No special alias is required. But what if you're working amongst three directories? What's a good way to quickly set up shortcuts which allow to bounce between them?
| reply

aliases

You may not want to aliase rm -i as rm, especially if you use rm to remove files, etc using a script in cron, using the next choice would be better.
| reply

grep through code

Here's one I like to use, this one for Python applications, but easy to set up for other languages as well:

alias greppy="find . | grep -v [.]svn | grep -v bundle | grep [.]py$ | xargs grep "

Beginning with the current directory, look for all of the Python files that are not part of subversion, not part of a bundle, skipping those that are like .py~ and .pyc, and pass those to grep.
| reply

Use of alias for rm -1

Regarding the comment on not aliasing rm to 'rm -i' due to its effect in scripts:

An alias shouldn't make any difference in scripts, as scripts should have hard paths for commands.

Scripts should contain something like this:

RM=/bin/rm
LS=/bin/ls
...

rm is then called in the script as $RM

There are at least 2 reasons for doing so:

* Your script will always run /bin/rm, not some script or executable named 'rm' that appears somewhere in your PATH
This is the same reason you probably don't want ./ in your path

* The PATH value becomes irrelevant to the running of frequently used commands in the script.

Personally, I use a function hardpath() that determines the location of each executable within a predetermined set of directories, and sets the requisite variable to that location. The script fails if a required executable is not found in the path set.


| reply

CD between 3 directories quickly

THE CODE:
cdA()
{
A_old_dir=$PWD
[ ! -z $* ] && A_new_dir=$*
cd $A_new_dir
}
cdB()
{
B_old_dir=$PWD
[ ! -z $* ] && B_new_dir=$*
cd $B_new_dir
}
cdC()
{
C_old_dir=$PWD
[ ! -z $* ] && C_new_dir=$*
cd $C_new_dir
}
alias ,a=cdA
alias ,b=cdB
alias ,c=cdC

# I use a comma as a shortcut to 'cd'
# Both begin with a comma.
# Now ,a is easier than cdA
# Your choice, name them anything.

# try these
,a /usr/local/bin # puts you in specified directory
,b /var/adm
,c /usr/bin

# now use just the alias (no directory)
,a # puts you in /usr/local/bin
,c # puts you in /var/adm
,c # puts you in /usr/bin


# and my two favorite cd-related shortcuts
alias ,=cd # cd to a directory
alias ,,='cd -' # cd back to the previous directory


# I picked parts of these up over the years doing
# UNIX support. I've tweaked them and made them
# do what I've needed. Have fun.
| reply

typos - CD between 3 directories quickly

I meant to say that 'cd' and comma both begin with a 'c', that's how I remember it.

Also, in the 'now use just the alias' section, the second one should be ,b (not ,c).

Ciao
| reply

Unix alias

Some more information about unix alias command
| reply

replica bags

If I didn't read this artcle ,I wounldn't believe these things replica bags happened in the world . Why people are always replica handbags so stoniess to others ? Man are really stupy creature.
| reply
Post a reply
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
peer-to-peer

jfruh
Apple syncing patent can't come soon enough

pasmith
New Twitter features borrow from 3rd party clients

Esther Schindler
Open Source Changes the Software Acquisition Process

mikelgan
How to set up continuous podcast play on the new iTunes

David Strom
Five important Windows 7 mobility features

sjvn
Guard your Wi-Fi for your own sake                        

Sandra Henry-Stocker
Grepping on Whole Words

 

Sidekick: The Good News & the Bad News
Either way you look at it Microsoft Data Center management did not follow standards or best practices in this failure. In which case it makes me wonder more about the outsourcing of corporate data much less personal data.
- mburton325

Join the conversation here

The Daily Tip

The Daily TipQuick, practical advice for IT pros. Made fresh daily.

Hot tips:

Want to cash in on your IT savvy? Send your tip to tips@itworld.com. If we post it, we'll send you a $25 Amazon e-gift card.

Newsletters

Subscribe to ITWORLD TODAY and receive the latest IT news and analysis.

I would like to receive offers via email from ITworld partners.
By clicking submit you agree to the terms and conditions outlined in ITworld's privacy policy.
Featured Sponsor

AISO founders envisioned a Web hosting company that was environmentally friendly. While the company employed energy-efficient innovations like solar panels, its infrastructure produced unacceptable power and cooling requirements. Find out how AISO leveraged AMD technology to overcome their challenge in this case study white paper.

In this whitepaper, Scalar explores the opportunity to change the landscape with respect to mission critical databases built around Oracle. Leveraging technologies such as Linux, high-end commodity processing power and Oracle RAC technology to architect, design, build and maintain database infrastructure that delivers maximum availability, reliability and performance at a fraction of traditional cost.

On a typical day, weather.com, the Web site for The Weather Channel in Atlanta, serves up between 15 million and 20 million page views. But in September 2004, when back-to-back hurricanes ransacked Florida, the peak traffic on one day more than tripled: over 70 million page views by more than 7 million unique visitors. Read the full success story now.

Marketplace