Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 221
  • 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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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