7 GNU/Linux Basic File Operations

Mr. Hardik Joshi

epgp books

 

Introduction

 

In the previous module we had understood the concept of Linux file system. The Linux file system is inverted tree structure where the root “/” directory is the top most directory. The file system is a data structure to store the meta-data of files. Linux supports various file systems. The following table lists few file systems that are supported by Linux:

 

 

Linux files are classified into the following three general categories depending on the content and usage of file, the files/directories are identified by a single character when it gets listed using “ls” command:

  • Regular files (-)
  • Directory files (d)
  • Device files or special files.
    • Block files (b)
    • Character device files (c)
    • Named Pipe file (p)
    • Symbolic Link (l)
    • Socket files (s)

 

A regular file is a randomly addressable sequence of bytes. Most of the files, like data files, source program files, files containing Linux commands or any text file, are called regular files. These files can be created, changed or deleted by the user whenever he or she needs. These types of files are also called ordinary files. Linux treats everything as a file. In simple terms, directories are files that organize other files and directories. A device file is a point of interface to one of the computer’s hardware devices. Thus a device file acts as a communication channel between two or more cooperating programs. The computer’s random access memory, disk drives, I/O ports and other such devices are accessed through these device files. All such devices will have at least one special file associated with it.

 

File Operations

 

Before discussing various commands for file operations, let us classify the types of commands. All commands can be classified into two categories, external command and internal commands.

 

External Commands are commands with an independent existence in the form of a separate file. For example, programs for the commands such as cat and Is, exist independently in a directory called the /bin directory. When such commands are given, the shell reaches these command files with the help of a system variable called the PATH variable and executes them. Most of the Linix commands are external commands.

 

Internal Commands are commands that does not have an independent existence. For example, the echo command is an internal command as its routine will be a part of the shell’s routine. In other words the echo command is built into the shell. As such, internal commands are also called the built-in commands. cd and mkdir, are two examples of internal commands.

 

The following table shows operations (commands) that can be performed on files. The commands listed in following table can be executed on the “$” prompt of command line interface. The demonstration of these commands is shown in figure 1.

Figure 1: Demonstration of ls command

 

Few directory related commands are listed in following table, the output of these commands is shown in figure 2.

you can view video on GNU/Linux Basic File Operations

References:

 

[1] Jain, 100 Shell Programs in Unix. Pinnacle Technology, 2009.

[2] Garrels, Bash Guide for Beginners (Second Edition). Fultus Corporation, 2010.

[3] Isrd, Basics Of Os Unix And Shell Programming. Tata McGraw-Hill Education, 2006.

[4] Seebach, Beginning Portable Shell Scripting: From Novice to Professional. Apress, 2008.

[5] Foster-Johnson, J. C.Welch, and M. Anderson, Beginning Shell Scripting. John Wiley & Sons, 2007.

[6] Robbins and N. H. F. Beebe, Classic Shell Scripting: Hidden Commands that Unlock the Power of Unix. O’Reilly Media, Inc., 2005.

[7] Peters, Expert Shell Scripting. Apress, 2009.

[8] G. Venkateshmurthy, Introduction to Unix and Shell Programming. Pearson Education India, 2005.

[9] Festari, Learning Shell Scripting with Zsh. Packt Publishing Ltd, 2014.

[10] Newham, Learning the bash Shell: Unix Shell Programming. O’Reilly Media, Inc.,2005.

[11] Rosenblatt and A. Robbins, Learning the Korn Shell. O’Reilly Media, Inc., 2002.

[12] E. S. Jr, Linux Command Line. NO STARCH Press, 2012.

[13] Blum and C. Bresnahan, Linux Command Line and Shell Scripting Bible. John Wiley & Sons, 2015.

[14] Blum and C. Bresnahan, Linux Command Line and Shell Scripting Bible. John Wiley & Sons, 2015.

[15] Lakshman, Linux Shell Scripting Cookbook. Packt Publishing Ltd, 2011.

[16] Tushar, Linux Shell Scripting Cookbook. Packt Publishing Ltd, 2013.

[17] O. Burtch, Linux Shell Scripting with Bash. Sams, 2004.

[18] K. Michael, Mastering Unix Shell Scripting: Bash, Bourne, and Korn Shell Scripting for Programmers, System Administrators, and UNIX Gurus. John Wiley & Sons, 2011.

[19] Johnson, Pro Bash Programming: Scripting the Linux Shell. Apress, 2009.

[20] Veeraraghavan, Sams Teach Yourself Shell Programming in 24 Hours. Sams Publishing, 2002.[21] Parker, Shell Scripting: Expert Recipes for Linux, Bash and more. John Wiley & Sons, 2011.

[22] F. A. Johnson, Shell Scripting Recipes: A Problem Solution Approach. Dreamtech Press, 2007.

[23] Verma, Unix and Shell Programming. Laxmi Publications, 2006.

[24] A. Forouzan and R. F. Gilberg, UNIX and Shell Programming: A Textbook. Brooks/Cole-Thomson Learning, 2003.

[25] P. Kanetkar, Unix Shell Programming. BPB Publications, 2002.

[26] Sanchez-Clark, Unix Shell Scripting Interview Questions, Answers, and Explanations: Unix Shell Certification Review. Equity Press, 2007.

[27] Taylor, Wicked Cool Shell Scripts: 101 Scripts for Linux, Mac OS X, and Unix Systems. No Starch Press, 2004.