001package org.unix4j.unix; 002 003import org.unix4j.command.CommandInterface; 004 005import org.unix4j.unix.tail.TailFactory; 006import org.unix4j.unix.tail.TailOption; 007import org.unix4j.unix.tail.TailOptions; 008import org.unix4j.unix.tail.TailOptionSets; 009 010/** 011 * Non-instantiable module with inner types making up the <b>tail</b> command. 012 * <p> 013 * <b>NAME</b> 014 * <p> 015 * tail - display the last part of a file 016 * <p> 017 * <b>SYNOPSIS</b> 018 * <p> 019 * <table> 020 * <tr><td width="10px"></td><td nowrap="nowrap">{@code tail}</td></tr> 021 * <tr><td width="10px"></td><td nowrap="nowrap">{@code tail <args>}</td></tr> 022 * <tr><td width="10px"></td><td nowrap="nowrap">{@code tail <count>}</td></tr> 023 * <tr><td width="10px"></td><td nowrap="nowrap">{@code tail [-cqs] <count>}</td></tr> 024 * <tr><td width="10px"></td><td nowrap="nowrap">{@code tail <files>}</td></tr> 025 * <tr><td width="10px"></td><td nowrap="nowrap">{@code tail <count> <files>}</td></tr> 026 * <tr><td width="10px"></td><td nowrap="nowrap">{@code tail <count> <paths>}</td></tr> 027 * <tr><td width="10px"></td><td nowrap="nowrap">{@code tail [-cqs] <count> <files>}</td></tr> 028 * <tr><td width="10px"></td><td nowrap="nowrap">{@code tail [-cqs] <count> <paths>}</td></tr> 029 * </table> 030 * <p> 031 * See {@link Interface} for the corresponding command signature methods. 032 * <p> 033 * <b>DESCRIPTION</b> 034 * <p> 035 * <p> This filter displays the first <i>count</i> lines or characters of each of the specified files, or of the standard input if no files are specified. If <i>count</i> is omitted it defaults to 10. Both line and character counts start from 1. </p> <p> If more than a single file is specified, each file is preceded by a header consisting of the string {@code "==> XXX <=="} where {@code "XXX"} is the name of the file. </p> 036 * 037 * <p> 038 * <b>Options</b> 039 * <p> 040 * The following options are supported: 041 * <p> 042 * <table> 043 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -c}</td><td> </td><td nowrap="nowrap">{@code --chars}</td><td> </td><td>The {@code count} argument is in units of characters instead of 044 lines. Starts from 1 and includes line ending characters.</td></tr> 045 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -q}</td><td> </td><td nowrap="nowrap">{@code --suppressHeaders}</td><td> </td><td>Suppresses printing of headers when multiple files are being 046 examined.</td></tr> 047 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -s}</td><td> </td><td nowrap="nowrap">{@code --countFromStart}</td><td> </td><td>The {@code count} argument is relative to the beginning of the file 048 instead of counting from the end of the file. For instance, 049 {@code tail -s 10} prints the lines starting from line 10; 050 {@code tail -s 1} prints the whole file.</td></tr> 051 * </table> 052 * <p> 053 * <b>OPERANDS</b> 054 * <p> 055 * The following operands are supported: 056 * <p> 057 * <table> 058 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code <count>}</td><td> : </td><td nowrap="nowrap">{@code long}</td><td> </td><td>The last {@code count} lines of each input file are 059 copied to standard output, starting from 1 (characters instead of 060 lines if the {@code -c} option is specified, and offset from start 061 instead of end with {@code -s} option). Must be a non-negative 062 integer or an exception is thrown. If {@code count} is greater than 063 the number number of lines (characters) in the input, the 064 application will not error and send the whole file to the output.</td></tr> 065 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code <paths>}</td><td> : </td><td nowrap="nowrap">{@code String...}</td><td> </td><td>Pathnames of the input files to be filtered; wildcards * and ? are 066 supported; relative paths are resolved on the basis of the current 067 working directory.</td></tr> 068 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code <files>}</td><td> : </td><td nowrap="nowrap">{@code java.io.File...}</td><td> </td><td>The input files to be filtered; relative paths are not resolved (use 069 the string paths argument to enable relative path resolving based on 070 the current working directory).</td></tr> 071 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code <args>}</td><td> : </td><td nowrap="nowrap">{@code String...}</td><td> </td><td>String arguments defining the options and operands for the command. 072 Options can be specified by acronym (with a leading dash "-") or by 073 long name (with two leading dashes "--"). Operands other than the 074 default "--paths" operand have to be prefixed with the operand 075 name (e.g. "--count" for a subsequent count operand value).</td></tr> 076 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code <options>}</td><td> : </td><td nowrap="nowrap">{@code TailOptions}</td><td> </td><td>Options for the tail command.</td></tr> 077 * </table> 078 */ 079public final class Tail { 080 /** 081 * The "tail" command name. 082 */ 083 public static final String NAME = "tail"; 084 085 /** 086 * Interface defining all method signatures for the "tail" command. 087 * 088 * @param <R> 089 * the generic return type for all command signature methods 090 * to support different implementor types; the methods of a 091 * command factory for instance returns a command instance; 092 * command builders can also implement this interface, but their 093 * methods return the builder itself enabling for chained method 094 * invocation to create joined commands 095 */ 096 public static interface Interface<R> extends CommandInterface<R> { 097 /** 098 * Reads the last 10 lines from the standard input and writes them to 099 the standard output. 100 * 101 * @return the generic type {@code <R>} defined by the implementing class; 102 * the command itself returns no value and writes its result to the 103 * standard output; see class level parameter comments for more 104 * details 105 */ 106 R tail(); 107 /** 108 * Reads the last n lines from each of the files specified and writes 109 them to the standard output. If more than a single file is 110 specified, each file is preceded by a header consisting of the 111 string {@code "==> XXX <=="} where {@code "XXX"} is the name 112 of the file. 113<p> 114 Options can be specified by acronym (with a leading dash "-") or by 115 long name (with two leading dashes "--"). Operands other than the 116 default "--paths" operand have to be prefixed with the operand 117 name. 118 * 119 * @param args String arguments defining the options and operands for the command. 120 Options can be specified by acronym (with a leading dash "-") or by 121 long name (with two leading dashes "--"). Operands other than the 122 default "--paths" operand have to be prefixed with the operand 123 name (e.g. "--count" for a subsequent count operand value). 124 * @return the generic type {@code <R>} defined by the implementing class; 125 * the command itself returns no value and writes its result to the 126 * standard output; see class level parameter comments for more 127 * details 128 */ 129 R tail(String... args); 130 /** 131 * Reads the last {@code count} lines from the standard input and 132 writes them to the standard output. 133 * 134 * @param count The last {@code count} lines of each input file are 135 copied to standard output, starting from 1 (characters instead of 136 lines if the {@code -c} option is specified, and offset from start 137 instead of end with {@code -s} option). Must be a non-negative 138 integer or an exception is thrown. If {@code count} is greater than 139 the number number of lines (characters) in the input, the 140 application will not error and send the whole file to the output. 141 * @return the generic type {@code <R>} defined by the implementing class; 142 * the command itself returns no value and writes its result to the 143 * standard output; see class level parameter comments for more 144 * details 145 */ 146 R tail(long count); 147 /** 148 * Reads the last {@code count} lines or characters from the standard 149 input and writes them to the standard output. 150 * 151 * @param options Options for the tail command. 152 * @param count The last {@code count} lines of each input file are 153 copied to standard output, starting from 1 (characters instead of 154 lines if the {@code -c} option is specified, and offset from start 155 instead of end with {@code -s} option). Must be a non-negative 156 integer or an exception is thrown. If {@code count} is greater than 157 the number number of lines (characters) in the input, the 158 application will not error and send the whole file to the output. 159 * @return the generic type {@code <R>} defined by the implementing class; 160 * the command itself returns no value and writes its result to the 161 * standard output; see class level parameter comments for more 162 * details 163 */ 164 R tail(TailOptions options, long count); 165 /** 166 * Reads the last 10 lines from each of the specified files and writes 167 them to the standard output. If more than a single file is 168 specified, each file is preceded by a header consisting of the 169 string {@code "==> XXX <=="} where {@code "XXX"} is the name 170 of the file. 171 * 172 * @param files The input files to be filtered; relative paths are not resolved (use 173 the string paths argument to enable relative path resolving based on 174 the current working directory). 175 * @return the generic type {@code <R>} defined by the implementing class; 176 * the command itself returns no value and writes its result to the 177 * standard output; see class level parameter comments for more 178 * details 179 */ 180 R tail(java.io.File... files); 181 /** 182 * Reads the last {@code count} lines from each of the specified files 183 and writes them to the standard output. If more than a single file 184 is specified, each file is preceded by a header consisting of the 185 string {@code "==> XXX <=="} where {@code "XXX"} is the name 186 of the file. 187 * 188 * @param count The last {@code count} lines of each input file are 189 copied to standard output, starting from 1 (characters instead of 190 lines if the {@code -c} option is specified, and offset from start 191 instead of end with {@code -s} option). Must be a non-negative 192 integer or an exception is thrown. If {@code count} is greater than 193 the number number of lines (characters) in the input, the 194 application will not error and send the whole file to the output. 195 * @param files The input files to be filtered; relative paths are not resolved (use 196 the string paths argument to enable relative path resolving based on 197 the current working directory). 198 * @return the generic type {@code <R>} defined by the implementing class; 199 * the command itself returns no value and writes its result to the 200 * standard output; see class level parameter comments for more 201 * details 202 */ 203 R tail(long count, java.io.File... files); 204 /** 205 * Reads the last {@code count} lines from each of the specified files 206 and writes them to the standard output. If more than a single file 207 is specified, each file is preceded by a header consisting of the 208 string {@code "==> XXX <=="} where {@code "XXX"} is the name 209 of the file. 210 * 211 * @param count The last {@code count} lines of each input file are 212 copied to standard output, starting from 1 (characters instead of 213 lines if the {@code -c} option is specified, and offset from start 214 instead of end with {@code -s} option). Must be a non-negative 215 integer or an exception is thrown. If {@code count} is greater than 216 the number number of lines (characters) in the input, the 217 application will not error and send the whole file to the output. 218 * @param paths Pathnames of the input files to be filtered; wildcards * and ? are 219 supported; relative paths are resolved on the basis of the current 220 working directory. 221 * @return the generic type {@code <R>} defined by the implementing class; 222 * the command itself returns no value and writes its result to the 223 * standard output; see class level parameter comments for more 224 * details 225 */ 226 R tail(long count, String... paths); 227 /** 228 * Reads the last {@code count} lines or characters from each of the 229 specified files and writes them to the standard output. If more than 230 a single file is specified and the {@code -q} option is not 231 specified, each file is preceded by a header consisting of the 232 string {@code "==> XXX <=="} where {@code "XXX"} is the name 233 of the file. 234 * 235 * @param options Options for the tail command. 236 * @param count The last {@code count} lines of each input file are 237 copied to standard output, starting from 1 (characters instead of 238 lines if the {@code -c} option is specified, and offset from start 239 instead of end with {@code -s} option). Must be a non-negative 240 integer or an exception is thrown. If {@code count} is greater than 241 the number number of lines (characters) in the input, the 242 application will not error and send the whole file to the output. 243 * @param files The input files to be filtered; relative paths are not resolved (use 244 the string paths argument to enable relative path resolving based on 245 the current working directory). 246 * @return the generic type {@code <R>} defined by the implementing class; 247 * the command itself returns no value and writes its result to the 248 * standard output; see class level parameter comments for more 249 * details 250 */ 251 R tail(TailOptions options, long count, java.io.File... files); 252 /** 253 * Reads the last {@code count} lines or characters from each of the 254 specified files and writes them to the standard output. If more than 255 a single file is specified and the {@code -q} option is not 256 specified, each file is preceded by a header consisting of the 257 string {@code "==> XXX <=="} where {@code "XXX"} is the name 258 of the file. 259 * 260 * @param options Options for the tail command. 261 * @param count The last {@code count} lines of each input file are 262 copied to standard output, starting from 1 (characters instead of 263 lines if the {@code -c} option is specified, and offset from start 264 instead of end with {@code -s} option). Must be a non-negative 265 integer or an exception is thrown. If {@code count} is greater than 266 the number number of lines (characters) in the input, the 267 application will not error and send the whole file to the output. 268 * @param paths Pathnames of the input files to be filtered; wildcards * and ? are 269 supported; relative paths are resolved on the basis of the current 270 working directory. 271 * @return the generic type {@code <R>} defined by the implementing class; 272 * the command itself returns no value and writes its result to the 273 * standard output; see class level parameter comments for more 274 * details 275 */ 276 R tail(TailOptions options, long count, String... paths); 277 } 278 279 /** 280 * Options for the "tail" command: {@link TailOption#chars c}, {@link TailOption#suppressHeaders q}, {@link TailOption#countFromStart s}. 281 * <p> 282 * <table> 283 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -c}</td><td> </td><td nowrap="nowrap">{@code --chars}</td><td> </td><td>The {@code count} argument is in units of characters instead of 284 lines. Starts from 1 and includes line ending characters.</td></tr> 285 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -q}</td><td> </td><td nowrap="nowrap">{@code --suppressHeaders}</td><td> </td><td>Suppresses printing of headers when multiple files are being 286 examined.</td></tr> 287 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -s}</td><td> </td><td nowrap="nowrap">{@code --countFromStart}</td><td> </td><td>The {@code count} argument is relative to the beginning of the file 288 instead of counting from the end of the file. For instance, 289 {@code tail -s 10} prints the lines starting from line 10; 290 {@code tail -s 1} prints the whole file.</td></tr> 291 * </table> 292 */ 293 public static final TailOptionSets Options = TailOptionSets.INSTANCE; 294 295 /** 296 * Singleton {@link TailFactory factory} instance for the "tail" command. 297 */ 298 public static final TailFactory Factory = TailFactory.INSTANCE; 299 300 // no instances 301 private Tail() { 302 super(); 303 } 304}