How To Find When A Command Is Executed In Linux

This tutorial briefly describes how to find the execution time of a command in Linux and understand the benefits of the execution time of a command in Linux.
First, let's understand how to find the execution time of Linux commands.
Table of contents
- Determine the execution time of a specific command
- Understand the benefits of command execution time
- Summarize
Find command execution time in Linux
To find the execution time of a Linux command, you can use the history command, which displays a list of executed commands, as well as their respective dates and times. How to use it is as follows:
$ HISTTIMEFORMAT="%d/%m/%y %T " history
This formats the historical output to display the date and time of each command. %d/%m/%y format represents day, month and year, while %T represents time in a 24-hour time.
The example output of the above command is as follows:
<code>[...] 1362 22/03/24 17:17:20 time sleep 2 1363 22/03/24 17:33:35 HISTTIMEFORMAT="%d/%m/%y %T " history</code>
As the output shows, timestamps have been enabled in my bash history command output. Based on the above output, I executed the time command at 5:17:20 pm on March 22, 2024 .
Alternatively, you can use %F instead of %d/%m/%y . Both are correct.
$ HISTTIMEFORMAT="%F %T " history
If you are using Fish shell , enable timestamps in the historical command output using the following command:
history --show-time='%F %T '
On the Zsh shell, the command is:
history -f
For more details on how to enable timestamps in the history command output of Bash, Fish, and Zsh shells, see the following guide:
- How to enable timestamps in Bash history in Linux
- How to enable timestamp for history command in Fish Shell
- How to enable timestamp for Zsh's history command in Linux
Determine the execution time of a specific command
You may have noticed that the above command shows the execution time of all previous commands. What if you want to know when a specific command is executed? This is very simple!
If you want to know the execution time of a command, you can use the time command. For example:
$ time your_command_here
This will measure the time required for execution and display the execution time after the command is completed.
Example:
$ time ls
The output will display three times:
- real (total elapsed time),
- user (time spent in user mode),
- sys (time spent in kernel mode).
Sample output:
<code>[...] real 0m0.001s user 0m0.001s sys 0m0.000s</code>
For more detailed information on the usage of time commands, we recommend that you refer to the following guide:
- Find the execution time of a command or process in Linux
Understand the benefits of command execution time
Whether you are a system administrator or a programmer, understanding the execution time of commands is very useful for optimizing performance.
There are many benefits to understanding the execution time of commands in Linux:
- Performance Measurement : It can help you measure the performance of a script or command.
- Optimization : By determining the execution time of a command, you can optimize your scripts to run more efficiently, reducing the total execution time.
- Resource usage :
timecommand can also display the process's system resource usage, which is very helpful for viewing the efficiency of a specific command. - Bottleneck Identification : If a particular task takes more time than expected, it can help identify performance bottlenecks in a system or script.
- System Monitoring : For system administrators, understanding execution time is critical to system monitoring and can help with capacity planning and troubleshooting.
Summarize
That's it. In this short tutorial, we discuss a useful Linux tip that quickly helps users find the execution time of a command. Hope it helps you.
Related readings:
- How to clear command line history in Linux
- How to display Bash history without line numbers in Linux
- How to avoid duplicate entries in Bash history in Linux
The above is the detailed content of How To Find When A Command Is Executed In Linux. For more information, please follow other related articles on the PHP Chinese website!
Hot AI Tools
Undress AI Tool
Undress images for free
Undresser.AI Undress
AI-powered app for creating realistic nude photos
AI Clothes Remover
Online AI tool for removing clothes from photos.
Clothoff.io
AI clothes remover
Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!
Hot Article
Hot Tools
Notepad++7.3.1
Easy-to-use and free code editor
SublimeText3 Chinese version
Chinese version, very easy to use
Zend Studio 13.0.1
Powerful PHP integrated development environment
Dreamweaver CS6
Visual web development tools
SublimeText3 Mac version
God-level code editing software (SublimeText3)
Understanding RAID Configurations on a Linux Server
Aug 05, 2025 am 11:50 AM
RAIDimprovesstorageperformanceandreliabilityonLinuxserversthroughvariousconfigurations;RAID0offersspeedbutnoredundancy;RAID1providesmirroringforcriticaldatawith50�pacityloss;RAID5supportssingle-drivefailuretoleranceusingparityandrequiresatleastthre
Linux how to enable and disable services at boot
Aug 08, 2025 am 10:23 AM
To manage the startup of Linux services, use the systemctl command. 1. Check the service status: systemctlstatus can check whether the service is running, enabled or disabled. 2. Enable the service startup: sudosystemctlenable, such as sudosystemctlenablenginx. If it is started at the same time, use sudosystemctlenable--nownginx. 3. Disable the service startup: sudosystemctldisable, such as sudosystemctldisablecups. If it is stopped at the same time, use sudosystemctldisabl
How to set up a firewall in Linux
Aug 22, 2025 pm 04:41 PM
UsefirewalldoriptablestosecureLinux;firewalldisuser-friendlywithzonesandservices,idealforCentOS/RHEL/Fedora,whileiptablesoffersgranularcontrolforDebian/Ubuntu.Enablefirewalld:sudosystemctlstartfirewalld,allowserviceslikeSSHwith--add-service=ssh,orope
Linux how to list all running processes
Aug 08, 2025 am 06:42 AM
Usepsauxforacompletesnapshotofallrunningprocesses,showingdetailedinformationlikeUSER,PID,CPU,andmemoryusage.2.Usetoporhtopforreal-timemonitoringofprocesseswithdynamicupdates,wherehtopoffersamoreintuitiveinterface.3.UsepgreporpidoftoquicklyfindthePIDs
How to clean up your Linux system
Aug 22, 2025 am 07:42 AM
Removeunusedpackagesanddependencieswithsudoaptautoremove,cleanpackagecacheusingsudoaptcleanorautoclean,andremoveoldkernelsviasudoaptautoremove--purge.2.Clearsystemlogswithsudojournalctl--vacuum-time=7d,deletearchivedlogsin/var/log,andempty/tmpand/var
Linux how to view the contents of a file
Aug 19, 2025 pm 06:44 PM
ToviewfilecontentsinLinux,usedifferentcommandsbasedonyourneeds:1.Forsmallfiles,usecattodisplaytheentirecontentatonce,withcat-ntoshowlinenumbers.2.Forlargefiles,uselesstoscrollpagebypageorlinebyline,searchwith/search_term,andquitwithq.3.Usemoreforbasi
how to create an alias in linux
Aug 19, 2025 pm 08:13 PM
The steps to set up alias in Linux are as follows: 1. Temporarily set the use of the alias command such as aliasll='ls-la'; 2. Permanently set the shell configuration file, such as ~/.bashrc, and then execute the source to take effect; 3. Be careful to avoid overwriting the original command and the different shell configurations are independent. Alias can simplify complex commands and improve efficiency, but only after the current shell environment takes effect and closes the terminal, it needs to be reasonably defined and regularly checked for configuration.
Understanding the Linux Filesystem Hierarchy Standard (FHS)
Aug 06, 2025 pm 04:23 PM
/bin and /sbin store basic commands and system management commands; 2./usr stores user programs and related resources; 3./etc is the configuration file directory; 4./var stores variable data such as logs and caches; 5./home and /root are the home directories of ordinary users and root users; 6./tmp and /run are used for temporary files and runtime data; 7./dev, /proc, /sys provides device and system information interfaces; 8./lib and /lib64 contain library files required for system startup; 9./opt and /srv are used for third-party software and service data respectively; FHS improves system management efficiency through standardized directory structure, making the layout of Linux files clear and consistent, making it easy to maintain and


