Determine the File Count in Unix Directory

May 21, 2008

To determine the number of files in the Unix directory, use the following command.

CODE:
  1. ls -l | grep -c "^-.*"

Writing Files in Unix

May 9, 2008

To write files in Unix, the syntax is

CODE:
  1. echo <text> > <filename>

Example

CODE:
  1. echo "This is my message." > myfile.txt

To add another line in the myfile.txt, use the following syntax.

CODE:
  1. echo "This is my second message." >>  myfile.txt

You may notice that double greater than sign (>>) is used instead of single greater than sign. This means that the message is written in append mode.

Let's open the myfile.txt by using the following command.

CODE:
  1. tail  myfile.txt

The content of the myfile.txt should have the following.

CODE:
  1. This is my message.
  2. This is my second message.