Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: command alias

  1. #1
    Join Date
    May 2008
    Beans
    99

    command alias

    Hello everyone, I'm pretty new to Ubuntu and want to have some shell commands to make my work easier. Basically I hope to have a short cut like this:
    Code:
    goto nameabc123456
    and then I go to the directory
    Code:
    ./name/abc/123/456/
    How could I get this work? Do I need to write some python scripts?
    Any suggestions are welcome!

  2. #2
    Join Date
    Jul 2007
    Location
    Burlington, NC
    Beans
    1,995
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: command alias

    The TAB key is your best friend: http://en.wikipedia.org/wiki/Command_line_completion
    Give me Free Software or Give me Death!

  3. #3
    Join Date
    May 2008
    Beans
    99

    Re: command alias

    Sorry I might not make it very clear. It's for our daily work and the directories is much deeper than I wrote. Just imagine it's something like:

    Code:
    /name/test/xxx/year/month/day/version/abc/123/456
    So I need to make it as easy as possible.

  4. #4
    Join Date
    Apr 2006
    Location
    Montana
    Beans
    Hidden!
    Distro
    Kubuntu Development Release

    Re: command alias

    Add an alias to ~/.bashrc

    The syntax is

    alias shortcut = command

    I advise you use the full path to most commands, but cd is "built in"

    Code:
    alias foo='cd /full/path/to/directory'
    change "foo" and the path as needed.
    There are two mistakes one can make along the road to truth...not going all the way, and not starting.
    --Prince Gautama Siddharta

    #ubuntuforums web interface

  5. #5
    Join Date
    May 2008
    Beans
    99

    Re: command alias

    Our file system have thousands of the code in this style. So I have to have a function like command that I get quick path change when I input "goto name123456" "goto name 254157" "goto name521516" etc.

  6. #6
    Join Date
    Apr 2006
    Location
    Montana
    Beans
    Hidden!
    Distro
    Kubuntu Development Release

    Re: command alias

    Quote Originally Posted by Unewbeginner View Post
    Our file system have thousands of the code in this style. So I have to have a function like command that I get quick path change when I input "goto name123456" "goto name 254157" "goto name521516" etc.
    Then you shall have to write a script to do that for you. Without knowing your thousands of directories it would be guess work for us to start something like this for you.

    http://linuxcommand.org/
    There are two mistakes one can make along the road to truth...not going all the way, and not starting.
    --Prince Gautama Siddharta

    #ubuntuforums web interface

  7. #7
    Join Date
    Jul 2007
    Location
    Burlington, NC
    Beans
    1,995
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: command alias

    For specifying a full path, it can't get any faster than tab completion.
    Tab completion also guarantees no typos.
    Give me Free Software or Give me Death!

  8. #8
    Join Date
    May 2008
    Beans
    99

    Re: command alias

    Quote Originally Posted by bodhi.zazen View Post
    Then you shall have to write a script to do that for you. Without knowing your thousands of directories it would be guess work for us to start something like this for you.

    http://linuxcommand.org/
    Our system is for multiple users, and then has a level related to user names(like Mike, Tom, Kate, etc). And the system has some codes for detail information, a 3-character code (for example "abc", "exj", "tsr", etc".
    Then two sets of numbers (each has 3 digits). You could call it test codes.
    Then some individual folders for the test results (pic for all pictures, sim for all simulations, etc).

    Below are some examples for our folders.
    Code:
    /Projects/tsr/job/mike/012/531/sim
    /Projects/ace/job/tom/423/151/pic
    I want to develop a shortcut for this:
    when mike inputs the command below on his machine, then he gets to the first directory above.
    Code:
    sim tsr012531
    when tom inputs the command below on his machine, then he gets to the second directory above.
    Code:
    pic ace423151
    Hope it makes things clear

  9. #9
    Join Date
    Jul 2008
    Location
    Canada
    Beans
    8
    Distro
    Ubuntu

    Re: command alias

    echo "anyName(){cd /thing/one/$1/awesome/$2/$3;}" | tee -a ~/.bashrc
    (also, what the code after the | does is copy the code between the "" into the .bashrc file (which is where you store your aliases and extra functions))

    doing that will go to /thing/one/my/awesome/code/isAwesome if you type on
    anyName my code isAwesome

    BUT, keep in mind, they NEED to be separated by space.

    also going with your example if I wanted tom to go to: /Projects/ace/job/tom/423/151/pic when he typed in: pic ace 423 151
    "goToFolder(){cd /Projects/$2/job/$USER/$3/$4/$1;}"

    Although I will however say that it really is much easier to specify a full path via Tab-completion.
    Last edited by brishu; November 28th, 2010 at 11:47 AM.

  10. #10
    Join Date
    Jul 2009
    Location
    London
    Beans
    1,480
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: command alias

    a bash function like this may give you a start:
    Code:
    function pic() {
        input=$1
        first=${input:0:3}
        remaining=${input:3}
        trailing_path=""
        while true
        do
            [[ ${#remaining} -le 0 ]] && break
            trailing_path="${trailing_path}${remaining:0:3}/"
            remaining=${remaining:3}
        done
        requested_dir="$first/job/$USER/${trailing_path}pic"
        cd $requested_dir
    }

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •