Need to exclude certain file extensions while listing the file using ls


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Need to exclude certain file extensions while listing the file using ls
# 1  
Old 08-06-2013
Need to exclude certain file extensions while listing the file using ls

Hi friends,
I need to check for the latest file
say i have list of files like this

Code:
test_files
test_files.1
test_files.2
test_files.3.bin.Z

I do it this way

Code:
ls -lrt test_files*|tail -1

Now i need to exclude test_files.3.bin.Z even if it is the latest file,how do i do it?

tried

Code:
ls -lrt test_files*|grep -v *.bin.Z

# 2  
Old 08-06-2013
Hello,

Could you please check the following command.


Code:
ls -ltr | awk '/test_files*/' | grep -v "test_files.[0-9].bin.*" | tail -1


Note: I have make it according to your bin file name.


Thanks,
R. Singh
# 3  
Old 08-06-2013
Thanks it works perfectly. Smilie
# 4  
Old 08-06-2013
That string of pipes after ls can be replaced by one awk cmd:
Code:
ls -t | awk '/test_files*/ && !/bin/ {print; exit}'

---------- Post updated at 16:41 ---------- Previous update was at 16:31 ----------

In a recent bash, you can use "extended pattern matching operators":
Code:
ls -t @(test_!(*.bin.*)) | head -1

Might save a millisecond or two.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Comparing file names with different extensions

Hello, I need some help. I have files in one and the same directory, but with different extensions, like this: file1.IN file2.IN file3.IN file1.OUT file2.OUT Apparently some files with OUT extension can be missing. So I want to compare *.IN and *.OUT, ignoring the extension and get result... (3 Replies)
Discussion started by: apenkov
3 Replies

2. Shell Programming and Scripting

Remove comments from file with specific file name extensions

Hello Unix board community, I have to program a shell script, but I am a complete noob so I hope I get some help here. The assignment is as follows: The program removes all comments regardless of formatting or language from files with specific file name extensions (php, css, js, ...).... (3 Replies)
Discussion started by: TheZeusMan
3 Replies

3. Shell Programming and Scripting

Search for file extensions in the given directories

Hey guys, I'm lost... I need to make a script that will work in this way: ./script.sh -e sh /usr/bin /home/student this script will result in this output: amuFormat.sh /usr/bin gettext.sh /urs/bin perfect.sh /home/student the parameter -e <ext> gives you which... (2 Replies)
Discussion started by: Miki1579
2 Replies

4. Emergency UNIX and Linux Support

Sorting file content by file extensions

Hi Experts, I have one .txt file which has filenames with various extensions e.g. .gz,.dat,.CTL,.xml. I want to sort all the filenames as per their extensions and would like to delete all the file names with .xml extension. Please help. PS : I am using Sun OS Generic_122300-60. ... (9 Replies)
Discussion started by: ajaypatil_am
9 Replies

5. Ubuntu

[Solved] Using Find with an exclude/exclude file

I am familiar with using tar and exclude/include files: tar zcf backup.dirs.tgz --files-from=include.mydirs --exclude-from=exclude.mydirs --no-recursion but was wondering if I could use find in the same way. I know that you can just specify the directories to exclude but my list is... (2 Replies)
Discussion started by: metallica1973
2 Replies

6. Shell Programming and Scripting

Checking file extensions

I'm in csh and have a list of file names, example set Lst = "file1.ry file2.ry file3.ry file4.ry" I want to check if all the extensions are ry. Is they are, I want to do something. (1 Reply)
Discussion started by: kristinu
1 Replies

7. Shell Programming and Scripting

Checking file extensions

I am trying to store file with certain file extensions to list but having some problems. Here is a part of the code set fryLst = "" set fxtLst = "" foreach f ($AfullNameLst) set fname = $f:r set fext = $f:e if ("$fext" == ".ry") set fryLst = "$fryLst $f" if ("$fext" == ".xt")... (2 Replies)
Discussion started by: kristinu
2 Replies

8. UNIX for Dummies Questions & Answers

Find all the unique file extensions

Hi How can i find the unique list of file extensions in a folder/subfolders e.g. MAIN/ a.txt b.txt a.clas a.java b.class a.txt.112 c.12.ram.jar i just need to get the below out irrespective of file being present in folder or subfolders txt clas java (5 Replies)
Discussion started by: reldb
5 Replies

9. Shell Programming and Scripting

File extensions in a dir

Hi All, Is there a way to list all file extensions in a directory and its recursive dirs? Thanks (5 Replies)
Discussion started by: ganga.dharan
5 Replies

10. Shell Programming and Scripting

File name extensions

Hello people, I was wondering if anyone could help me? I want to produce a shell script that changes the filename extension on all matching file. E.G. change all files called ‘something.rtf' to ‘something.doc' by giving the command: Changex rtf doc *where ‘Changex' is the name of... (2 Replies)
Discussion started by: thurrock
2 Replies
Login or Register to Ask a Question