Show Menu

Bash comparison options Cheat Sheet by

Bash comparison options
bash

Test options

-b file
True if file is a Block special device
-c file
True if file is a Char­acter special device
-d file
True if file is a Dire­ctory
-e file
True if file Exists
-g file
True if file has its set-­gro­up-id bit set
-G file
True if file is owned by the current effective group id
-k file
True if file has its "s­tic­ky" bit set
-L file
True if file is a symbolic Link
-O file
True if file is owned by the current effective user id
-p file
True if file is a named Pipe
-r file
True if file is read­able
-S file
True if file is a Socket
-s file
True if file has a Size greater than zero
-t [FD]
True if FD is opened on a termin­al. If FD is omitted, it defaults to 1 (standard output)
-u file
True if file has its set-­user-id bit set
-w file
True if file is writ­able
-x file
True if file is exec­uta­ble
file1 -ef file2
True if file1 and file2 have the same device and inode numbers, i.e., if they are hard links to each other
 

File age

file1 -nt file2
True if file1 is newer than file2
file1 -ot file2
True if file1 is older than file2

String tests

-z String
True if the length of String is zero
-n String
True if the length of String is nonzero
String1 = String2
True if the strings are equal
String1 != String2
True if the strings are not equal

Numeric tests

ARG1 -eq ARG2
True if ARG1 is equal ARG2
ARG1 -ne ARG2
True if ARG1 is not-equal ARG2
ARG1 -lt ARG2
True if ARG1 is less-than ARG2
ARG1 -le ARG2
True if ARG1 is less-t­han­-or­-equal ARG2
ARG1 -gt ARG2
True if ARG1 is greate­r-than ARG2
ARG1 -ge ARG2
True if ARG1 is greate­r-t­han­-or­-equal ARG2

Download the Bash comparison options Cheat Sheet

1 Page
//media.cheatography.com/storage/thumb/respi_bash-comparison-options.750.jpg

PDF (recommended)

Alternative Downloads

Share This Cheat Sheet!

 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Linux Command Line Cheat Sheet
          Bash/ZSH Shourtcuts Cheat Sheet
          bash Shortcuts Cheat Sheet

          More Cheat Sheets by respi

          Special Vars Quick Reference Cheat Sheet