• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
sharadchhetri

sharadchhetri

Tutorials On Linux, Unix & Open Source

  • Home
  • Linux Commands
  • Resources
    • Learn Linux
  • My WordPress plugins

How to know last command run successfully : Linux / Unix

January 26, 2014 by Sharad Chhetri 2 Comments

In this post I am sharing a small and useful tip about, how to know last command run successfully in Linux and Unix .The post will explain ,to get the exit status of command used last time. As a System Engineer, sometimes I have to check the success status of last command I run on terminal.It is not only with command but you can apply this for script also.

To know the exit status of last command, run below given command

echo $? 

You will get the output in integer.
If output is ZERO ( 0 ), it means command has been run successfully. Whereas if output of the command is NON ZERO then command was not run successfully.

See given below example

linux@tuxworld:/tmp$ ls 
acroread_1002_1002  orbit-linux  plugtmp-2	     pulse-PKdhtXMmr18n  unity_support_test.0
kde-linux	    plugtmp	 plugtmp-3	     ssh-RRoiHGlxeCVF
ksocket-linux	    plugtmp-1	 pulse-EfTYmbAMhCGe  tmpQA7rpT
linux@tuxworld:/tmp$ 
linux@tuxworld:/tmp$ echo $?
0
linux@tuxworld:/tmp$ 
linux@tuxworld:/tmp$ lsla
lsla: command not found
linux@tuxworld:/tmp$ 
linux@tuxworld:/tmp$ echo $?
127
linux@tuxworld:/tmp$ 
linux@tuxworld:/tmp$ 

In above given example, you can see after using ls command,I used echo $? command.Its output is ZERO ,it means command run successfully.

Whereas,on after running false command lsla,the echo $? command output is 127. Which is NON ZERO,hence the command was not run successfully

Share this:

  • Twitter
  • Facebook
  • More
  • Print
  • Email
  • LinkedIn
  • Reddit
  • Tumblr
  • Pinterest
  • Pocket
  • Telegram
  • WhatsApp
  • Mastodon

Related posts:

  1. run command in remote linux / unix system by using ssh
  2. How To Find Absolute Full Path Of Command On Linux / Unix : which command
  3. Useful tail command with examples in Linux/Unix
  4. Find exit status code of last executed command on Linux and Unix
  5. 6 important examples of cd command on Linux and Unix Systems
  6. Linux / Unix : whoami command use and advantage
  7. Head command in Linux / Unix
  8. What is Linux Internal And External Command
  9. How to read logs which are writing continuously : LINUX/UNIX
  10. Unix / Linux : How to print duplicate lines from file

Filed Under: Linux Commands Tagged With: linux command

Reader Interactions

Comments

  1. Ebin says

    March 20, 2022 at 8:45 am

    how to check it using if statement
    eg ;
    command
    if command run
    echo “success”

    Reply
  2. jerryjr says

    November 26, 2019 at 9:19 pm

    hey there, i had a similar situation with bq command. After extracting a file in a bucket. Then, when i issue this command bq ls , my output was ‘o’.

    What does that mean?

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Our Social Media Presence

  • Facebook
  • GitHub
  • Twitter

Linux Command

What is Linux Internal And External Command

Linux Basic Commands With Examples For Every Beginner

tr command to convert lines to space , tab and vertical tab

smbpasswd command not found on CentOS 7 and RHEL 7

Solution : semanage command not found

Unix / Linux : How to print duplicate lines from file

More Posts from this Category

You Might Like These Articles!

simplecodesyntax wordpress plugin

SimpleCodeSyntax : My Another WordPress Plugin

Install Nginx

How To Install Nginx On Ubuntu 22.04 LTS

Install Latest Git package in Ubuntu Operating System

How To Always Install Latest Git Package In Ubuntu Operating System

Bash script for installing VirtualBox on Ubuntu 22.04 LTS Desktop

Install VirtualBox On Ubuntu 22.04 LTS Desktop (Bash Script)

libfuse

dlopen(): error loading libfuse.so.2 – Got Error On Ubuntu

Failed to open/create the internal network

VirtualBox Error: Failed to open/create the internal network

Always Useful Tips And Tricks

Set GRUB password after installation of CentOS/Red Hat

Change default editor of crontab in Ubuntu

Run the script using nohup without hitting enter key two times

How to install korn shell ksh in Linux

Read the file inside compressed .gz files without extract

How to configure ethernet in CentOS 6 after installing in Virtual Box

rsync all files,hidden files,symlinks,hardlinks to remotes Linux Server

Explore 90+ Article On "Linux Tips And Tricks"

Copyright © 2023 ยท
The material in this site cannot be republished either online or offline, without our permission.
Proudly Blogging From Bharat.

  • Contact
  • About Me
  • My WordPress plugins
  • Privacy Policy