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 <inputs>}</td></tr> 026 * <tr><td width="10px"></td><td nowrap="nowrap">{@code tail <count> <files>}</td></tr> 027 * <tr><td width="10px"></td><td nowrap="nowrap">{@code tail <count> <paths>}</td></tr> 028 * <tr><td width="10px"></td><td nowrap="nowrap">{@code tail <count> <inputs>}</td></tr> 029 * <tr><td width="10px"></td><td nowrap="nowrap">{@code tail [-cqs] <count> <files>}</td></tr> 030 * <tr><td width="10px"></td><td nowrap="nowrap">{@code tail [-cqs] <count> <paths>}</td></tr> 031 * <tr><td width="10px"></td><td nowrap="nowrap">{@code tail [-cqs] <count> <inputs>}</td></tr> 032 * </table> 033 * <p> 034 * See {@link Interface} for the corresponding command signature methods. 035 * <p> 036 * <b>DESCRIPTION</b> 037 * <p> 038 * <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> 039 * 040 * <p> 041 * <b>Options</b> 042 * <p> 043 * The following options are supported: 044 * <p> 045 * <table> 046 * <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 047 lines. Starts from 1 and includes line ending characters.</td></tr> 048 * <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 049 examined.</td></tr> 050 * <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 051 instead of counting from the end of the file. For instance, 052 {@code tail -s 10} prints the lines starting from line 10; 053 {@code tail -s 1} prints the whole file.</td></tr> 054 * </table> 055 * <p> 056 * <b>OPERANDS</b> 057 * <p> 058 * The following operands are supported: 059 * <p> 060 * <table> 061 * <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 062 copied to standard output, starting from 1 (characters instead of 063 lines if the {@code -c} option is specified, and offset from start 064 instead of end with {@code -s} option). Must be a non-negative 065 integer or an exception is thrown. If {@code count} is greater than 066 the number number of lines (characters) in the input, the 067 application will not error and send the whole file to the output.</td></tr> 068 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code <paths>}</td><td> : </td><td nowrap="nowrap">{@code String...}</td><td> </td><td>Path names of the input files to be filtered; wildcards * and ? are 069 supported; relative paths are resolved on the basis of the current 070 working directory.</td></tr> 071 * <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 072 the string paths argument to enable relative path resolving based on 073 the current working directory).</td></tr> 074 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code <inputs>}</td><td> : </td><td nowrap="nowrap">{@code org.unix4j.io.Input...}</td><td> </td><td>The inputs to be filtered.</td></tr> 075 * <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. 076 Options can be specified by acronym (with a leading dash "-") or by 077 long name (with two leading dashes "--"). Operands other than the 078 default "--paths" operand have to be prefixed with the operand 079 name (e.g. "--count" for a subsequent count operand value).</td></tr> 080 * <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> 081 * </table> 082 */ 083public final class Tail { 084 /** 085 * The "tail" command name. 086 */ 087 public static final String NAME = "tail"; 088 089 /** 090 * Interface defining all method signatures for the "tail" command. 091 * 092 * @param <R> 093 * the generic return type for all command signature methods 094 * to support different implementor types; the methods of a 095 * command factory for instance returns a command instance; 096 * command builders can also implement this interface, but their 097 * methods return the builder itself enabling for chained method 098 * invocation to create joined commands 099 */ 100 public static interface Interface<R> extends CommandInterface<R> { 101 /** 102 * Reads the last 10 lines from the standard input and writes them to 103 the standard output. 104 * 105 * @return the generic type {@code <R>} defined by the implementing class; 106 * the command itself returns no value and writes its result to the 107 * standard output; see class level parameter comments for more 108 * details 109 */ 110 R tail(); 111 /** 112 * Reads the last n lines from each of the files specified and writes 113 them to the standard output. If more than a single file is 114 specified, each file is preceded by a header consisting of the 115 string {@code "==> XXX <=="} where {@code "XXX"} is the name 116 of the file. 117<p> 118 Options can be specified by acronym (with a leading dash "-") or by 119 long name (with two leading dashes "--"). Operands other than the 120 default "--paths" operand have to be prefixed with the operand 121 name. 122 * 123 * @param args String arguments defining the options and operands for the command. 124 Options can be specified by acronym (with a leading dash "-") or by 125 long name (with two leading dashes "--"). Operands other than the 126 default "--paths" operand have to be prefixed with the operand 127 name (e.g. "--count" for a subsequent count operand value). 128 * @return the generic type {@code <R>} defined by the implementing class; 129 * the command itself returns no value and writes its result to the 130 * standard output; see class level parameter comments for more 131 * details 132 */ 133 R tail(String... args); 134 /** 135 * Reads the last {@code count} lines from the standard input and 136 writes them to the standard output. 137 * 138 * @param count The last {@code count} lines of each input file are 139 copied to standard output, starting from 1 (characters instead of 140 lines if the {@code -c} option is specified, and offset from start 141 instead of end with {@code -s} option). Must be a non-negative 142 integer or an exception is thrown. If {@code count} is greater than 143 the number number of lines (characters) in the input, the 144 application will not error and send the whole file to the output. 145 * @return the generic type {@code <R>} defined by the implementing class; 146 * the command itself returns no value and writes its result to the 147 * standard output; see class level parameter comments for more 148 * details 149 */ 150 R tail(long count); 151 /** 152 * Reads the last {@code count} lines or characters from the standard 153 input and writes them to the standard output. 154 * 155 * @param options Options for the tail command. 156 * @param count The last {@code count} lines of each input file are 157 copied to standard output, starting from 1 (characters instead of 158 lines if the {@code -c} option is specified, and offset from start 159 instead of end with {@code -s} option). Must be a non-negative 160 integer or an exception is thrown. If {@code count} is greater than 161 the number number of lines (characters) in the input, the 162 application will not error and send the whole file to the output. 163 * @return the generic type {@code <R>} defined by the implementing class; 164 * the command itself returns no value and writes its result to the 165 * standard output; see class level parameter comments for more 166 * details 167 */ 168 R tail(TailOptions options, long count); 169 /** 170 * Reads the last 10 lines from each of the specified files and writes 171 them to the standard output. If more than a single file is 172 specified, each file is preceded by a header consisting of the 173 string {@code "==> XXX <=="} where {@code "XXX"} is the name 174 of the file. 175 * 176 * @param files The input files to be filtered; relative paths are not resolved (use 177 the string paths argument to enable relative path resolving based on 178 the current working directory). 179 * @return the generic type {@code <R>} defined by the implementing class; 180 * the command itself returns no value and writes its result to the 181 * standard output; see class level parameter comments for more 182 * details 183 */ 184 R tail(java.io.File... files); 185 /** 186 * Reads the last 10 lines from each of the specified inputs and writes 187 them to the standard output. If more than a single input is 188 specified, each one is preceded by a header consisting of the 189 string {@code "==> XXX <=="} where {@code "XXX"} is the input's 190 string representation. 191 * 192 * @param inputs The inputs to be filtered. 193 * @return the generic type {@code <R>} defined by the implementing class; 194 * the command itself returns no value and writes its result to the 195 * standard output; see class level parameter comments for more 196 * details 197 */ 198 R tail(org.unix4j.io.Input... inputs); 199 /** 200 * Reads the last {@code count} lines from each of the specified files 201 and writes them to the standard output. If more than a single file 202 is specified, each file is preceded by a header consisting of the 203 string {@code "==> XXX <=="} where {@code "XXX"} is the name 204 of the file. 205 * 206 * @param count The last {@code count} lines of each input file are 207 copied to standard output, starting from 1 (characters instead of 208 lines if the {@code -c} option is specified, and offset from start 209 instead of end with {@code -s} option). Must be a non-negative 210 integer or an exception is thrown. If {@code count} is greater than 211 the number number of lines (characters) in the input, the 212 application will not error and send the whole file to the output. 213 * @param files The input files to be filtered; relative paths are not resolved (use 214 the string paths argument to enable relative path resolving based on 215 the current working directory). 216 * @return the generic type {@code <R>} defined by the implementing class; 217 * the command itself returns no value and writes its result to the 218 * standard output; see class level parameter comments for more 219 * details 220 */ 221 R tail(long count, java.io.File... files); 222 /** 223 * Reads the last {@code count} lines from each of the specified files 224 and writes them to the standard output. If more than a single file 225 is specified, each file is preceded by a header consisting of the 226 string {@code "==> XXX <=="} where {@code "XXX"} is the name 227 of the file. 228 * 229 * @param count The last {@code count} lines of each input file are 230 copied to standard output, starting from 1 (characters instead of 231 lines if the {@code -c} option is specified, and offset from start 232 instead of end with {@code -s} option). Must be a non-negative 233 integer or an exception is thrown. If {@code count} is greater than 234 the number number of lines (characters) in the input, the 235 application will not error and send the whole file to the output. 236 * @param paths Path names of the input files to be filtered; wildcards * and ? are 237 supported; relative paths are resolved on the basis of the current 238 working directory. 239 * @return the generic type {@code <R>} defined by the implementing class; 240 * the command itself returns no value and writes its result to the 241 * standard output; see class level parameter comments for more 242 * details 243 */ 244 R tail(long count, String... paths); 245 /** 246 * Reads the last {@code count} lines from each of the specified inputs 247 and writes them to the standard output. If more than a single input 248 is specified, each file is preceded by a header consisting of the 249 string {@code "==> XXX <=="} where {@code "XXX"} is the input's 250 string representation. 251 * 252 * @param count The last {@code count} lines of each input file are 253 copied to standard output, starting from 1 (characters instead of 254 lines if the {@code -c} option is specified, and offset from start 255 instead of end with {@code -s} option). Must be a non-negative 256 integer or an exception is thrown. If {@code count} is greater than 257 the number number of lines (characters) in the input, the 258 application will not error and send the whole file to the output. 259 * @param inputs The inputs to be filtered. 260 * @return the generic type {@code <R>} defined by the implementing class; 261 * the command itself returns no value and writes its result to the 262 * standard output; see class level parameter comments for more 263 * details 264 */ 265 R tail(long count, org.unix4j.io.Input... inputs); 266 /** 267 * Reads the last {@code count} lines or characters from each of the 268 specified files and writes them to the standard output. If more than 269 a single file is specified and the {@code -q} option is not 270 specified, each file is preceded by a header consisting of the 271 string {@code "==> XXX <=="} where {@code "XXX"} is the name 272 of the file. 273 * 274 * @param options Options for the tail command. 275 * @param count The last {@code count} lines of each input file are 276 copied to standard output, starting from 1 (characters instead of 277 lines if the {@code -c} option is specified, and offset from start 278 instead of end with {@code -s} option). Must be a non-negative 279 integer or an exception is thrown. If {@code count} is greater than 280 the number number of lines (characters) in the input, the 281 application will not error and send the whole file to the output. 282 * @param files The input files to be filtered; relative paths are not resolved (use 283 the string paths argument to enable relative path resolving based on 284 the current working directory). 285 * @return the generic type {@code <R>} defined by the implementing class; 286 * the command itself returns no value and writes its result to the 287 * standard output; see class level parameter comments for more 288 * details 289 */ 290 R tail(TailOptions options, long count, java.io.File... files); 291 /** 292 * Reads the last {@code count} lines or characters from each of the 293 specified files and writes them to the standard output. If more than 294 a single file is specified and the {@code -q} option is not 295 specified, each file is preceded by a header consisting of the 296 string {@code "==> XXX <=="} where {@code "XXX"} is the name 297 of the file. 298 * 299 * @param options Options for the tail command. 300 * @param count The last {@code count} lines of each input file are 301 copied to standard output, starting from 1 (characters instead of 302 lines if the {@code -c} option is specified, and offset from start 303 instead of end with {@code -s} option). Must be a non-negative 304 integer or an exception is thrown. If {@code count} is greater than 305 the number number of lines (characters) in the input, the 306 application will not error and send the whole file to the output. 307 * @param paths Path names of the input files to be filtered; wildcards * and ? are 308 supported; relative paths are resolved on the basis of the current 309 working directory. 310 * @return the generic type {@code <R>} defined by the implementing class; 311 * the command itself returns no value and writes its result to the 312 * standard output; see class level parameter comments for more 313 * details 314 */ 315 R tail(TailOptions options, long count, String... paths); 316 /** 317 * Reads the last {@code count} lines or characters from each of the 318 specified inputs and writes them to the standard output. If more than 319 a single input is specified and the {@code -q} option is not 320 specified, each file is preceded by a header consisting of the 321 string {@code "==> XXX <=="} where {@code "XXX"} is the input's 322 string representation. 323 * 324 * @param options Options for the tail command. 325 * @param count The last {@code count} lines of each input file are 326 copied to standard output, starting from 1 (characters instead of 327 lines if the {@code -c} option is specified, and offset from start 328 instead of end with {@code -s} option). Must be a non-negative 329 integer or an exception is thrown. If {@code count} is greater than 330 the number number of lines (characters) in the input, the 331 application will not error and send the whole file to the output. 332 * @param inputs The inputs to be filtered. 333 * @return the generic type {@code <R>} defined by the implementing class; 334 * the command itself returns no value and writes its result to the 335 * standard output; see class level parameter comments for more 336 * details 337 */ 338 R tail(TailOptions options, long count, org.unix4j.io.Input... inputs); 339 } 340 341 /** 342 * Options for the "tail" command: {@link TailOption#chars c}, {@link TailOption#suppressHeaders q}, {@link TailOption#countFromStart s}. 343 * <p> 344 * <table> 345 * <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 346 lines. Starts from 1 and includes line ending characters.</td></tr> 347 * <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 348 examined.</td></tr> 349 * <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 350 instead of counting from the end of the file. For instance, 351 {@code tail -s 10} prints the lines starting from line 10; 352 {@code tail -s 1} prints the whole file.</td></tr> 353 * </table> 354 */ 355 public static final TailOptionSets Options = TailOptionSets.INSTANCE; 356 357 /** 358 * Singleton {@link TailFactory factory} instance for the "tail" command. 359 */ 360 public static final TailFactory Factory = TailFactory.INSTANCE; 361 362 // no instances 363 private Tail() { 364 super(); 365 } 366}