🖥️tty
➡️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 tty command with important options and switches using examples.
3 minute read
▁ ▂ ▃ ▄ ꧁ 🔴☠ COMMANDLINE-KUNGFU WITH CHEATSHEETS ☠🔴꧂▅ ▃ ▂ ▁
# ████████╗████████╗██╗ ██╗
# ╚══██╔══╝╚══██╔══╝╚██╗ ██╔╝
# ██║ ██║ ╚████╔╝
# ██║ ██║ ╚██╔╝
# ██║ ██║ ██║
# ╚═╝ ╚═╝ ╚═╝
# The tty command prints the filename of the terminal connected to standard input.
tty
/dev/pts/10
# Have script run itself in a virtual terminal
tty >/dev/null || { urxvt -hold -e "$0" "$@" & exit; }
# Explanation: This can be the first line of a script that will be clicked from a graphical user interface in X to make it open up a virtual terminal to display output. If a terminal is already open it will run in the current terminal. It assumes urxvt and uses the hold option to keep from closing, both of which could be substituted for such as rxvt or add read at the end of the script.
# It's a single line if statement that checks the exit code of tty which prints the current terminal name usually nothing under X.
# The curly braces are needed for grouping.
# A space is required after the opening brace { and a semicolon is required before the closing brace }.
# Replacing what would be a semicolon, the ampersand & forks the terminal command to a second process and the launching script exits right away.
# -e feeds to the terminal application the expression of $0which holds the path of the script itself and $@, the entire set of quoted arguments.
# Limitations: If the script is large, say several gigabytes and the system tries to make two copies of the script, twice the size of RAM or memory will be needed for loading it.
# rxvt -e will kill any subprocesses at the end
## Alternative one-liners:
# Have script run itself in a virtual terminal
tty >/dev/null || { urxvt -e /bin/sh -c "tty >/tmp/proc$$; while test x; do sleep 1; done" & while test ! -f /tmp/proc$$; do sleep .1; done; FN=$(cat /tmp/proc$$); rm /tmp/proc$$; exec >$FN 2>$FN <$FN; }
# Explanation:
# We begin by testing if the script is not in a terminal with tty.
# If it is not we start a terminal that runs tty and saves it to a filename. $$ was set by the original script and is its PID. That is opened in the background using & and then the original script waits for the filename to appear, then reads and removes it.
# Finally, the main command is a special syntax of the bash builtin command exec that contains nothing but redirections (of stdout, stderr, and stdin) so they will apply to every command in the rest of the script file.
#==============================##==============================#
# CMD TTY #
#==============================##==============================#
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 tty in a clear format. This allows users to quickly access the needed information for tty without having to sift through lengthy texts. Especially in stressful situations or for recurring tasks, cheatsheets for tty 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.