Howtodojo logo
  • Home 
  • About 
  • Certifications 
  • Sample Database 
  • Cheatsheet 
  • Glossary 
  • Blog 
  • Tags 
  1.   Linux Commands
  1. Home
  2. Guides
  3. Linux Commands
  4. Linux true Command

Linux true Command

Share via
Howtodojo
Link copied to clipboard

In this tutorial we will learn how to use true command in Linux. We'll also learn the common usage of true in shell script.

On this page
What is Linux true Command?   true Syntax   Using true command in Linux   Using true Command To Force Exit Status 0 in Linux Script   true Command Manual / Help   Linux true Command Source Code   Related Linux Commands   Summary  

What is Linux true Command?  

In this tutorial we learn how to use true command in Linux. true command in Linux will do nothing, successfully. This command is the opposite of false command.

true Syntax  

true [ignored command line arguments]
true OPTION

Using true command in Linux  

To use true we can invoke the command without any options or parameters.

true

true command will gives us no output or anything at all. But we can check the exit status of the true command using the command below right after invoking true command.

echo $?
0

The exit status 0 above shows that the command executed successfully.

Using true Command To Force Exit Status 0 in Linux Script  

You might be wondering what is the use case of Linux true command? You will usually this command being found in a shell script to make sure the command that we have provides exit status 0.

The next question will be, why we want to make sure we get exit status 0? In a shell script if we don’t get exit status 0 the script will be terminated and exit. For non critical command we can make sure that the command will still continue to run even though the command is not successfully run.

The format of the command will be similar to

COMMAND || true

The double pipe || above means OR. If the first command (command on the left) successfully run, the second command will not be invoked, but if the first command failed. The second command will be invoked.

Since the second command is true, then the exit status will always be 0. For this tutorial, let’s create a new directory named private directory.

mkdir privatedir

If we tried to remove the directory it will be failed since it is a directory.

$ rm -f privatedir/
rm: cannot remove 'privatedir/': Is a directory

If we check the exit status of the command above. The exit status will be 1

echo $?
1

Now if we run the command to remove privatedir directory above but with true command. The exit status will be 0.

rm -f privatedir/ || true
rm: cannot remove 'privatedir/': Is a directory

It will still show error message that the removal failed but if we check the exit status, the exit status will be 0

echo $?
0

The sample above is the most common usage of true command in Linux.

true Command Manual / Help  

We can use man and info command to see the manual page of true command.

true command also have code --help option to show list of options.

man page of the true command can be opened using the command below. To exit man or info page you can press q.

man true

Info page for the true command can be opened using command below.

info true

To open help page from true command we can run command below.

true --help

Linux true Command Source Code  

You can find true command source code from the folowing repositories:

  • [GitHub] GNU Coreutils true command source code
  • true source code on GNU Savannah cgit
  • [GNU Savannah gitweb] true source code on

Related Linux Commands  

You can read tutorials of related Linux commands below:

  • false command in Linux
  • test command in Linux
  • who command in Linux

Summary  

In this tutorial we learn how to use true in Linux with practical examples. Visit our Linux Commands guide to learn more about using command line interface in Linux.

 Linux users Command
Linux logname Command 
On this page:
What is Linux true Command?   true Syntax   Using true command in Linux   Using true Command To Force Exit Status 0 in Linux Script   true Command Manual / Help   Linux true Command Source Code   Related Linux Commands   Summary  
Follow me

We publish tutorials, tips and tricks about Linux, open source, cloud computing, and infrastructure

     
Copyright © 2012 - 2025 howtodojo.com. |
Howtodojo
Code copied to clipboard