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 07-04-2008, 04:48 AM   #1
djfog
Member
 
Registered: Jun 2008
Distribution: Linux Mint 4.0(Daryna)
Posts: 31

Rep: Reputation: 15
Command to list files starting with uppercase letter


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 only files.
Thanks in advance..
 
Old 07-04-2008, 05:16 AM   #2
indeliblestamp
Member
 
Registered: Feb 2006
Distribution: Fedora
Posts: 341
Blog Entries: 3

Rep: Reputation: 40
Hint: You can also use ls -a [A-Z]* instead of piping ls to grep.
To list only files, use this:
Code:
ls -lad [A-Z]* | grep -v ^d | awk '{print $9}'
You should see the man pages for ls, grep and awk for details, but in short, what the command does is:
-- listing all files but without expanding directories
-- grep all lines that don't start with 'd' (i.e. only files, symlinks, etc)
-- cut out the files column from the normal ls -l listing
 
Old 07-04-2008, 05:17 AM   #3
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
See the -F option for ls. Note how it treats files, directories, etc. uniquely.
 
Old 07-04-2008, 05:21 AM   #4
djfog
Member
 
Registered: Jun 2008
Distribution: Linux Mint 4.0(Daryna)
Posts: 31

Original Poster
Rep: Reputation: 15
Well,I found that the command :
Code:
ls -ap|grep '^[A-Z].*[^/]$'
does the job.But now I'm having another problem as I want to find the number of files that were created a specific month.I tried something similar to the previous command,but It didn't work.Here is my 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 where am I mistaken or how to fix it..?
Thanks in advance...
 
Old 07-04-2008, 05:24 AM   #5
indeliblestamp
Member
 
Registered: Feb 2006
Distribution: Fedora
Posts: 341
Blog Entries: 3

Rep: Reputation: 40
oops. Agreed, ls -F with a single grep is a much neater solution.
 
Old 07-04-2008, 05:30 AM   #6
djfog
Member
 
Registered: Jun 2008
Distribution: Linux Mint 4.0(Daryna)
Posts: 31

Original Poster
Rep: Reputation: 15
Thanks for your advices.This command worked:
Code:
ls -l|grep '\-\'$month'\-'|grep -v ^d|wc -l
 
  


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
Command to list files by permissions rickh Programming 5 06-20-2007 09:08 AM
UPPERCASE to lowercase command? pk21 Linux - General 4 06-12-2007 10:26 AM
Midnight Commander doesn't list file(s) beginning with uppercase? sixerjman Linux - Software 0 02-14-2006 11:31 AM
Command to run another command against a list of files psweetma Linux - General 3 11-09-2005 05:29 PM
Command to list some files? AoiSora Programming 13 10-29-2003 04:37 PM

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

All times are GMT -5. The time now is 10:21 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