Find the answer to your Linux question:
Results 1 to 6 of 6
Hi to all.Well I have come up with this command Code: ls -a|grep '^[A-Z]' but it is also lists the directories.I'm looking for a command to list inly files. Thanks ...
  1. #1
    Just Joined!
    Join Date
    Jun 2008
    Posts
    25

    List all files starting with an uppercase..

    Hi to all.Well I have come up with this command
    Code:
    ls -a|grep '^[A-Z]'
    but it is also lists the directories.I'm looking for a command to list inly files.
    Thanks in advance..

  2. #2
    Linux Engineer GNU-Fan's Avatar
    Join Date
    Mar 2008
    Posts
    935
    find * -maxdepth 0 -type f | grep '^[A-Z]'

    'f' stands for 'file'.
    There is also a built in regex evaluator in find so you won't have necessarily to grep.

  3. #3
    Linux User nalg0rath's Avatar
    Join Date
    Sep 2004
    Location
    Stockholm
    Posts
    303
    Code:
    # ls -ap|grep '^[A-Z].*[^/]$'
    ls -p puts a / on the end of all directories that are listed. Regexp brakedown:
    Code:
    ^[A-Z] -- line that begins with uppercase character
    . -- any character
    * -- the . any number of times
    [^/]$ -- exclude lines with / right before end of line
    Not tested but I think it would do the job.

  4. #4
    Just Joined!
    Join Date
    Jun 2008
    Posts
    25
    Thank you both for your answers.Both commands work great.

  5. #5
    Just Joined!
    Join Date
    Jun 2008
    Posts
    25
    Well,another question now is how to list all the files that were created a specific month.I tried something similar,but it didn't work.Here is the code:
    Code:
    read -p "give the month in 2 digit number" month
    echo "the number of files created on $month is:"
    ls -ap|grep '\-\'$month'\-[^/]$'|wc -l
    Any ideas how to fix it..?

  6. #6
    Just Joined!
    Join Date
    Jun 2008
    Posts
    25
    After trial and error I found that this command does the job:
    Code:
    ls -l|grep '\-\'$month'\-'|grep -v ^d|wc -l
    Thanks for your advices.You've been very helpful.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...