I am trying to write a Bash script that takes the name of a file or directory as an argument and reports if the file is a directory, regular file or other. The script should also report if the user has read, write and execute permission on the file or directory.
Obviously something like this will get the raw information:
#!/bin/sh
read -p "Enter a filename: " fname
file $fname
ls -la $fname
however, I am wondering if we could just drop the file command completely, pass the filename variable to an ls that we then write some kind of if, then, else statement based on the results. the ls command gives a file type and full break down of the permissions the user running it has on the file, so can I make custom output based on the results of an ls command?
ls
, I suggest you familiarize yourself with your system'sstat
command - it may be possible for you to get the output you want much more simply – steeldriver Jul 05 '18 at 20:00