This is probably a very simple thing but I can’t find an answer, possibly because I don’t know what terms to use in search.

How do I use an alias of a path with mv or cp? Or even cd?

In /etc/bash.bashrc I have: alias docs=‘/media/docs

cd docs Gives “No such file or directory”

Yet: docs Gives “Is directory”

With alias docs=‘cd /media/docs’ and by typing docs I get into the directory. Obviously I can’t use that alias with mv or cp though.

Maybe this isn’t even an intended use of alias but still. Why doesn’t it work?

  • MimicJar@lemmy.world
    link
    fedilink
    arrow-up
    8
    ·
    edit-2
    11 hours ago

    You might find a symbolic link useful. For example

    ln -s /media/docs ~/docs
    

    Now you’ll have a “folder” in your home directory named “docs” that points to “/media/docs”. You can use that path with commands like mv or cp.

    These commands now both move “myfile” to the same location

    mv myfile ~/docs
    mv myfile /media/docs
    
    • MolochHorridus@piefed.socialOP
      link
      fedilink
      English
      arrow-up
      2
      ·
      edit-2
      10 hours ago

      Thanks, but the problem with this is that I’ll type /media/docs/whatever much faster than hunt the ~ from my keyboard because I have to move my whole hand to do so.

      It’s altGr + ^ on my keyboard.

      • teawrecks@sopuli.xyz
        link
        fedilink
        arrow-up
        3
        ·
        8 hours ago

        Highly recommend remapping common characters to easy-to-access hand movements. The keyboard is a tool to make things easier. I never use caps-lock, but I use esc all the time, so I regularly swap them (or just have a second esc bind).

      • False@lemmy.world
        link
        fedilink
        arrow-up
        2
        ·
        9 hours ago

        That sounds inconvenient. I use ~ all the time. $HOME should point to the same dir in most cases though