Module I
Module I
directory path.
Example: pwd
cd [directory] : Change Directory - Moves to a specified
directory.
Example: cd /home/user/Documents
ls : List Directory Contents - Lists files and directories.
Example: ls -l
Files and Directories
In Linux, everything is treated as a file, including directories.
touch [file_name] : Creates an empty file.
Example: touch newfile.txt
mkdir [directory_name] : Creates a new directory.
Example: mkdir new_folder
cp [source] [destination] : Copies files or directories.
Example: cp file1.txt /home/user/
mv [source] [destination] : Moves or renames files or directories.
Example: mv old_name.txt new_name.txt
rm [file_name] : Removes files or directories.
Example: rm file1.txt
Manual Pages
Manual pages (man pages) provide detailed documentation on Linux
commands.
man [command] : Displays the manual page for a specific command.
Example: man ls
File Manipulation
Manipulating files includes operations like creating, editing, and
deleting files.
cat [file_name]: Concatenates and displays file content.
regular expressions.
grep [pattern] [file_name]: Searches for
a pattern.
Example: grep '^Hello' file1.txt (Matches lines starting with
"Hello")
Regular Expressions: Used for pattern
matching, e.g., ^, $, *, ..
Example: (Matches lines containing "a"
grep 'a.*b' file1.txt
followed by any characters and "b")
Piping and Redirection
Pipes and redirection allow combining
commands and controlling input/output.
Piping (|): Passes the output of one
command as input to another.
Example: cat file1.txt | grep "error"
Redirection (> and >>): Redirects output to
a file.
Example: (Writes output to a file)
ls > file_list.txt
Example: echo "New line" >> file1.txt (Appends to a file)
Process Management
Linux allows you to view and manage
running processes.
ps aux: Lists all running processes.
Process ID (PID).
Example: kill 1234
User Management
Linux supports multiple users with different
permissions.
adduser [username] : Creates a new user.
Example: adduser rakhi
passwd [username] : Changes a user’s password.
Example: passwd rakhi
usermod -aG [groupname] [username]: Adds a
user to a group.
Example: usermod -aG sudo rakhi
File Security
Security features protect files from
unauthorized access.
Permissions: Control read, write, and
execute access.
Example: (Owner can read and
chmod 600 file1.txt
write; others have no access)
Encryption: Tools like gpg encrypt files.
Example: gpg -c file1.txt (Encrypts the file)
Shell Scripting
Shell scripts automate tasks by running multiple
commands.
Shebang (#!/bin/bash): Indicates the script interpreter.
Example:
bash
Copy code
#!/bin/bash
echo "Hello, World!"
Executing Scripts: Make the script executable with
chmod +x script.sh and run it with ./script.sh.
Security in Operating Systems
Security in Linux involves implementing
measures to protect the system.
Firewall: Configure with iptables or ufw.