Compare file names on directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compare file names on directory
# 1  
Old 08-05-2013
Compare file names on directory

Dears,

Would you please help on following bash script:

I want to get the most recent file named alfaYYYYMMDD.gz in one directory:

for example:

in directory /tmp/
Code:
ls -ltr
alfa20130715.gz
holding.gz
alfa20130705.gz
sart.txt
merge.txt.gz
alfa20130802.gz

my result shoud be alfa20130802.gz ( created in 2013-08-02)


Thank you in advance

Last edited by Scott; 08-05-2013 at 10:27 AM.. Reason: Code tags
# 2  
Old 08-05-2013
Code:
$ head -1 <(ls -r alfa*)
alfa20130802.gz

$ tail -1 <(ls alfa*)   
alfa20130802.gz

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Renaming the file names in a directory

Hi, I have about 60 files in a directory and need to rename those files. For example the file names are i_can_phone_yymmdd.txt (where yymmdd is the date. i.e 170420 etc) i_usa_phone_1_yymmdd.txt i_eng_phone_4_yymmdd.txt The new file names should be phone.txt phone_1.txt phone_4.txt I am... (4 Replies)
Discussion started by: naveed
4 Replies

2. Shell Programming and Scripting

Compare Only "File Names" in 2 Files with file lists having different directory structure

I have a tar arcive arch_all.tar.gz and 4 batched tar archive . These batches are supposed to have all the files form arch1.all.tar.gz arch1_batch1.tar.gz arch1_batch2.tar.gz arch1_batch3.tar.gz arch1_batch4.tar.gz my issue is that the directory structure in "arch_all.tar.gz" is... (6 Replies)
Discussion started by: sumang24
6 Replies

3. UNIX for Dummies Questions & Answers

List Directory names which have the file

Hi All, Can any one help me to list out the directory names which contain the specified file. See for example File name : file.201307014.LKT Have the directory structure as below. /app/work/data/INDIA/file.201307014.LKT /app/work/data/AMERICA/file.201307014.KTP... (5 Replies)
Discussion started by: Balasankar
5 Replies

4. Shell Programming and Scripting

Check for particular files and compare the file names

Hi, Below are the 2 files in directory /tmp: masterCSF242323.img indexCSF242323.img 1) I want to compare if both the number (242323) are same in both the files. If they are same print - Files matching, else print files do not match. 2) Also if only index file is present in that... (7 Replies)
Discussion started by: apatil65
7 Replies

5. Shell Programming and Scripting

Grepping file names, comparing them to a directory of files, and moving them into a new directory

got it figured out :) (1 Reply)
Discussion started by: sHockz
1 Replies

6. UNIX for Dummies Questions & Answers

Compare the file names from a file to a directory

Hi, I have to acheive the below logic in the script. I have a file which has many columns and one of them is "File Names" and there will be only one such column name. Eg., cat File1 Number of files:10 File Names: ABC, DEF, RTY,URE .... ... ... The column will contain the... (3 Replies)
Discussion started by: Vijay81
3 Replies

7. Shell Programming and Scripting

Searching for file names in a directory while ignoring certain file names

Sun Solaris Unix Question Haven't been able to find any solution for this situation. Let's just say the file names listed below exist in a directory. I want the find command to find all files in this directory but at the same time I want to eliminate certain file names or files with certain... (2 Replies)
Discussion started by: 2reperry
2 Replies

8. Shell Programming and Scripting

Compare File Names in Different Directories...

I do not know much about shell scripting and need to create a script and I am at a loss. If someone can help me, that would be great!! I have two directories: /dir1 /dir2 I need to get the sequence number which is part of the filename in /dir1 and delete all files in /dir2 that are... (4 Replies)
Discussion started by: stky13
4 Replies

9. Shell Programming and Scripting

Compare file names

Hi everyone, How to compare between two filenames, in case the current filename is the same as the last one an alarm to be sent, in case the current filename is different from the last filename, no alarm to be sent. Is there a way to do this? Thanks in advance. (4 Replies)
Discussion started by: charbel
4 Replies

10. Shell Programming and Scripting

directory names in a flat file

Hi, Consider a flat file abc.conf contains some rows. Each row contains the directory name with full path. now I want to find a particular file in every directory which are mentioned in the abc.conf file. How it can be done through unix shell script. (2 Replies)
Discussion started by: surjyap
2 Replies
Login or Register to Ask a Question