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