LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-20-2006, 07:00 PM   #1
mettam
LQ Newbie
 
Registered: Jan 2006
Posts: 2

Rep: Reputation: 0
Alias help


Hi,
I can write simple aliases but I am stumped with this one, so I hope someone can help me with this alias syntax.

I have a directory with 100 folders all named like this:
work/
BAL001
BAL002
BAL003
etc

I would like to be able to type BAL013 and be taken to the BAL013 directory.


Justin.
 
Old 01-20-2006, 11:31 PM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
You are not looking for aliases---what you want is a soft link. Take a look at man ln for some details.

You can put a link to any file in any other directory.
 
Old 01-21-2006, 04:11 AM   #3
Electro
LQ Guru
 
Registered: Jan 2002
Posts: 6,042

Rep: Reputation: Disabled
Symbolic links will be too hard and takes some hard drive space. Alias can still be done.

To get to BAL013 using alias:

alias BAL013="cd BAL013"

Log out and log in. Then type BAL013 and you should be in BAL013 directory.
 
Old 01-21-2006, 07:25 AM   #4
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,760
Blog Entries: 4

Rep: Reputation: 78
Quote:
alias BAL013="cd BAL013"
But this will only work if you are in the parent directory of 'BAL013', and setting up 100+ of these is going to be very tedious. Plus, they will take up as much memory as the symlinks will take up disk space, if not more. I think this is a task better suited for a shell function:
Code:
cd_dir () {
    cd /home/mettam/work/${1}
}
and call it like:
Code:
$ cd_dir BAL013
You can put this function in your .bashrc and it will get sourced at login just like an alias.

Last edited by bulliver; 01-21-2006 at 07:29 AM.
 
Old 01-21-2006, 03:26 PM   #5
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,125

Rep: Reputation: 164Reputation: 164
As yet another alternative, set the bash CDPATH variable:

Code:
export CDPATH=.:/path/to/work
CDPATH now includes the current directory and /path/to/work and this works from anywhere in the file system. For example, if you are in /usr/local and you type `cd BAL001` you will be taken to /path/to/work/BAL001. See `man bash` and search for CDPATH for a bit more info.
 
Old 01-21-2006, 10:15 PM   #6
Electro
LQ Guru
 
Registered: Jan 2002
Posts: 6,042

Rep: Reputation: Disabled
I just gave an example. If mettam gave the full directory path to BAL013, then I would put the whole path.

A bash script needs to load up another terminal and run the command cd, so a bash script will take up both hard drive and memory space.
 
Old 01-22-2006, 02:17 AM   #7
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,760
Blog Entries: 4

Rep: Reputation: 78
Quote:
A bash script needs to load up another terminal and run the command cd, so a bash script will take up both hard drive and memory space.
Who said anything about a bash script? I mentioned a shell function, and the one I posted takes all of 33 bytes. If you put it in your .bashrc it will be sourced at login, and it will be available in the current terminal.

In any event, it is looking like gilead's solution is the most elegant for the OP's purposes.
 
Old 01-23-2006, 07:27 PM   #8
mettam
LQ Newbie
 
Registered: Jan 2006
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks for all your help.

The problem now is I am forced to use tcsh not bash, so my aliases are entered in my .cshrc.user file. I tryed to enter Bulliver's script in my .cshrc file but it didnt understand it.

Can someone give me the syntax for a .cshrc file.
Bulliver's file looks ideal if only it worked with tcsh.

Justin..
 
Old 01-23-2006, 07:42 PM   #9
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,760
Blog Entries: 4

Rep: Reputation: 78
Sorry guy, don't know csh syntax.

Have you tried, gilead's suggestion? it looks ideal. I think though you need to change 'export' to 'setenv' for csh.
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Alias question (2 commands for one alias) gflores Linux - Newbie 3 01-21-2006 01:40 AM
Alias ChimpFace9000 Linux - General 9 01-14-2004 05:01 AM
ip alias mindcry Linux - Networking 0 10-16-2003 08:41 PM
help with alias veteq99 Linux - Newbie 2 08-12-2003 05:23 PM
alias nobu Slackware 5 01-11-2003 02:09 PM


All times are GMT -5. The time now is 02:46 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