LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 05-12-2008, 06: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, 06:44 PM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

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

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

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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, 06: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



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

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

All times are GMT -5. The time now is 01:29 AM.

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