cat - concatenate a file
Display the contents of a file with the concatenate command, cat.
Syntax cat [options] [file]
Common Options
-n precede each line with a line number
-v display non-printing characters, except tabs, new-lines, and form-feeds
-e display $ at the end of each line (prior to new-line) (when used with -v option)
Examples % cat filename
You can list a series of files on the command line, and cat will concatenate them, starting each in turn, immediately after completing the previous one, e.g.:
% cat file1 file2 file3
DATE
The date command gives the current date and time.
Syntax
d ate[“+ fo rm at-S trln g ”]
Example
$date
Its output is as follows
Mon Nov 27 11:24:35 EST 2006
The date format can also be used with format-string The format-string can include following format-characters.
%T Gives time as HH:MM:SS
%H Gives Hour from 00 to 23
%M Gives Minute from 00 to 59
%S Gives Second from 00 to 59
%m Gives month of the year
%d Gives day of the month
%y Gives last two digits of the year.
Example
S date "+DATE IS%D TIME IS %T"
Will give the output as: DATE IS 1 1/27/06 TIME IS 16:38:23 Example
$ date "+DAY %d MONTH %m YEAR %y"
will give the output as: DAY 27 MONTH 1 1 YEAR 06
The find command recursively searches the directory tree for each specified path, seeking files that match a Boolean expression written using the terms given in the text that follows the expression. The output from the find command depends on the terms specified by the final parameter.
Note that the -print option is the default so is not required. This was not always the case. In earlier versions of AIX and on other UNIX systems that have not yet implemented the POSIX standard for the find command, the -print option is required for the result to be displayed or used in a pipe.
find replaces the {} with the names of the files matched. It is used as a placeholder for matches.
Note use of the escaped ; to terminate the command that find is to execute.
The find command may also be used with a -ls option; that is, $ find . -name 'm*' -ls.
Note that the -exec option is non-interactive.
The \; is hard coded with the find command. This is required for use with -exec and -ok.
It is a good idea to use the -ok option rather than -exec if there are not a lot of files that match the search criteria. It is a lot safer if your pattern is not exactly what you think it is.
The grep command searches for the pattern specified and writes each matching line to standard output.
The search can be for simple text, like a string or a name. grep can also look for logical constructs, called regular expressions, that use patterns and wildcards to symbolize something special in the text, for example, only lines that start with an uppercase T.
The command displays the name of the file containing the matched line, if more than one file is specified for the search.
On-Line Documentation:
The UNIX manual, usually called man pages, is available on-line to explain the usage of the UNIX system and commands. To use a man page, type the command "man" at the system prompt followed by the command for which you need information.
Syntax
man [options] command_name Common Options
-k keyword list command synopsis line for all keyword matches
-M path path to man pages
-a show all matching man pages (SVR4)
Backup using tar
Another program used to read and write files associated with an archive is tar.
Some of the available options are -A Append files to an archive -c Create a new archive -f Name of archive
-P Keep absolute paths of files -t List the files in an archive -v Verbose mode
-x Extract files from an archive
-z Compress/decompress files using gzip
gzip
This reduces the size of a file, thus freeing valuable disk space. For example, type
% ls -l science.txt
and note the size of the file using ls -l . Then to compress science.txt, type
% gzip science.txt
This will compress the file and place it in a file called science.txt.gz To see the change in size, type ls -l again.
To expand the file, use the gunzip command.
% gunzip science.txt.gz nslookup
Nslookup is a program to query Internet domain name servers. Nslookup has two modes: interactive and non-interactive. Interactive mode allows the user to query name servers for information about various hosts and domains or to print a list of hosts in a domain. Non-interactive mode is used to print just the name and requested information for a host or domain.
nslookup host
domain name, IP address, and alias information for the given host.
e.g., nslookup www.kent.edu gives related data for www.kent.edu Cut command.
cut command selects a list of columns or fields from one or more files.
Option -c is for columns and -f for fields. It is entered as cut options [files]
for example if a file named testfile contains this is firstline
this is secondline this is thirdline
ts ts
It is printing columns 1 and 4 of this file which contains t and s (part of this).
Options:
-c list cut the column positions identified in list.
-f list will cut the fields identified in list.
-s could be used with -f to suppress lines without delimiters.
Awk and Sed
Awk is a programming language that can be applied to data-manipulation and computing tasks on a UNIX operating system. Sed, a stream editor, acts like a filter by executing a group of editing instructions for a text file.
Examples:
df -t | awk 'BEGIN {tot=0} $2 == "total" {tot=tot+$1} END {print (tot*512)/1000000}'
Will give total space in your system in megabytes.
Here the output of command df -t is being passed into awk which is counting the field 1 after pattern "total" appears. Same way if you change $1 to $4 it will accumulate and display the addition of field 4
sed command launches a stream line editor which you can use at command line.
you can enter your sed commands in a file and then using -f option edit your text file. It works as
sed [options] files options:
-e 'instruction' Apply the editing instruction to the files.
-f script Apply the set of instructions from the editing script.
-n suppress default output.
for more information about sed, enter man sed at command line in your system.