• VMware

    Learn about VMware virtualization for its products like vsphere ESX and ESXi, vCenter Server, VMware View, VMware P2V and many more

  • Linux

    Step by step configuration tutorials for many of the Linux services like DNS, DHCP, FTP, Samba4 etc including many tips and tricks in Red Hat Linux.

  • Database

    Learn installation and configuration of databases like Oracle, My SQL, Postgresql, etc including many other related tutorials in Linux.

  • Life always offers you a second chance ... Its called tomorrow !!!

    Thursday, September 12, 2013

    7 Commands to read or view the contents of a file using CLI in Linux

    Let me show you 7 commands which can be used to view the contents of its file where each command has its own advantage and you can use them as per your requirement.

    1. less command

    This is most used and opted command for viewing the contents of any file as you get the option to scroll up and down the file as per your convenience.  So in case the file content you are trying to read is huge you can use this command

    Syntax
    # less (filename)# less http.conf (Use up and down arrow to scroll respectively)

    2. more command

    This command can also be used to views files with huge contents but things are a bit complicated as compared to less command. To scroll up and down the page you need to memorize specific buttons.

    Syntax
    # more (filename)# more http.conf

    SPACE : To scroll down
    d : To scroll to the very next line
    b : To scroll back to the previous line

    3. tail command

    This command if used without any additional switches displays the last 10 lines of the file you are trying to view. This command can be helpful in case you are specific to view particular content of any file.

    Syntax
    # tail (filename)# tail http.conf
    # tail -20 http.conf
    This will list last 20 lines of http.conf

    4. head command

    This command is similar to tail command with one difference that it shows top 10 lines of any file if used without any switches.
    Synatx
    # head (filename)# head http.conf
    # head -20 http.conf
    This will list first 20 lines of http.conf

    5. vi or vim command

    This command is basically used to edit files but again you can't ignore the fact can it can also be used to view files and close it without editing.

    Synatx
    # vi (filename)# vi http.conf Use up and down arrow to scroll up and down. For more information on extra switches use man command
    # man vi

    6. pr command

    This command can also be used to view the contents of any file but its not much user friendly. Alternatively you can utilize this using pipe and less command.

    Syntax
    # pr (filename) | less# pr http.conf | less

    7. cat command

    This command can also be used to read a file but it has a demerit, you won't get any option to scroll up and down if the file content is very huge. It can be useful if the file you are trying to view has less contents or else you might have to use less command along with pipe as shown above.

    Syntax
    # cat (filename)# cat http.conf | less (In case the file content is more)

    Related Articles

    Follow the below links for more tutorials

    How to secure Apache web server in Linux using password (.htaccess)
    How to register Red Hat Linux with RHN (Red Hat Network )
    Red hat Enterprise Linux 5.5 Installation Guide (Screenshots)
    15 tips to enhance security of your Linux machine
    Why is Linux more secure than windows and any other OS
    What is the difference between "su" and "su -" in Linux?
    What is swappiness and how do we change its value?
    How to log iptables messages in different log file
    What are the s and k scripts in the etc rcx.d directories
    How to check all the currently running services in Linux
    How to auto start service after reboot in Linux
    What is virtual memory, paging and swap space?

    0 comments:

    Post a Comment