[root@oel01db Shell-Scripting]# time tar -cvf archive.tar /var/log/
tar: Removing leading `/' from member names
/var/log/
/var/log/tallylog
.
.
/var/log/spooler-20251222
/var/log/spooler
real 0m0.166s
user 0m0.010s
sys 0m0.041s
[root@oel01db Shell-Scripting]#
This output is a perfect illustration of how Linux handles commands. It means you actually have two different versions of time on your system, and they behave differently.
Here is the breakdown of what that output tells you:
1. time is a shell keyword
This is the Internal Version.
What it is: A part of the Bash shell itself (like
if,while, orfor).Priority: Because it is a "keyword," Bash will always use this one by default when you just type
time.Strength: It is very flexible. It can time built-in shell functions, command blocks
{ ... }, and entire pipelines (time a | b | c).Weakness: It only gives you the basic "real, user, sys" output. It doesn't have many options for formatting.
Shell Keywords (The "Structure" of Bash)
Keywords are the fundamental building blocks of the shell's programming language. They are reserved words that define the logic and flow of a script.
Examples:
if,then,else,while,for,time,[[ ]],{ }.The Difference: Keywords are part of the shell's grammar. You cannot use them like a normal command (for example, you can't run
man [[because it’s not a standalone utility).
2. time is /usr/bin/time
This is the External Version.
What it is: An actual standalone program file located on your hard drive (part of the
gnu-timepackage).Priority: Bash ignores this unless you tell it specifically to use the file by typing the full path:
/usr/bin/time.Strength: It is much more powerful. It can track maximum RAM usage, disk I/O, and exit statuses. It also supports the
-oflag you were looking for earlier to save output to a file.Weakness: It cannot time shell keywords or complex Bash-only blocks as easily as the keyword version.
No comments:
Post a Comment