Many new features now available including 2-Factor authentication

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.



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..)


Mark Greaves (PCNetSpec)

Maybe use
file --mime-type
to get the mime info for the file type .. so for text files it'd be:-
and for a jpeg it'd be

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;
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.