LINUX
LINUX : CHAPTER 5 BROWSING THE FILE SYSTEM
INTRODUCTION
We have already learn in Linux, all info. is treated as file. For organizing data on the disk the O/S provides a file system.
The file system allows grouping of similar files together in a structure called directories.
The file system allows grouping of similar files together in a structure called directories.
FILE TYPES IN LINUX
A Linux file is a store house of information, which is simply a sequence of bytes. Since Everything is treated as a files in Linux, I/O devices connected to the system are also files in Linux. Their are three types of files ;
1. Ordinary files (Regular files)
All files created by a user comes under this category of files. These include all data files, Program files, object files. A user can make changes to such files.
2. Directory Files
For each directory their is a file by the same name as a directory, which contains information about the files under that directory.
3. Device files
These are special files typically associated with I/O devices such as printer, hard-disk, CD-ROM, etc.
TEXT AND BINARY FILES
A text file is a file that consist of text character without any embedded formatting information. It is also known as ASCII files. A Text file can be read by any editor or word processor.
A binary files is a program or data file that contains binary information in a machine readable form.
LINUX FILES IN HIERARCHY CONCEPT
Linux follows the tree Structure, file system is organised as hierarchy that start with the root directory.
The roots is represented by a forward slash (/). Under the root directory having the several system directories and the home directory.
Linux uses the forward slash (/) as a separator. But windows or Dos use back slash (\) as a separator.
The following section details some of the important directories in Linux. List of the standard system directories in Linux.
Their are several directories of the followings -
FUNDAMENTALS DIRECTORIES/FILES
1. /bin
This directory contains excitable programs files.
2. /dev
This directory contains the special device file. for example- The printer may be a file known as prn in this directory.
3. /etc
This directory contains all the system wide configuration information as text file.
4. /lib
This directory contains library files. It contain the reusable functions and routines from the programmer to use.
5. /tmp
This directory contains all the temporary files, which will be deleted from the system. This is simple to the
C:\ windows\temp
directory in the windows based operating System.
6. /mnt
This is directory where the storage devices are mounted. This directory contains the sub-directories such as floppy and CD-ROM. The these devices are mounted, this directory shows the contents of the floppy disk and CD-ROM like USB, Pen drive.
7. /usr
This Directory contains the home directories of the users. Their is one home directory for each user.
8. /kernel
This directory contains all the kernel specific code. It is responsible for resource allocation, security and low level hardware interface.
| Linux System directories |
FILE AND DIRECTORY NAME
- Up to 255 characters
- May as may not have extensions.
- Contains alphabets, digits, dot hyphens (-) and the underscore
( _ ) symbols anywhere. - Can have as many dots embedded in the name for example M.1.N.1 is a perfectly valid file name.
- Can contains uppercase and lowercase alphabets.
- Are case sensitive for e.g. "MINI" is not the same as "mini".
- Should not have blankspace.
PATH NAMES
Each directory in Linux is refereed by using its path name beginning from the root directory. These are two types of path name these are -
1. Absolute Path Name
An absolute path name indicate the complete path name of a directory starting from the root. The Absolute path name of the directory is
usr/mini/sales/north/delhi
2. Relative Path Name
It indicate the location of a directory relative to the current working directory.
FILES AND DIRECTORY COMMANDS
Linux commands are enter after the $ prompt appear on the monitor.
All Linux commands should be enter in lower case
1. HOME
To know your home directory, just type the following command "home".
2. PWD (Present working directory)
To find out which directory you are currently working in, type the following command "pwd"
3. MKDIR (Make Directory)
To create a new directory user the "mkdir" command following by the directory name if you want to create a directory name "sales" then type the following command
mkdir sales
To create a number of directories with one mkdir command, separate the directory name with space.
mkdir rahul sumit amit rakesh
mkdir sales/east
4. CD (Change Directory)
You can change the working directory using the "cd" command follow by the path name to which you want to move.
e.g To move to the sales directories type the following command
cd sales
5. RMDIR (Removing a Directory)
The command rmdir follow by the directory name which is to be remove is used for deleting a directory.
The directory to be deleted must be empty for this command to work.
To remove the exam directory type the following command
$ rmdir exam
6. LS (Listing directory content)
To list the names of the files and sub-directories of the current directory, LS command is used.
Its function is equivalent to the DIR in MS-DOS
e.g To listing the contents of current directory, type the following command .
$ ls
If the names of the files & directories under a specified directory are to be listed out, then we need to specify the directory name with the ls command as follow
$ ls north
List the different options of ls command and their uses are as ;
6. CAT (Creating files)
To create file type a command CAT at the shell prompt, followed by > character and the file name. Its its functions is very similar to the command in DOS. for example,
To create a file called January under the current directory enter the following command
$ cat > January
After you press enter key you will be prompted to enter the contents of the file.
Type the require data and press Ctrl+D to be terminated command line.
Transferring content from one file to another file. You can also pass the contents of a file to another file. for e.g
If You wish that the content of January should also be their in another file called Jan, enter the following command ;
$ cat January > Jan
If the file Jan is already exist it will get over-written. If you want to append the data to the file and not overwrite it, use >> as shown below ;
$ cat January >> Jan
7. CP (Copying files & Directories)
The command CP is used a copy the into another. MS-DOS equivalent for CP is the copy command like in dos, the CP command requires two arguments, source file name & a target file name. for example
To copy the file January into another file that is march, type the following command,
$ cp <source> <destination>
$ cp January march
8. RM (Removing files)
To delete or remove a file, the RM command is used. This is equivalent to the del command in DOS. for example,
To remove the file march type the following command ;
$ rm <file_name>
$ rm march
WILD CARDS ( *, ? )
The character *, ? functions in exactly the same way in Linux as they do in DOS.
The * character matches any no. of characters.
The ? character matches a single character. You may require to enter a no. of file name in the command line. If the file follow some common pattern you can make use of these wild cards.
For example
*.txt
???.txt
MOVING AND RENAME FILES & DIRECTORIES
A file or directory can be shifted from one directory to another by using the MV command.
The following command is moving the directory north to the after that mini directory.
mv north usr/mini/
Syntax for moving
mv <source> <destination>
Syntax for Renaming a directory
mv <old file name> <new file name>
VIEW FILE CONTENT
To list the contents of the file use the command CAT by the file name.
A CAT command is similar to the type command in the DOS.
for e.g
To list the contents of the January file type the following command -
cat <file-name>
cat January
The cat command can also display the contents of the more than one files by separating the different file name with the spaces.
Syntax
cat <file1> <file2> ...
for e.g
cat Jan Feb
JOINING TWO FILES (JOIN)
It merge two files record by record. This is unlike the cat command which appends one file after the another.
The join command operates on exactly two files and paste together those lines with a common key filed.
The files to be join must be sorted in the order of the key filed for matching to wok properly.
$ join Data1 Data2 ...
Output
1. Shoes Rs 650
2. Laces Rs 10
3. Shocks Rs 50
***
Your feedback is very important for us :)

Post a Comment
0 Comments