ls: cannot access '*.txt': No such file or directory
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
This is a shot in the dark, but the ls command, like the dir command, is not recursive. It will search only the current directory.
If you issue the command in your home directory, it will search only /home/[username]. It will not search the /home/[username]/Documents or /home/[username]/Desktop directories.
If you want a recursive search, use locate or find. See their man pages for more. (Personally, I prefer locate for simple searches.)
This is a shot in the dark, but the ls command, like the dir command, is not recursive. It will search only the current directory.
If you issue the command in your home directory, it will search only /home/[username]. It will not search the /home/[username]/Documents or /home/[username]/Desktop directories.
If you want a recursive search, use locate or find. See their man pages for more. (Personally, I prefer locate for simple searches.)
Oh, and welcome to LQ.
It isn't recursive by default, but if you call ls -R it will list files/directories recursively.
I should have clarified that ls is more suited for listing directories, not finding files like find does. So, as frankbell suggested, try using find. Or, if you really want to use ls, try ls Documents/*.txt Desktop/*.txt.
Won't work as "/*.txt" will be expanded by the shell as
all of the .txt files in the root (/) directory, which normally should be none!
So this will return a "No match" error.
Last edited by ehartman; 08-04-2019 at 06:35 AM.
Reason: typin error
That ~ in the command prompt means your in your home directory. There are many ways to search for files. This will change to Documents directory.
cd Documents
ls *.txt
While conceding that the lack of code tags makes the OP's statement difficult to read, I'm pretty sure that the ~ is part of the prompt (PS1) and not part of the command.
That said, yes, cd to a directory and then list will work. So will (from the user's home directory)
Code:
ls -R */*.txt
(and I, too, learned of the -R option in this thread. I can see its usefulness...)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.