When getting ready for the LPIC-1 101 exam you well find that objective 103.2 needs you to look at many command line utilities. In this blog we look at the tools cat and od.
LPIC-1 Objective 103.2
Many of you will be used to using the Linux command cat. This is a simple tool that can list the contents of a file, great for small files that are not likely to fill the screen but we can also display non-printing characters with cat -vet <filename>. The typical Linux line ending is a single $ representing a newline, whereas in Windows the line ending is ^M$ or return and new line. If you create scripts in Windows and upload them to Linux then you may find the scripts do not run. Using cat by itself will show no issues but digging deeper with cat -vet will reveal the problem. Additionally the command od can be used, and I like the option -a to display the ascii dump: od -a <filename>. In the ascii mode the output will show cr nl for Window’s line ending and just nl for Linux line endings. To resolve the problem there is a specific tool dos2unix; however all we really need is the standard Linux utility tr: tr -d ‘r’ < windows.sh > linux.sh. This will remove the additional and unwanted line endings.