• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 222
  • Last Modified:

bash

Is there a way to list all the files(not directories) in a directory that starts with some letter, with the use of ls and grep ? When I say all files, I mean files with extension and files without extension. I know how to do it with a for loop, but I don't know how to do it with ls and grep.
0
Vemont
Asked:
Vemont
  • 2
  • 2
1 Solution
 
TintinCommented:
If you *really* want to use ls and grep, the following will work for all files starting with 'a'

ls -F a*|grep -v /


a more robust way is to do

find . -type f -name "a*" -maxdepth 1

0
 
VemontAuthor Commented:
ls -F a*|grep -v / won't work on all systems because they don't all use / at the end of directories. It will probably work on Linux though.
0
 
TintinCommented:
Vemont.

What systems won't display a / for directories using 'ls -F'?

Certainly works on all Linux systems, Solaris, FreeBSD, openBSD, AIX
0
 
VemontAuthor Commented:
OK, you're right, I thought it wouldn't work on Solaris, but it did. Thanks! :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now