0% found this document useful (0 votes)
3 views11 pages

Untitled Document

The document provides an overview of the Unix file system, detailing its structure, types of files, and essential commands for navigation, file operations, and text processing. It also covers user management in Unix, including user creation, modification, permissions, and group management. Key commands for managing users and files are summarized for quick reference.

Uploaded by

sohamkadam5505
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views11 pages

Untitled Document

The document provides an overview of the Unix file system, detailing its structure, types of files, and essential commands for navigation, file operations, and text processing. It also covers user management in Unix, including user creation, modification, permissions, and group management. Key commands for managing users and files are summarized for quick reference.

Uploaded by

sohamkadam5505
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Unix File System – Simple Explanation for Oral Exam

The Unix file system is a tree-like structure that starts from the root directory (/). It
organizes files and directories, allowing easy navigation and access control. Permissions
help secure files by defining access for the owner, group, and others.

Types of Unix Files

1.​ Regular Files – Store data (text, programs, images, etc.).


2.​ Directory Files – Contain other files and directories.
3.​ Character Device Files – Handle data as a stream (e.g., keyboard, terminal).
4.​ Block Device Files – Handle data in blocks (e.g., hard drives, USBs).
5.​ Symbolic Links – Act as shortcuts to files or directories.
6.​ Pipes – Allow one process to send data to another.
7.​ Socket Files – Enable communication between processes over a network or locally.
8.​ FIFO Files – Named pipes for synchronized process communication.

Steps to Use Unix Commands

Step 1: Navigation and Directory Management


pwd → Show current directory.​
sh​
CopyEdit​
pwd

1.​

ls → List files and directories.​


sh​
CopyEdit​
ls

2.​

mkdir → Create a new directory.​


sh​
CopyEdit​
mkdir SEIT

3.​

cd → Change directory.​
sh​
CopyEdit​
cd SEIT

4.​

rmdir → Remove an empty directory.​


sh​
CopyEdit​
rmdir SEIT

5.​

rm → Delete a file or directory (-r for recursive deletion).​


sh​
CopyEdit​
rm test.txt
rm -r directory_name

6.​

Step 2: File Operations


Create a file using cat.​
sh​
CopyEdit​
cat > test.txt

1.​ Type text, then press Ctrl + D to save.

View file content using cat.​


sh​
CopyEdit​
cat test.txt

2.​

Copy a file using cp.​


sh​
CopyEdit​
cp source.txt destination.txt

3.​

Move/Rename a file using mv.​


sh​
CopyEdit​
mv test.txt mytest.txt
4.​

Change file permissions using chmod.​


sh​
CopyEdit​
chmod 755 mytest.txt
chmod u+x script.sh

5.​

Count lines, words, and characters using wc.​


sh​
CopyEdit​
wc mytest.txt
wc -l mytest.txt # Line count only

6.​

Split large files using split.​


sh​
CopyEdit​
split -l 1000 largefile.txt part_

7.​

Step 3: Text Processing & Piping


Print text using echo.​
sh​
CopyEdit​
echo "Hello, world!"

1.​

Convert lowercase to uppercase using tr.​


sh​
CopyEdit​
echo "hello" | tr 'a-z' 'A-Z'

2.​

Use Piping (|) and Redirection (>, >>).​


sh​
CopyEdit​
ls | grep "text" # Find "text" in file list
echo "Hello" > hello.txt # Save output to file
cat file.txt >> append.txt # Append content

3.​

Search text in files using grep.​


sh​
CopyEdit​
grep "hello" file.txt
grep -i "hello" file.txt # Case-insensitive search

4.​

Sort file content using sort.​


sh​
CopyEdit​
sort myfile.txt

5.​

View first or last lines using head or tail.​


sh​
CopyEdit​
head -n 5 myfile.txt # First 5 lines
tail -n 5 file.txt # Last 5 lines

6.​

Compare two files using diff.​


sh​
CopyEdit​
diff file1.txt file2.txt

7.​

Compare sorted files using comm.​


sh​
CopyEdit​
comm file1.txt file2.txt

8.​

View files page-by-page using more.​


sh​
CopyEdit​
more file.txt

9.​
Summary

●​ Navigation: pwd, ls, cd, mkdir, rm


●​ File handling: cat, cp, mv, chmod, wc, split
●​ Processing: echo, tr, grep, sort, head, tail
●​ Comparison: diff, comm
●​ Viewing: more

These commands help manage files efficiently in Unix/Linux. 🚀


4o

O
Search
Reason

User Management in Unix – Simple Explanation for Oral Exam

