Assignment No: A-1 Date: Aim: Implementation of Create/ Rename/ Delete A File Using Unix/Linux Commands
Assignment No: A-1 Date: Aim: Implementation of Create/ Rename/ Delete A File Using Unix/Linux Commands
DATE:
Software Requirements: 64-BIT Fedora 17 or latest 64-BIT Update of Equivalent Open source OS, Latest Open source update of Eclipse Programming frame work, Editor like Vi,gedit or Nano Editor in Unix. Theory: All data in UNIX is organized into files. All files are organized into directories. These Directories are organized into a tree-like structure called the file system. A file system is a logical collection of files on a partition or disk. A partition is a container for information and can span an entire hard drive if desired. One file system per partition allows for the logical maintenance and management of differing file systems. Everything in Unix is considered to be a file, including physical devices such as DVD-ROMs, USB devices, floppy drives, and so forth. In UNIX there are three basic types of files: 1. Ordinary Files: An ordinary file is a file on the system that contains data, text, or program instructions. In this tutorial, you look at working with ordinary files. 2. Directories: Directories store both special and ordinary files. For users familiar with Windows or Mac OS, UNIX directories are equivalent to folders. 3. Special Files: Some special files provide access to hardware such as hard drives, CD-ROM drives, modems, and Ethernet adapters. Other special files are similar to aliases or shortcuts and enable you to access a single file using different names. A UNIX file system is a collection of files and directories that has the following properties: It has a root directory (/) that contains other files and directories. Each file or directory is uniquely identified by its name, the directory in which it resides, and a unique identifier, typically called an inode. By convention, the root directory has an inode number of 2 and the lost+found directory has an inode number of 3. Inode numbers 0 and 1 are not used. File inode numbers can be seen by specifying the -i option to ls command. It is self contained. There are no dependencies between one filesystem and any other.
cp file1 file2 file filename find filename dir head filename less filename ls dirname more filename mv file1 file2 pwd rm filename tail filename touch filename whereis filename which filename
Copies one file/directory to specified location. Identifies the file type (binary, text, etc). Finds a file/directory. Shows the beginning of a file. Browses through a file from end or beginning. Shows the contents of the directory specified. Browses through a file from beginning to end. Moves the location of or renames a file/directory. Shows the current directory the user is in. Removes a file. Shows the end of a file. Creates a blank file or modifies an existing file.s attributes. Shows the location of a file. Shows the location of a file if it is in your PATH.
2. File Handling Operations: 2.1 Listing Files: To list the files and directories stored in the current directory. Use the following command: [scoe]$ ls
2.2 Creating Files:
You can use vi editor to create ordinary files on any Unix system. You simply need to give following command: [scoe]$ vi filename Above command would open a file with the given filename. You would need to press key i to come into edit mode. Once you are in edit mode you can start writing your content in the file as below: Hello World! Once you are done, do the following steps: Press key esc to come out of edit mode. Press two keys Shift + ZZ together to come out of the file completely or ESC + : WQ
Owner permissions: The owner's permissions determine what actions the owner of the file can perform on the file. Group permissions: The group's permissions determine what actions a user, who is a member of the group that a file belongs to, can perform on the file. Other (world) permissions: The permissions for others indicate what action all other users can perform on the file. Using ls -l command it displays various information related to file permission. To change file or directory permissions, you use the chmod (change mode) command. There are two ways to use chmod: symbolic mode and absolute mode Symbolic mode is as Chmod operator + Description Adds the designated permission(s) to a file or directory. Removes the designated permission(s) from a file or Directory. = Sets the designated permission(s). The second way to modify permissions with the chmod command is to use a number to specify each set of permissions for the file. Each permission is assigned a value, as the following table shows, and the total of each set of permissions provides a number for that set. Number 0 1 2 3 4 5 6 7 Octal Permission Representation No permission Execute permission Write permission Execute and write permission: 1 (execute) + 2 (write) = 3 Read permission Read and execute permission: 4 (read) + 1 (execute) = 5 Read and write permission: 4 (read) + 2 (write) = 6 All permissions: 4 (read) + 2 (write) + 1 (execute) = 7 Ref ----x -w-wx r-r-x rwrwx
[scoe]$ chmod 777 filename.sh [scoe]$ a./filename.sh 4. umask: assign default permissions
You can use the built-in shell command umask to influence the default permissions given to the files you create. Every process has its own umask attribute; the shells built-in umask command sets the shells own umask, which is then inherited by commands that you run. The umask is specified as a three-digit octal value that represents the permissions to take away. When a file is created, its permissions are set to whatever the creating program requests minus whatever the umask forbids. Thus, the individual digits of the umask allow the permissions shown in Table.
Permission encoding for umask Octal 0 1 2 3 Binary 000 001 010 011 Perms rwx rwr-x r-Octal 4 5 6 7 Binary 100 101 110 111 Perms -wx -w--x ---
For example, umask 027 allows all permissions for the owner but forbids write permission to the group and allows no permissions for anyone else. The default umask value is often 022, which denies write permission to the group and world but allows read permission. You cannot force users to have a particular umask value because they can always reset it to whatever they want. However, you can put a suitable default in the sample.profile file that you give to new users. Algorithm: Write algorithm +flowchart on blank page as per your program.
Conclusion: Hence we have implemented file handling operations using Unix Commands.