🖥️time
➡️This is a command-line reference manual for commands and command combinations that you don’t use often enough to remember it. This cheatsheet explains the time command with important options and switches using examples.
5 minute read
▁ ▂ ▃ ▄ ꧁ 🔴☠ COMMANDLINE-KUNGFU WITH CHEATSHEETS ☠🔴꧂▅ ▃ ▂ ▁
# ████████╗██╗███╗ ███╗███████╗
# ╚══██╔══╝██║████╗ ████║██╔════╝
# ██║ ██║██╔████╔██║█████╗
# ██║ ██║██║╚██╔╝██║██╔══╝
# ██║ ██║██║ ╚═╝ ██║███████╗
# ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝
# Make the output of the `time` builtin easier to parse
TIMEFORMAT=%R
# Explanation: The time builtin prints a summary of the real time, user CPU time and system CPU time spent executing commands, for example:
time sleep 1
# real 0m1.002s
# user 0m0.000s
# sys 0m0.002s
# If you need to parse this output, it helps to simplify it using the TIMEFORMAT variable. The value %R means "the elapsed time in seconds", for example:
TIMEFORMAT=%Rtime sleep 1
# 1.004
# The complete documentation of the format definition is in man bash, search for
TIMEFORMAT
# Export all Stremio movie names - I couldn't find movie library on any of the SQLlite Stremio databases, but on ~/.config/stremio/backgrounds2 the background image filenames corresponds to IMDB URL. So I foreach files and wget HTML title of each movie and save it to a file. This will retrieve all movie names, not just the Library.
time for movie in $(ls -1 /home/$USER/.config/stremio/backgrounds2 | sort -u);do wget -qO- --header="Accept-Language: en" "https://www.imdb.com/title/$movie/" | hxselect -s '\n' -c 'title' 2>/dev/null | tee ~/$(date +%Y-%m-%d_%T)-movie-list.txt ; done
time usleep 100000
# sleep for 1/10s or 1/100s or even 1/1000000s - sleep in microseconds instead of seconds Alternatively to usleep, which is not defined in POSIX 2008 (though it was defined up to POSIX 2004, and it is evidently available on Linux and other platforms with a history of POSIX compliance), the POSIX 2008 standard defines nanosleep Show Sample Output
time cat
# Instant stopwatch. Run to start timer and press Ctrl-D to stop it. "real" time is the elapsed time.
# Re-compress a gzip (.gz) file to a bzip2 (.bz2) file
time gzip -cd file1.tar.gz 2>~/logfile.txt | pv -t -r -b -W -i 5 -B 8M | bzip2 > file1.tar.bz2 2>>~/logfile .txt
# Explanation: *Requires PV (pipe viewer) if you want to monitor throughput; otherwise you can leave out the pv pipe. Transparently decompresses an arbitrary .gz file (does not have to be a tar) and re-compresses it to bzip2, which has better compression and error recovery. Echoes error messages to a file named logfile.txt in your home directory. NOTE: The original .gz file will NOT be deleted. If you want to save space, you will have to delete it manually.
# Test your hard drive speed
time (dd if=/dev/zero of=zerofile bs=1M count=500;sync);rm zerofile
# Explanation: Creates a 500MB blank file and times how long it takes to finish writing the entire thing to disk (sync)
time the entire dd + sync operation, and then remove the temporary file
# Limitations: Works with Bash; not tested in other environments
time tar jcvf largebackup.tar.bz2 /data
# Put 'time' before any command to record the real, system and user time it takes to complete.
# quick integer CPU benchmark
# You could have that little benchmark run on all cores in parallel, as a multi-core benchmark or stress test First find the number of cores, then have parallel iterate over that in, well, parallel
time cat /proc/cpuinfo |grep proc|wc -l|xargs seq|parallel -N 0 echo "2^2^20" '|' bc
# Sample output:
# ...
# 41454625947560171969501001538543925124881846970621917597708878154881\
# 18278788738248093374936943243527734573872009289119068940335579136
# real 0m12,698s
# user 0m14,461s
# sys 0m0,382s
# small CPU benchmark with PI, bc and time.
# Broken in two parts, first get the number of cores with cat /proc/cpuinfo |grep proc|wc -l and create a integer sequence with that number (xargs seq), then have GNU parallel loop that many times over the given command. Cheers!
time cat /proc/cpuinfo |grep proc|wc -l|xargs seq|parallel -N 0 echo "scale=4000\; a\(1\)\*4" '|' bc -l
# Sample output:
# ...
# 66983895228684783123552658213144957685726243344189303968642624341077\
# 3226978028073189154411010446823252716201052652272111660396
# real 0m31,847s
# user 0m59,085s
# sys 0m0,151s
# Redirect the output of the time builtin command
{ time command; } > out.out 2> time+err.out
# Explanation:
# time is a bash builtin command, and redirecting its output does not work the same way as with proper executables
# If you execute within braces like above, the output of time will go to stderr (standard error), so you can capture it with 2>time.out
# An alternative is to use the /usr/bin/time executable, by referring to its full path. (The path may be different depending on your system.)
Cheatsheets are an excellent complement to other information sources like Linux man-pages, Linux help, or How-To’s and tutorials, as they provide compact and easily accessible information. While man-pages and detailed tutorials often contain comprehensive explanations and extensive guides, cheatsheets summarize the most important options forthe command time in a clear format. This allows users to quickly access the needed information for time without having to sift through lengthy texts. Especially in stressful situations or for recurring tasks, cheatsheets for time are a valuable resource to work efficiently and purposefully.
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
█║▌│║█║▌★ KALI ★ PARROT ★ DEBIAN 🔴 PENTESTING ★ HACKING ★ █║▌│║█║▌
██╗ ██╗ ██████╗ ██████╗ ██╗ ██╗███████╗██████╗
████████╗██╔══██╗██╔═══██╗╚██╗██╔╝██╔════╝██╔══██╗
╚██╔═██╔╝██║ ██║██║ ██║ ╚███╔╝ █████╗ ██║ ██║
████████╗██║ ██║██║ ██║ ██╔██╗ ██╔══╝ ██║ ██║
╚██╔═██╔╝██████╔╝╚██████╔╝██╔╝ ██╗███████╗██████╔╝
╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═════╝
█║▌│║█║▌ WITH COMMANDLINE-KUNGFU POWER █║▌│║█║▌
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.