CIS 218 File Utilities and Filters
Text / File Commands • File Manipulation cat displays file text on STDOUT cut displays designated fields/characters echo displays string on STDOUT expand converts tabs to spaces file display info about a file find Locate file by name (find fmt simple text formatter fuser File user grep displays that match a pattern head displays designated number of lines from top of file join join two files together less display text a page at a time ls list file info lsof list open files more display text a page at a time nl numbers lines od displays octal, decimal, hex dump of file paste merges lines from two files sort sorts lines in a file Display file inode info (metadata). See also ls – I, find – inum. stat strings displays text strings in a binary file tac displays text in reverse order tail displays designated number of lines from bottom of file update file timestamp info, create file if it doesn’t exist touch tr translate utility unexpand converts spaces to tabs uniq displays unique sequential occurences of lines uuencode, uudecode See also base 64 command wc counts characters, words, and lines
UNIX Filters • cat: displays contents of a file (on STDOUT) • echo: copies string to STDOUT • head: displays beginning records in a file (default 10) • tail: displays ending records in a file (default 10) • sort: sorts records of a text file in ASCII order • uniq: removes consecutive duplicate lines of a text file (sort) • cut: displays specific words/bytes/columns of records in a text file -d used to tell what the column delimiter is -f used to tell which words to select -c used to tell which characters to select -b used to tell which bytes to select • join: joins specific matching records in a file • paste: joins records in a file, delineated by tabs • colrm: extracts specified parts of a file by column # based on their character position. Two numeric arguments tell beginning and ending column numbers that should be removed (if only 1 number end is assumed) • tr: translates one character to another tr ‘[a - z]’ ‘[A - Z]’ • wc: "word count“ counts # of characters, words and lines -l stands for just lines -w stands for just words -c stands for just characters • od: “octal dump“ displays text file contents in different formats -c characters -x hexadecinal -o octal • strings: displays text strings in a binary file
UNIX Filters • grep "global ‘regular expression’ filename". grep searches for the specified pattern displays each matching record. grep [- v] ‘regexp string’ filename • Filename follows normal filename expansion rules • -v inverts the selection • ‘regular expression’ meaning the usual regexp parameters: ^ - beginning of line $ - end of line . - replaced by any 1 character [ ] - choose one from the class of characters in the set [^ ] – negates the selection set * - 0 or more of preceding character ? – 0 or 1 of preceding character + - 1 or more of preceding character ‘ ‘ or “” - quotes a string \ - “escapes” the following character
UNIX Filters • find [/dir] – name filename – print – exec cmd {} \; • Locates files by filename anywhere in the directory structure starting at /dir. Within authorizations of the user ID issued in the find command. • Filename follows normal filename expansion rules • If specified, -exec repetitively issues cmd against every matching file name found specified by {}.
Redirection • Redirection > Redirect output to a file >> Append output to a file 2> Redirect errors to a file < Send file as input << HERE" redirection in a script | “Pipe" – STDOUT of one command to STDIN of next command tee Redirect STDOUT to a file also used in combination with exec command for filehandle redirection.
Recommend
More recommend