this post was submitted on 17 May 2026
24 points (100.0% liked)

Linux

65349 readers
517 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 7 years ago
MODERATORS
 

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?

you are viewing a single comment's thread
view the rest of the comments
[–] brandon@piefed.social 5 points 1 day ago* (last edited 1 day ago) (1 children)

By default bash will only expand an alias if it's the first argument of the command (that is, the command itself).

It's probably not intended to use aliases this way, and there are probably better options for you.

However, there is a little trick you can do. If the alias command ends in a space, then bash will also check the next argument:

alias cd='cd '

Notice the trailing space after 'cd' in the alias definition.

alias docs='/media/docs'

then, cd docs should work the way you expect.

Another method would be to:

alias docs='echo /media/docs'

Then you can do

cd `docs`  

The backticks will cause the shell to replace that portion with the output of the docs shell command, which will be expanded via the alias.

All that said, it's probably easiest just to use a link, like another commenter suggested.

[–] kibiz0r@midwest.social 2 points 20 hours ago

Cursed knowledge.