Results 1 to 4 of 4

Thread: How to alias a path in .bashrc

  1. #1
    Join Date
    Nov 2013
    Beans
    7

    How to alias a path in .bashrc

    I want to create an alias like this in my .bashrc

    Code:
    alias trash="~/.local/share/Trash/files"
    in order to use the aliased location like this

    Code:
    mv trash
    but it doesn't work. How can i achieve this?

  2. #2
    Join Date
    Jun 2007
    Location
    Arizona U.S.A.
    Beans
    2,080

    Re: How to alias a path in .bashrc

    An alias must use a command. It cannot just represent a string.

    Correct usage:
    Code:
    dmn@Sydney:~$ alias greeting='echo "how are you today?" '
    dmn@Sydney:~$ greeting
    how are you today?
    Incorrect usage:
    Code:
    dmn@Sydney:~$ alias photos="~/Pictures"
    dmn@Sydney:~$ cd photos
    bash: cd: photos: No such file or directory

  3. #3
    Join Date
    May 2005
    Location
    Lyon, France
    Beans
    916
    Distro
    Ubuntu Development Release

    Re: How to alias a path in .bashrc

    have a look in .bashrc to see what is an alias.

    you don't need an alias to delete things in command line. use rm.

    you can use functions to ease your life. put those functions in bashrc or bash_aliases
    James Dupin
    IT contractor
    Project delivery specialist
    http://fr.linkedin.com/in/jamesdupin

  4. #4
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,468
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: How to alias a path in .bashrc

    that won't work, aliases match only beginning of the line
    alias xxx=yyy
    xxx something <- this will substitute alias
    something xxx <- this won't

    you might try:
    - using a custom variable
    Code:
    trash=~/.local/share/Trash/files
    mv ... $trash
    - creating a symlink to ~/.local/share/Trash/files in ~
    Code:
    ln -s ~/.local/share/Trash/files ~/trash
    mv ... ~/trash
    - creating a custom function
    Code:
    mvt() { mv -t ~/.local/share/Trash/files -- "$@"; }
    mvt <files>
    i'd go with a function
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

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
  •