list files commands


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting list files commands
# 1  
Old 04-16-2008
list files commands

hi all scripting gurus,

need some guide and advise from you.

i'm trying to list all the files in the year 2004 and the file format is something like this: 11176MZ00004JV900004JVB00004JVCcDBU20041206.txt try to use the symbol ^ but somehow it does not help.

i try this as well: ls -ltr | grep 200401 | more and it does shows the files listed in 2004 but also in 2005 and 2006. any way i can refine this search? Smilie

can anyone help? many thanks. Smilie


wee
# 2  
Old 04-16-2008
If there are files from 2005 and 2006 which coincidentally contain 200401 in their file name then you need to make the regular expression more exact. If the date is always just before a final .txt extension then grep 2004....\.txt$ might work better. (Just a dot means "any character" in a regular expression.)
# 3  
Old 04-16-2008
Quote:
Originally Posted by era
If there are files from 2005 and 2006 which coincidentally contain 200401 in their file name then you need to make the regular expression more exact. If the date is always just before a final .txt extension then grep 2004....\.txt$ might work better. (Just a dot means "any character" in a regular expression.)
hi era,

thanks for the guide. tried the command but getting this result:

spids111% ls -ltr |grep *2004....\.txt$* | more
No match
spids111%

somewhere gone wrong in my command line? Smilie

thanks again! Smilie

wee
# 4  
Old 04-16-2008
Quote:
Originally Posted by lweegp
hi era,

thanks for the guide. tried the command but getting this result:

spids111% ls -ltr |grep *2004....\.txt$* | more
No match
spids111%

somewhere gone wrong in my command line? Smilie

thanks again! Smilie

wee
it works!! sorry i put in the *...oops...many thanks!! Smilie

wee
# 5  
Old 04-16-2008
Quote:
Originally Posted by lweegp
it works!! sorry i put in the *...oops...many thanks!! Smilie

wee
apologies...one more question.

if i want to remove the files in 2004 what is the next command i need to put in? using rm command? like this:

spids111% ls -ltr | grep 2004....\.txt$ | rm * ?
# 6  
Old 04-16-2008
rm doesn't read standard input, it expects the files to remove on its command line. Use xargs or backticks.

Code:
rm `ls -ltr | grep 2004....\.txt$`

or

Code:
ls -ltr | grep 2004....\.txt$ | xargs rm

Try it with "echo" instead of "rm" to make sure that you're doing the right thing.
# 7  
Old 04-16-2008
(Weird, double post, sorry.)

Last edited by era; 04-16-2008 at 06:29 AM.. Reason: Double post!?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to save and run a list of commands?

Dear every one, I am working with the data of my lab program and I have to do many times by the same list of some commands (grep, then save to file, then use awk to delete odd lines, save to file, use awk to delete even lines, save to file...). Is there any way to save a list of command which I... (4 Replies)
Discussion started by: phamnu
4 Replies

2. UNIX for Dummies Questions & Answers

sudo commands list

Hi, Can you please give me a list of commands executed through 'sudo' command, thank you. (1 Reply)
Discussion started by: Dev_Dev
1 Replies

3. UNIX for Dummies Questions & Answers

how to know the list of all commands supported by unix ?

how to know the list of all commands supported by unix. how to know the list of functions supported by unix. (4 Replies)
Discussion started by: Gopi Krishna P
4 Replies

4. Shell Programming and Scripting

List of internal commands ??

Dear Sir/Mam, Can you tell me list of internal commands which are easy to implements...??? Means sir I am a beginner in unix shell programming. So, I just wanted to know that which internal commands are easy to implements in C language. thanks.... (1 Reply)
Discussion started by: ranusahu
1 Replies

5. UNIX for Dummies Questions & Answers

Command for maintaining the list of commands used

Hi, There is a command by which you can maintain a list of commands previously typed. By this you dont have to type in the same command again and can use the up-down arrows to scroll through the list. Which is this command, i am not able to recall. (8 Replies)
Discussion started by: appledrive
8 Replies

6. UNIX for Advanced & Expert Users

Comparison List of commands

Hi, I would like to have a list of commands in a table, see below example Command description HPUNIX SUN UNIX IBM AIX all above i need comparison list of commands ASAP please.......... B.R (1 Reply)
Discussion started by: f_amshan
1 Replies

7. Solaris

List of Commands

Dear All, I am a new Administrator of Solaris in the company , I need a list of the commands pls ... Regards Adel (2 Replies)
Discussion started by: ArabOracle.com
2 Replies

8. UNIX for Dummies Questions & Answers

A Thorough List of FreeBSD commands?!?

I was just wondering if anyone knew of a site that covered all or many of FreeBSD's built in commands. I would also like to know what FreeBSD automatically logs, and where it logs it. Thanks! (1 Reply)
Discussion started by: Kyser_Soze
1 Replies

9. UNIX for Dummies Questions & Answers

List of Commands for Unix Please

Hello, I have recentlly been given access to a Unix based server in order to learn how to operate a Unix machine.. i have never used Unix before and am in need of a list of commands and there functions.. if you have one available please send it to me in .txt or wordpad document form.. thank you in... (5 Replies)
Discussion started by: ShdwMaster
5 Replies
Login or Register to Ask a Question