LinuxQuestions.org
Register a domain and help support LQ
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 05-12-2008, 07:36 PM   #1
mg92865
Member
 
Registered: Jun 2006
Distribution: Ubuntu
Posts: 35

Rep: Reputation: 16
List Only Files In a Directory beginning with "k" using the ls command


I can use the ls command to list the files in the directory that I am looking in.

Is is possible using ls, to restrict the results to only a specific group of files, say those starting with the letter k?

Thank you for any assistance you can provide.


mg92865
 
Old 05-12-2008, 07:44 PM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
First "man ls".

Then "ls k*".
 
Old 05-12-2008, 07:44 PM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Use the wildcard "*"
Code:
ls k*
this will list all the files whose name begins with k followed by any other string of characters. In some cases you can also use the wildcard for a single character "?", e.g. suppose you have files testfile_1.txt, testfile_2.txt testfile_10.txt testfile_11.txt, the command
Code:
ls testfile_?.txt
lists only testfile_1.txt and testfile_2.txt, whereas
Code:
ls testfile_*.txt
will list them all.
 
Old 05-12-2008, 07:58 PM   #4
mg92865
Member
 
Registered: Jun 2006
Distribution: Ubuntu
Posts: 35

Original Poster
Rep: Reputation: 16
Seems very Clear Now - Thanks

I looked thru the man page, but there is no referene to *. And I actually now realized I knew about the wildcard *. It just seems that I didn't put them together.

Anyway, I appreciate the assistance, and this has solved my problem.

Thanks,

mg92865
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Standard commands give "-bash: open: command not found" even in "su -" and "su root" mibo12 Linux - General 4 11-11-2007 11:18 PM
"argument list too long" - why am I getting this with the find command laggerific Linux - Software 11 10-01-2007 01:01 PM
"list dynamic dependency" of an executable using command other than "ldd" Amrita@3086 Solaris / OpenSolaris 3 04-04-2007 05:56 AM
need a list of every installed RPM beginning with the letter "j" me210 Linux - Software 2 01-17-2007 11:59 AM
command gedit "/etc/apt/sources.list" not working secret_force Linux - Newbie 4 08-02-2006 05:28 PM


All times are GMT -5. The time now is 06:46 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration