LinuxEra.com arrow Interview Questions arrow How can you view a file?
Wednesday, 08 September 2010
How can you view a file?
Courtesy: Navdeep Singh  
By executing `cat` command. e.g.: cat file.txt

The cat command reads each File parameter in sequence and writes it to standard output. If you do not specify a file name, the cat command reads from standard input. You can also specify a file name of - (dash) for standard input.

 

Examples:

Attention: Do not redirect output to one of the input files using the redirection symbol, > (caret).

1. To display a file at the workstation, enter:

cat notes

This command displays the data in the notes file. If the file is more than one less than the number of available display lines, some of the file scrolls off the screen. To list a file one page at a time, use the pg command.

2. To concatenate several files, enter:

cat section1.1 section1.2 section1.3 >section1

This command creates a file named section1 that is a copy of section1.1 followed by section1.2 and section1.3.

3. To suppress error messages about files that do not exist, enter:

cat  -q section2.1 section2.2 section2.3 >section2
If section2.1 does not exist, this command concatenates section2.2 and section2.3. The result is the same if you do not use the -q flag, except that the cat command displays the error message:

cat: cannot open section2.1

You may want to suppress this message with the -q flag when you use the cat command in shell procedures.

4. To append one file to the end of another, enter:

cat section1.4 > > section1

The > > (two carets) appends a copy of section1.4 to the end of section1. If you want to replace the file, use the > (caret).

5. To add text to the end of a file, enter:

cat >>notes
Get milk on the way home
Ctrl-D

This command adds Get milk on the way home to the end of the file called notes. The cat command does not prompt; it waits for you to enter text. Press the Ctrl-D key sequence to indicate you are finished.

6. To concatenate several files with text entered from the keyboard, enter:

cat section3.1 - section3.3 >section3

This command concatenates section3.1, text from the keyboard (indicated by the minus sign), and section3.3.

 
< Prev   Next >
Special Note

Linux Preloaded on Dell: At this point however, there are no specifics on the Linux preload, other than it will be available on laptop and desktop systems. From David Lord, a spokesman for Dell.

Rejoice penguins, Linux will be an option on future Dell desktop and mobile computers.

After several weeks of soliciting feedback from customers through its IdeaStorm Web site, pre-loading Linux became the first customer-requested option adopted by the company.

 
Your Views
What do you think about LinuxEra.com?