Miscellaneous
expr
Evaluate expressions — arithmetic, string matching, and comparisons.
Synopsis
syntax
expr EXPRESSION
Examples
Arithmetic addition: 8
expr 5 + 3
Multiplication (escape the asterisk): 50
expr 10 \* 5
String length: 11
expr length 'hello world'
Extract filename without extension
expr 'hello.txt' : '\(.*\)\.txt'
About expr
The `expr` command evaluate expressions — arithmetic, string matching, and comparisons. Utility commands cover a broad range of everyday tasks from date manipulation and arithmetic to terminal control and system documentation.
These tools fill in the gaps between major categories and are frequently used in shell scripts, cron jobs, and interactive sessions. The command accepts 0 commonly used flags shown above, though the full set of options is available in the man page (`man expr`).
The 4 examples on this page cover typical real-world usage patterns that you can copy and adapt for your own workflows.
Related commands
More Miscellaneous Commands
Other commands in the Miscellaneous category