Score:4

Why doesn't the shell find a file inside the current directory by its name alone?

cn flag

I downloaded VS Code's .deb file for Ubuntu. I renamed it to vs.deb.

Then I go to my downloads directory:

cd ~/Downloads

And now that I'm here, I try to install it:

sudo apt install vs.deb

And here's what I get:

Reading package lists... Done   
Building dependency tree          
Reading state information... Done   
E: Unable to locate package vs.deb   
E: Couldn't find any package by glob 'vs.deb'

But when I install it using ./vs.deb, then it gets installed:

sudo apt install ./vs.deb

Why doesn't Linux accept the name of the file inside the same directory without requiring the relative path?

David avatar
cn flag
Is the current directory defined in any PATH statement? I think not therefore you need the ./ This is well known and not a stupid behavior.
Kulfy avatar
mz flag
Does this answer your question? [How do I install a .deb file via the command line?](https://askubuntu.com/questions/40779/how-do-i-install-a-deb-file-via-the-command-line) Quoting from [Braiam's answer](https://askubuntu.com/a/769542): *"Even if you are on the directory with the package you need to give a path using `./` at the start"*
guiverc avatar
cn flag
You are trying to install a file; so a path is required. Your command without a path is to download & install the package name you provided (it's more secure to not make assumptions that it could be a file but be a package in an approved source).
Peter Cordes avatar
fr flag
@David: If you're talking about the `PATH` environment variable, e.g. `/usr/local/bin:/bin:...` then no, it would make no sense for `apt` to search `$PATH` for `.deb` files given as args. The querent made a wrong assumption about the shell being relevant. Your comment might be misleading to beginners who don't realize that it doesn't actually apply; I'd suggest deleting it.
Score:19
cn flag

What you experience is not related to the shell, but to how the apt command interprets the arguments on the command line.

It is primarily aimed at installing packages from the software repositories. By default, an argument to apt means the name of a package in the software sources. The message:

E: Unable to locate package vs.deb

clearly indicates that a package vs.deb does not exist in the software sources.

Still, apt allows you to directly install a downloaded .deb package file and resolve dependencies for it. You must give an explicit file path to indicate you want to install a .deb file. ./vs.deb already indicates a file path: ./ means the current directory, so apt will find the vs.deb file in the current directory.

Actually, it is never the shell that "finds" a file. The shell just passes arguments to the application, and it is up to the application to interpret these arguments. At most, the shell does expansion (e.g. replacing * with all filenames or ~ with the full path of your home folder) or variable substitution (e.g. $HOME is replaced by the content of that variable).

chrylis -cautiouslyoptimistic- avatar
er flag
Arguably, brace expansion _does_ qualify as "finding" the files.
Peter Cordes avatar
fr flag
`apt`'s predecessor, `apt-get`, could never take a `.deb` as a command line option, only a package name; you had to use `dpkg -i` to install a .deb file. So there's historical precedent for Debian's higher-level package tools to *not* interpret args as paths, at least not by default.
cn flag
@chrylis-cautiouslyoptimistic- Brace expansion doesn't do anything related to files, it's a purely textual transformation. Wildcard expansion, on the other hand, does look for matching files.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.