0% found this document useful (0 votes)
8 views

Detailed Unit III File Management in Linux

Unit III covers file management in Linux, detailing the types of files (ordinary, directory, and device files) and the hierarchical structure of the UNIX file system. It explains commands for directory management, handling ordinary files, file content manipulation, compression, and attributes, as well as file ownership and permissions. Key commands include pwd, cd, ls, cp, rm, and chmod, among others.

Uploaded by

poojalandge1295
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Detailed Unit III File Management in Linux

Unit III covers file management in Linux, detailing the types of files (ordinary, directory, and device files) and the hierarchical structure of the UNIX file system. It explains commands for directory management, handling ordinary files, file content manipulation, compression, and attributes, as well as file ownership and permissions. Key commands include pwd, cd, ls, cp, rm, and chmod, among others.

Uploaded by

poojalandge1295
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Unit III: File Management in Linux

3.1 The File

Linux treats everything as a file, categorized into:

1. Ordinary File:

- Stores data, text, or program instructions.

- Example: .txt, .sh, .py files.

2. Directory File:

- Contains references to other files and directories.

- Acts like a folder in GUI-based systems.

3. Device File:

- Represents hardware devices (e.g., /dev/sda for hard drives).

File Naming:

- Can include alphabets, numbers, underscores, and periods.

- Avoid special characters (e.g., *, ?, &, !).

Parent-Child Relationship:

- The directory structure is hierarchical, with parent and child directories.

UNIX File System Tree:

- The root directory is represented by '/'.

- All files and directories stem from the root.


Home Directory:

- Each user has a unique home directory (e.g., /home/username).

Commands for Directory Management:

- pwd: Displays the current directory.

Example: pwd

- cd: Changes the current directory.

Example: cd /home/user

- mkdir: Creates a new directory.

Example: mkdir new_folder

- rmdir: Removes an empty directory.

Example: rmdir old_folder

- ls: Lists directory contents.

Example: ls -l

3.2 Absolute and Relative Pathnames

1. Absolute Pathnames:

- Specifies the complete path from the root directory.

- Example: /home/user/documents/file.txt

2. Relative Pathnames:

- Specifies the path relative to the current directory.


- Example: ./documents/file.txt or ../parent_folder/file.txt

3.3 Handling Ordinary Files

1. cat: Displays and creates files.

Example: cat file.txt

2. cp: Copies files.

Example: cp source.txt destination.txt

3. rm: Deletes files.

Example: rm old_file.txt

4. mv: Renames or moves files.

Example: mv old_name.txt new_name.txt

5. more: Paginates long output.

Example: more large_file.txt

3.4 The lp Subsystem and file Command

1. lp: Prints a file.

Example: lp document.txt

2. file: Displays the type of a file.

Example: file script.sh

3.5 File Content Manipulation

1. wc: Counts lines, words, and characters.


Example: wc file.txt

2. od: Displays data in octal.

Example: od -c file.txt

3. cmp: Compares two files.

Example: cmp file1.txt file2.txt

4. comm: Shows common lines between two files.

Example: comm file1.txt file2.txt

5. diff: Displays differences between files.

Example: diff old.txt new.txt

3.6 File Compression and Archiving

1. gzip and gunzip:

- Compress: gzip file.txt

- Decompress: gunzip file.txt.gz

2. tar: Creates and extracts archives.

- Create: tar -cvf archive.tar /path/to/files

- Extract: tar -xvf archive.tar

3. zip and unzip:

- Compress and archive: zip archive.zip file1 file2

- Extract: unzip archive.zip

3.7 File Attributes


1. ls -l: Lists file attributes such as permissions, owner, size, and modification date.

Example: ls -l

2. -d option: Lists directory attributes.

Example: ls -ld /path/to/directory

3.8 File Ownership and Permissions

1. chmod: Changes file permissions.

Example: chmod 755 file.txt

2. chown: Changes file ownership.

Example: sudo chown user:group file.txt

3. chgrp: Changes group ownership.

Example: sudo chgrp group file.txt

You might also like