less-than-more-than
View text files interactively
TLDR
Open a file in a file descriptor for read an write
Open a file descriptor to a remote connection
Close a file descriptor
SYNOPSIS
This term refers to shell features rather than a single command. The primary components are:
1. less command syntax:
less [-?abBcCdeEfFgGiIJKmMnNqQrRsSuUVwWXz] [-P prompt] [-t tag] [-T tagsfile] [-u [bBsS]] [-x tab,...] [-y lines] [-z lines] [-_ [^]] [-- [.] ] [-| file...]
2. Input Redirection syntax:
command options < input_file
3. Output Redirection syntax:
command options > output_file
command options >> append_file
PARAMETERS
-?
Display help (brief list of less commands).
-a
Search forward from the current position in the first file, or from the beginning of subsequent files.
-B
Don't automatically skip over blank lines.
-E
Causes less to exit automatically when the end of the file is reached.
-F
Causes less to exit if the entire file can be displayed on the first screen.
-i
Causes searches to ignore case, unless the search pattern contains uppercase letters.
-N
Display line numbers at the beginning of each line.
-R
Causes 'raw' control characters to be displayed.
-S
Chop long lines rather than wrapping them.
-X
Disable sending termcap initialization/deinitialization strings to the terminal.
DESCRIPTION
The phrase "less-than-more-than" does not refer to a single, executable Linux command. Instead, it's a colloquial expression that commonly alludes to two distinct but related concepts in the Linux command-line environment:
1. Shell Input Redirection (<): The "less-than" symbol is used to redirect the content of a file to become the standard input for a command, rather than the keyboard.
2. Shell Output Redirection (>): The "more-than" symbol is used to redirect the standard output of a command to a file, overwriting its contents.
These operators are fundamental to shell scripting and command-line data processing. Often, these redirection concepts are discussed in conjunction with the less command, a powerful pager used for viewing text files or command output one screen at a time. While less itself primarily takes input (often via redirection or pipes) and displays it, it doesn't directly use '>' for its own output in the same way other commands might. The "less-than-more-than" idiom, therefore, encapsulates the idea of controlling data flow into and out of commands, with less being a common consumer of redirected input.
CAVEATS
The most important caveat is that "less-than-more-than" is not a directly executable Linux command or program. It is a conceptual term referring to shell features (<, >) and a separate utility (less). Confusing it as a single command will lead to errors.
When using output redirection (>), be extremely cautious as it overwrites the target file without warning. Use >> (append redirection) to add content to the end of a file, or ensure you intend to replace the file's contents entirely. Input redirection (<) expects the specified file to exist and be readable. Improper use of these operators can lead to data loss or unexpected command behavior.
INPUT REDIRECTION (<)
The 'less-than' symbol (<) is used to change the standard input source for a command from the keyboard to a specified file. Instead of waiting for user input, the command will read its input directly from the contents of the file. This is particularly useful for commands that process text, allowing them to operate on file content without having to open the file explicitly.
Example: grep "pattern" < logfile.txt (finds patterns in logfile.txt by redirecting its content to grep's standard input).
OUTPUT REDIRECTION (>)
The 'more-than' symbol (>) is used to redirect the standard output of a command from the terminal screen to a specified file. If the file does not exist, it will be created. If the file already exists, its contents will be completely overwritten.
For appending output to an existing file without overwriting, the double 'more-than' symbol (>>) is used. This adds the command's output to the end of the file.
Example: ls -l > filelist.txt (writes directory listing to filelist.txt, overwriting if it exists).
Example: echo "New line" >> filelist.txt (adds "New line" to the end of filelist.txt).
HISTORY
The less command was written by Mark Nudelman and first released in 1983, with the goal of being a more flexible and powerful alternative to the earlier more pager. Its name is a playful jab at more, implying it can do "less" (meaning fewer restrictions) than more can. It allows both forward and backward navigation, unlike more which was primarily forward-only.
Input and output redirection, using the '<' and '>' operators, are fundamental features of the Unix shell, predating specific commands like less. These redirection mechanisms were integral to the design of the original Unix operating system and its command-line interface, allowing for powerful piping and script automation. They enable the core Unix philosophy of small, specialized tools working together by manipulating their standard input and output streams.