In this article you will learn about basics of files in Unix and what are files in Unix along with associated commands like od command and file command.
Basics of Files in Unix
A file is a sequence of bytes (1 byte = 8 bits). The meaning of the bytes in a file only depends on the program that interprets the file.
The command od (octal dump) prints a visible representation of all the bytes of a file as shown below. The -c option interprets bytes as characters. The -b option displays the octal values of the bytes in the file.
Whenever the RETURN key is pressed in the input, it is placed as an ASCII newline character (\n). This is the most common special character. Other special characters are backspace (\b), tab (\t), carriage return (\r), etc. Different programs treat the data in a file in different ways.
When the user presses RETURN key, kernel echoes a carriage return and a newline, but stores only the newline in the input. This sequence of carriage return and linefeed (newline) is popularly known as CRLF.
Unix does not store any special character for detecting the end of a file. Unix keeps track of the size (as bytes) of a file. So, a program stops processing the file when there are no more bytes to process.
What’s in a File?
The format of a file is determined by the programs that use it. Since file types are not determined by the file system, the kernel can’t tell us the type of a file, it doesn’t know it. The file command makes a guess at best about the given file/directory as shown below:
To determine the type of file, the file command reads the first few bytes of a file and looks for clues about the file type. For example, an executable program is marked by a binary “magic number” at its beginning. The octal value 410 marks a pure executable program as shown below:
The advantage of lack of file formats is, programmers need not worry about the file types, and all the standard programs will work on any file. The drawback is some sort and search programs like grep expect text as input. It can’t examine binary files correctly.
For more information you can visit the following links:
Suryateja Pericherla, at present is a Research Scholar (full-time Ph.D.) in the Dept. of Computer Science & Systems Engineering at Andhra University, Visakhapatnam. Previously worked as an Associate Professor in the Dept. of CSE at Vishnu Institute of Technology, India.
He has 11+ years of teaching experience and is an individual researcher whose research interests are Cloud Computing, Internet of Things, Computer Security, Network Security and Blockchain.
He is a member of professional societies like IEEE, ACM, CSI and ISCA. He published several research papers which are indexed by SCIE, WoS, Scopus, Springer and others.
Nice Information