I let the user specify a filename say hello.txt and the number of newest lines say 30 they want from the file.
I then fire the below command to get them the data they are looking for.
tail -30f hello.txt > hello.txt.tmp; mv hello.txt.tmp hello.txt;
The problem is when the user provides some irrelevant file that does not have text or directory the command does not work. For example:jdk.zip
tail -30f jdk.zip > jdk.zip.tmp; mv jdk.zip.tmp jdk.zip;
The above simply never returns.
Thus, I need a solution that I should be able to check if the provided file will work with the tail command or not; before I fire the actual command.
Thus, a directory, a zip file, a PDF, an mp4 file, etc whichever do not work with the tail command should not be tailed.
I'm on Linux system.