Updates:

Forums updated to SMF version 2.1.1

copy files with no extension

Started by cabajones, July 03, 2017, 01:00:29 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

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
file --mime-type
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
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;
and
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;
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.
WARNING: You are logged into reality as 'root'
logging in as 'insane' is the only safe option.
pcnetspec.co.uk