Section 5:41. Previewing Text Files in HDFS

The “cat” and “tail” commands in HDFS are used to view the contents of a file stored in the Hadoop Distributed File System.

The “cat” command allows you to display the entire contents of a file in the terminal. For example:

hadoop fs -cat /user/data/file.txt

This command will display the contents of the file “/user/data/file.txt” in the terminal.

The “tail” command is similar to “cat”, but it only displays the last few lines of a file. This is useful when you want to view the latest entries in a log file or the end of a large file. By default, “tail” displays the last 10 lines of a file, but you can specify the number of lines to display using the “-n” option. For example:

hadoop fs -tail -n 5 /user/data/file.txt

This command will display the last 5 lines of the file “/user/data/file.txt”.

Both “cat” and “tail” are important tools for working with files stored in HDFS, as they allow you to quickly inspect the contents of a file without having to download it to your local file system.

  • -tail can be used to preview last 1 KB of the file
  • -cat can be used to print the whole contents of the file on the screen. Be careful while using -cat as it will take a while for even medium sized files.
  • If you want to get first few lines from file you can redirect output of hadoop fs -cat to Linux more command

Share this post