Delete files according to attributes


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Delete files according to attributes
# 1  
Old 09-20-2011
Delete files according to attributes

In a directory I have many *.dat *.f files and also binary files created from Fortran compilation that doesn't have a filename extension.

Is it possible to delete these binary files according to its attributes?

Thanks.
# 2  
Old 09-20-2011
What kind of attributes are you talking about? Extension?
# 3  
Old 09-20-2011
Yes. The unix file command will identify file types based on the content of the file.
Since deleting the wrong files is probably not an option, start by seeing what your file command sees in that directory:
Code:
find /path/to/directory/ -type f  -exec file {} \; | sort -k 2.1,2.99 -u

This will give you the file "types" that exist in the directory, with a few filenames, so you can see how this all works. Post the result.
This User Gave Thanks to jim mcnamara For This Post:
# 4  
Old 09-20-2011
Hi,
Mostly binary file doesn't have "." in the name. If this applies in your system, I can give command to remove such files.
# 5  
Old 09-20-2011
Thanks for the replies.

This is the output from jim mcnamara's code
Code:
./inp10: ASCII English text
./nc.m: ASCII text
./DILAT2.DAT: ASCII text, with very long lines
./DILAT.BIN: data
./interpolate: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), for GNU/Linux 2.6.4, dynamically linked (uses shared libs), not stripped
./interp.o: ELF 64-bit LSB relocatable, x86-64, version 1 (GNU/Linux), not stripped
./restrt.bin: empty
./interp.f: FORTRAN program

One of the files I want to delete is the file 'interpolate' above. The other files also must have the same type. How do I delete these files?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script needed to delete to the list of files in a directory based on last created & delete them

Hi My directory structure is as below. dir1, dir2, dir3 I have the list of files to be deleted in the below path as below. /staging/retain_for_2years/Cleanup/log $ ls -lrt total 0 drwxr-xr-x 2 nobody nobody 256 Mar 01 16:15 01-MAR-2015_SPDBS2 drwxr-xr-x 2 root ... (2 Replies)
Discussion started by: prasadn
2 Replies

2. Shell Programming and Scripting

Delete all files if another files in the same directory has a matching occurrence of a specific word

he following are the files available in my directory RSK_123_20141113_031500.txt RSK_123_20141113_081500.txt RSK_126_20141113_041500.txt RSK_126_20141113_081800.txt RSK_128_20141113_091600.txt Here, "RSK" is file prefix and 123 is a code name and rest is just timestamp of the file when its... (7 Replies)
Discussion started by: kridhick
7 Replies

3. UNIX for Dummies Questions & Answers

Concatenate files and delete source files. Also have to add a comment.

- Concatenate files and delete source files. Also have to add a comment. - I need to concatenate 3 files which have the same characters in the beginning and have to remove those files and add a comment and the end. Example: cat REJ_FILE_ABC.txt REJ_FILE_XYZ.txt REJ_FILE_PQR.txt >... (0 Replies)
Discussion started by: eskay
0 Replies

4. Shell Programming and Scripting

Need help creating a script to FTP files to a server and then delete the files that were transfered.

I am trying to FTP files to a Windows server through my Linux machine. I have setup the file transfer with no problems but am having problem deleting those files from the Linux box. My current non-working solution is below. Any ideas, anyone?? :wall: Please be gentle, I'm fairly new to this... (4 Replies)
Discussion started by: jmalfhs
4 Replies

5. UNIX for Advanced & Expert Users

Help with can't get execution attributes

Hi Gurus, I am trying to create a FS using SVM but system is throwing the following error. newfs /dev/md/rdsk/d1002 newfs: construct a new file system /dev/md/rdsk/d1002: (y/n)? y /usr/sbin/clri: can't get execution attributes (1 Reply)
Discussion started by: rama krishna
1 Replies

6. Shell Programming and Scripting

How can i delete html attributes from tag ?

Input: <table class="pixelBorderTable faqTable" width="100%" border="1" cellpadding="3" cellspacing="0"> <tbody><tr> <td class="pixelBorderTableHeaderTd" valign="top" width="20%" bgcolor="#666666"><p>&nbsp;</p></td> <td class="pixelBorderTableHeaderTd" valign="top"... (1 Reply)
Discussion started by: cola
1 Replies

7. Shell Programming and Scripting

Delete all files if another files in the same directory has a matching occurence of a specific word

Hello, I have several files in a specific directory. A specific string in one file can occur in another files. If this string is in other files. Then all the files in which this string occured should be deleted and only 1 file should remain with the string. Example. file1 ShortName "Blue... (2 Replies)
Discussion started by: premier_de
2 Replies

8. UNIX for Dummies Questions & Answers

Problems with any ls attributes

I got a server (test server) that hangs anytime we run a ls attribute like ls -ltr or ls -al. We can run ls | more command with no problem. But getting back to the ls attribute problem, it just sits and hangs, I did a ps -ef | grep ls, and a user had 15 sessions of ls -al running, I killed those,... (3 Replies)
Discussion started by: Sarccastik Dude
3 Replies

9. Shell Programming and Scripting

file attributes

How to retrieve file attributes in a sh/bash script (modification time, access time, size, etc.)? (1 Reply)
Discussion started by: Hitori
1 Replies

10. UNIX for Dummies Questions & Answers

when I try to run rm on multiple files I have problem to delete files with space

Hello when I try to run rm on multiple files I have problem to delete files with space. I have this command : find . -name "*.cmd" | xargs \rm -f it doing the work fine but when it comes across files with spaces like : "my foo file.cmd" it refuse to delete it why? (1 Reply)
Discussion started by: umen
1 Replies
Login or Register to Ask a Question