Customizing the Output
stat provides us the option to customize output instead of using the default output format. There are two ways by which we can customize the output
The first is using the -c option or the –format option with the format of the output. If we provide the multiple files to the stat command with the –format option, then it will automatically add the new line after each operand’s output:
stat --format='%n' /etc/passwd
Another way to print customized output is using the –print option with the format. With this option, we can provide trailing characters to the format for example if we want to add a new line after each line output we can use \n trailing characters with a backslash. Here is one of using –print option
stat --print='%n\n' /etc/passwd
To know all format sequences, read the man page of the stat using the man command. The stat can also display the information in the terse form. We can display information in the terse form with -terse option:
stat -t /etc/passwd
Stat command in Linux with examples
The stat is a command which gives information about the file and filesystem. Stat command gives information such as the size of the file, access permissions and the user ID and group ID, birth time access time of the file. Stat command has another feature, by which it can also provide the file system information. This is the best tool to use when we want the information of any file.
Now let’ see one by one how can we use the stat command.
Contact Us