LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 08-03-2019, 09:36 PM   #1
mansitalmgr
LQ Newbie
 
Registered: Jun 2019
Posts: 1

Rep: Reputation: Disabled
ls: cannot access '*.txt': No such file or directory


I use windows 10. I have installed virtual box 6.0 and run ubuntu in it.
Tried to run mansital@VB:~$ ls *.txt

I got ls: cannot access '*.txt': No such file or directory

I have .txt files in Documents and Desktop folder.

Last edited by mansitalmgr; 08-03-2019 at 09:42 PM.
 
Old 08-03-2019, 09:46 PM   #2
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,311
Blog Entries: 28

Rep: Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137
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.

Last edited by frankbell; 08-03-2019 at 09:50 PM.
 
1 members found this post helpful.
Old 08-03-2019, 09:55 PM   #3
individual
Member
 
Registered: Jul 2018
Posts: 315
Blog Entries: 1

Rep: Reputation: 233Reputation: 233Reputation: 233
Quote:
Originally Posted by frankbell View Post
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.
 
1 members found this post helpful.
Old 08-03-2019, 10:05 PM   #4
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,311
Blog Entries: 28

Rep: Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137
Thanks, individual. I learned something thanks to you.
 
Old 08-03-2019, 10:29 PM   #5
individual
Member
 
Registered: Jul 2018
Posts: 315
Blog Entries: 1

Rep: Reputation: 233Reputation: 233Reputation: 233
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.
 
1 members found this post helpful.
Old 08-04-2019, 01:18 AM   #6
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,781

Rep: Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198
Try
Code:
ls -R /*.txt
 
Old 08-04-2019, 04:57 AM   #7
ehartman
Senior Member
 
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,674

Rep: Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888
Quote:
Originally Posted by MadeInGermany View Post
Try
Code:
ls -R /*.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
 
2 members found this post helpful.
Old 08-04-2019, 06:18 AM   #8
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,680

Rep: Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894
In addition
Quote:
Tried to run mansital@VB:~$ ls *.txt
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
 
1 members found this post helpful.
Old 08-04-2019, 09:08 AM   #9
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,781

Rep: Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198
In my last post I forgot that the shell handles the glob.
Well, then let the shell do it all.
In bash (>=4.0) try
Code:
shopt -s globstar
ls /**.txt

Last edited by MadeInGermany; 08-04-2019 at 09:09 AM.
 
Old 08-04-2019, 09:23 AM   #10
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,725

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Quote:
Originally Posted by michaelk View Post
In addition
Quote:
Tried to run mansital@VB:~$ ls *.txt
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...)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
"Cannot load library icui18n: (icui18n: cannot open shared object file: No such file or directory)" BW-userx Slackware 1 04-19-2019 08:13 AM
[SOLVED] read txt file into an array and make a second txt file zimbot Linux - General 12 09-05-2015 01:39 PM
windows eclipse platform - crt1.o: No such file: No such file or directory jnettleton Programming 2 05-18-2012 09:01 PM
cat onelinefile.txt >> newfile.txt; cat twofile.txt >> newfile.txt keep newline? tmcguinness Programming 4 02-12-2009 06:38 AM
How can read from file.txt C++ where can save this file(file.txt) to start reading sam_22 Programming 1 01-11-2007 05:11 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:05 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration