Posted on 2006-05-06
Last Modified: 2012-05-05
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.
Question by:Vemont
    LVL 48

    Accepted Solution

    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


    Author Comment

    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.
    LVL 48

    Expert Comment


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

    Certainly works on all Linux systems, Solaris, FreeBSD, openBSD, AIX

    Author Comment

    OK, you're right, I thought it wouldn't work on Solaris, but it did. Thanks! :)

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
    The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now