Tech Zone > Linux Solutions

copy files with no extension

(1/1)

cabajones:
Hi,

Can you please let me know how to copy files with no extension using shell script.I have a file of type file with no extension(.txt or .csv etc..)



Thanks
jones

Mark Greaves (PCNetSpec):
Maybe use

--- Code: ---
file --mime-type
--- End code ---
to get the mime info for the file type .. so for text files it'd be:-
text/plain
and for a jpeg it'd be
image/jpeg

Then maybe something like

--- Code: ---
find /path/to/directory/to/search | while read FILE; do if [ $(file --mime-type -b "$FILE") == "text/plain" ]; then cp -v "$FILE" "/path/to/where/you/want/them/copied/$FILE"; fi; done;
--- End code ---
and

--- Code: ---
find /path/to/directory/to/search | while read FILE; do if [ $(file --mime-type -b "$FILE") == "image/jpeg" ]; then cp -v "$FILE" "/path/to/where/you/want/them/copied/$FILE"; fi; done;
--- End code ---
Where this is going to fall over is in your example you list txt and csv .. as far as I'm aware they are both text/plain files .. so searching for them by mime type aint gonna distinguish between them, in which case you're going to have to somehow distinguish between them by content.

Navigation

[0] Message Index

Go to full version