Unix allows multiple users to use the system while keeping everything secure. User
management helps system administrators:​
✔ Create, modify, and delete users.​
✔ Manage groups and permissions.​
✔ Set password policies and control access.

Key Concepts

1.​ User Accounts – Every user has a username and a User ID (UID).
2.​ Groups – A collection of users with shared permissions.
3.​ Superuser (Root) – The admin user with full access.
4.​ File Ownership & Permissions – Decide who can read, write, or execute files.

Important Commands
Command Purpose

who, whoami Show logged-in users and current user.


su, sudo Switch users and run commands as another
user.

useradd, passwd, Create, modify, and manage users.


usermod

groupadd, groupdel, Manage user groups.


gpasswd

chown, chgrp Change file ownership and group permissions.

chage Set password expiry.

logout, exit Log out of a session.

Steps to Manage Users in Unix

Step 1: Check the Current User

●​ Command: whoami
●​ Purpose: Shows the currently logged-in user.
●​ Command: who
●​ Purpose: Lists all users currently logged in.

Step 2: Create a New User


Command:​
sh​
CopyEdit​
sudo useradd -m testuser

●​
○​ sudo → Runs as an administrator.
○​ useradd → Creates a new user.
○​ -m → Creates a home directory.

Verify User Creation:​


sh​
CopyEdit​
cat /etc/passwd | grep testuser

●​ Expected Output: Shows user details like home directory and shell.

Set Password:​
sh​
CopyEdit​
sudo passwd testuser

●​ Expected Output: Prompts to enter and confirm a password.

Step 3: Switch to the New User


Command:​
sh​
CopyEdit​
su - testuser

●​
○​ Switches to testuser.

Verify:​
sh​
CopyEdit​
whoami

●​ Expected Output: testuser

Logout from new user:​


sh​
CopyEdit​
logout

●​

Step 4: Modify User Permissions


Command:​
sh​
CopyEdit​
sudo usermod -aG sudo testuser

●​
○​ Adds testuser to the sudo (admin) group.

Verify Group Membership:​


sh​
CopyEdit​
groups testuser

●​ Expected Output: testuser sudo


Step 5: Manage Groups
Create a Group:​
sh​
CopyEdit​
sudo groupadd testgroup

●​

Verify Group Creation:​


sh​
CopyEdit​
cat /etc/group | grep testgroup

●​ Expected Output: Shows group details.

Add User to Group:​


sh​
CopyEdit​
sudo usermod -aG testgroup testuser

●​

Verify:​
sh​
CopyEdit​
groups testuser

●​ Expected Output: testuser sudo testgroup

Delete a Group:​
sh​
CopyEdit​
sudo groupdel testgroup

●​

Verify:​
sh​
CopyEdit​
cat /etc/group | grep testgroup

●​ No output = Group deleted.

Step 6: Change File Ownership


Create a Test File:​
sh​
CopyEdit​
touch testfile.txt

●​

Check Ownership:​
sh​
CopyEdit​
ls -l testfile.txt

●​

Change Owner to testuser:​


sh​
CopyEdit​
sudo chown testuser testfile.txt

●​

Verify:​
sh​
CopyEdit​
ls -l testfile.txt

●​ Expected Output: Shows testuser as the new owner.

Step 7: Modify Password Policy


Check Password Expiry Details:​
sh​
CopyEdit​
sudo chage -l testuser

●​

Set Password Expiry to 30 Days:​


sh​
CopyEdit​
sudo chage -M 30 testuser

●​

Verify:​
sh​
CopyEdit​
sudo chage -l testuser

●​ Expected Output: Password expires: (new date)

Step 8: Delete User


Delete User (Keep Home Directory):​
sh​
CopyEdit​
sudo userdel testuser

●​

Verify User Deletion:​


sh​
CopyEdit​
cat /etc/passwd | grep testuser

●​ No output = User deleted.

Delete User (Remove Home Directory):​


sh​
CopyEdit​
sudo userdel -r testuser

●​

Step 9: Logout & Exit


Command:​
sh​
CopyEdit​
logout

●​
●​ Purpose: Exit the current session.

Summary of Commands
Action Command

Check current user whoami, who

Create a user sudo useradd -m testuser


Set password sudo passwd testuser

Switch user su - testuser

Modify user permissions sudo usermod -aG sudo


testuser

Create a group sudo groupadd testgroup

Add user to group sudo usermod -aG testgroup


testuser

Delete a group sudo groupdel testgroup

Change file ownership sudo chown testuser


testfile.txt

Check password expiry sudo chage -l testuser

Set password expiry sudo chage -M 30 testuser

Delete a user sudo userdel -r testuser

Logout logout, exit

You might also like