Skip to Content
Learning Linux Shell Scripting - Second Edition
book

Learning Linux Shell Scripting - Second Edition

by Ganesh Sanjiv Naik
May 2018
Beginner
332 pages
7h 28m
English
Packt Publishing
Content preview from Learning Linux Shell Scripting - Second Edition

File-testing binary operators

The following are various options for binary file operations using test, which is taken from the Bash reference manual available at http://www.gnu.org/software/bash/:

Test Operator

Tests True If

[ file_1 -nt file_2 ]

Check whether file_1 is newer than file_2

[ file_1 -ot file_2 ]

Check whether file_1 is older than file_2

[ file_1 -ef file_2 ]

Check whether file_1 and file_2 have the same device or inode numbers

 

Let's write the script test07.sh to test the basic file attributes, such as whether it is a file or folder and whether it has a file size bigger than 0. The output will be different depending on whether the case file is present:

#!/bin/bash # Check whether file is Directory ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning Linux Shell Scripting

Learning Linux Shell Scripting

Ganesh Sanjiv Naik
Linux Shell Scripting Cookbook - Third Edition

Linux Shell Scripting Cookbook - Third Edition

Clif Flynt, Sarath Lakshman, Shantanu Tushar

Publisher Resources

ISBN: 9781788993197Supplemental Content