View Single Post
Old 25. May 2009, 03:55 PM   #7 (permalink)
debtboy
Senior Member
 
debtboy's Avatar
 
Join Date: May 2009
Location: ~/
Posts: 128
Default Viewing a file's contents

Hi everyone,

Now that your starting to move around the filesystem with cd,
list files with ls, you may want to view the contents of some of these files.
I generally use more but there are some who prefer less,
either way you can view the contents of selected files which is very handy!!

The key word here is view, so you can NOT change the contents of
any of these files as you could with an editor like vi or emacs.

First lets create a text file named my_text.txt
The .txt extension is meaningless in Linux, but I'm sure
long time Windows user's feel better with it there.

Try this command:
echo "this is a test file" > my_text.txt




Now lets do a listing ls -l and see the file we just created.



Notice that default permissions were issued to the file automatically.

Now lets look inside the file we created.
more my_text.txt



The contents of the file are dumped right into the console.
If you looking at a file that's larger than the console window
you can navigate the same as you would with man pages (Linux manual)
enter key to scroll through line by line
spacebar to scroll page by page
q to quit out of viewing

Now you can change directories cd, list files ls
and view the contents of those files with more.
Start looking around the filesystem and start view the contents of files.
NOTE:
Don't try to view binary files which are normally located in /bin or /sbin directories.

more is especially useful for viewing network config files located in /etc
Try this to view the contents of your resolv.conf file which should call out
the DNS nameservers. (ref: other post about openDNS)
more /etc/resolv.conf

more is used to view files, to make changes you will need permissions and an editor.
debtboy is offline   Reply With Quote