Welcome To LINUX World
Welcome To LINUX World
History of OS
• Operating systems were developed in the 1950s. General Motors' research lab
implemented the first OS in the early 1950s for their IBM 701.
• In the mid-1960s, operating systems started using disks. In the late 1960s, the UNIX
operating system was developed.
• The first OS developed by Microsoft was MS-DOS, released in 1981.
• In 1985, the first operating system with a GUI (Graphical User Interface) was
released.
• We commonly use the Windows operating system on our computers and laptops.
• Windows OS is recommended for personal use.
• Windows is a single-user-based operating system.
• In real-time environments, we often use the Linux OS to run our applications.
Advantages of LINUX
• Linux is free and open source.
• Linux is a multi-user-based operating system.
• Linux is a highly secure operating system.
1. Visit AWS: Go to the AWS website and click on "Create an AWS Account."
2. Sign Up: Provide your email address and choose a password. Follow the prompts to
complete the registration, including entering payment information. AWS offers a free
tier for new users for the first 12 months.
3. Verify Account: AWS will send a verification email. Verify your account to activate
it.
1. Login: Go to the AWS Management Console and sign in with your AWS credentials.
2. Navigate to EC2: In the search bar, type "EC2" and select it from the dropdown. This
will take you to the EC2 Dashboard.
With these steps and explanations, you should be able to set up and understand the basics of a
Linux environment on AWS EC2, leveraging the powerful features of EC2 to meet your
computing needs.
Summary
This guide has covered the essential aspects of setting up a Linux environment on AWS EC2,
including:
1. $ pwd
o Description: Print Working Directory.
o Usage: pwd
o Example: Displays the current directory path.
2. $ ls
o Description: List directory contents.
o Usage: ls [options] [directory]
o Options:
▪ -a: Include hidden files.
▪ -l: Long listing format.
▪ -h: Human-readable sizes.
▪ -r: Reverse order.
▪ -t: Sort by modification time.
▪ -R: Recursively list subdirectories.
o Examples:
▪ ls -l: Long listing format.
▪ ls -r: List in reverse order.
▪ ls -t: Sort by modification time.
▪ ls -lt: Long listing, sorted by modification time.
▪ ls -rt: Reverse order, sorted by modification time.
▪ ls -a: Include hidden files.
▪ ls -li: List with inode number.
▪ ls -R: Recursively list subdirectories.
▪ ls -lR: Long listing format, recursively.
3. $ cd
o Description: Change Directory.
o Usage: cd [directory]
o Example: cd /var/log
4. $ cp
o Description: Copy files and directories.
o Usage: cp [options] source destination
o Options:
▪ -r: Recursive copy (for directories).
o Example: cp file1.txt /tmp
5. $ mv
o Description: Move/rename files and directories.
o Usage: mv [options] source destination
o Example: mv oldname.txt newname.txt
6. $ rm
o Description: Remove files or directories.
o Usage: rm [options] file
o Options:
▪ -r: Recursive (for directories).
▪ -f: Force deletion.
o Example: rm -rf /tmp/testdir
7. $ mkdir
o Description: Create directories.
o Usage: mkdir [options] directory
o Options:
▪ -p: Create parent directories as needed.
o Example: mkdir -p /tmp/testdir
8. $ rmdir
o Description: Remove empty directories.
o Usage: rmdir directory
o Example: rmdir /tmp/testdir
9. $ touch
o Description: Create empty files or update the timestamp of existing files.
o Usage: touch filename
o Example: touch newfile.txt
10. $ cat
o Description: Concatenate and display files.
o Usage: cat [options] file
o Example: cat /etc/passwd
11. $ tac
o Description: Concatenate and display files in reverse.
o Usage: tac file
o Example: tac /etc/passwd
12. $ rev
o Description: Reverse lines characterwise.
o Usage: rev file
o Example: rev /etc/passwd
13. $ more
o Description: View file contents one page at a time.
o Usage: more filename
o Example: more /etc/passwd
14. $ less
o Description: View file contents with backward/forward navigation.
o Usage: less filename
o Example: less /var/log/syslog
15. $ head
o Description: Display the first lines of a file.
o Usage: head [options] file
o Options:
▪ -n N: Show the first N lines.
o Example: head -n 10 /var/log/syslog
16. $ tail
o Description: Display the last lines of a file.
o Usage: tail [options] file
o Options:
▪ -n N: Show the last N lines.
▪ -f: Follow the file (useful for logs).
o Example: tail -f /var/log/syslog
17. $ chmod
o Description: Change file modes or Access Control Lists (ACLs).
o Usage: chmod [options] mode file
o Options:
▪ u: User.
▪ g: Group.
▪ o: Others.
o Example: chmod 755
18. $ chown
o Description: Change file owner and group.
o Usage: chown [options] owner[:group] file
o Example: chown root:root /var/www/html
19. $ df
o Description: Report file system disk space usage.
o Usage: df [options]
o Options:
▪ -h: Human-readable format.
o Example: df -h
20. $ du
o Description: Estimate file space usage.
o Usage: du [options] [directory]
o Options:
▪ -h: Human-readable format.
▪ -s: Summary of directory usage.
o Example: du -sh /var/log
21. $ find
o Description: Search for files in a directory hierarchy.
o Usage: find [path] [expression]
o Example: find /var -name "*.log"
22. $ grep
o Description: Print lines matching a pattern.
o Usage: grep [options] pattern [file]
o Options:
▪ -i:Ignore case.
▪ -R: Recursive search.
▪ -c: Count the number of matches.
▪ -n: Show line numbers with output lines.
▪ -l: List filenames containing the pattern.
▪ -h: Suppress filename in output.
o Examples:
▪ grep -i "error" /var/log/syslog: Ignore case.
▪ grep -R "error" /var/log: Recursive search.
▪ grep -c "error" /var/log/syslog: Count matches.
▪ grep -n "error" /var/log/syslog: Show line numbers.
▪ grep -l "error" /var/log/*: List filenames containing the pattern.
▪ grep -h "error" /var/log/syslog: Suppress filename in output.
23. $ diff
o Description: Compare files line by line.
o Usage: diff [options] file1 file2
o Example: diff file1.txt file2.txt
24. $ ps
o Description: Report a snapshot of current processes.
o Usage: ps [options]
o Options:
▪ -e: All processes.
▪ -f: Full format listing.
o Example: ps -ef
25. $ top
o Description: Display tasks and system resource usage.
o Usage: top
o Example: Shows real-time system processes and resource usage.
26. $ kill
o Description: Send a signal to a process.
o Usage: kill [options] pid
o Example: kill 1234
27. $ history
o Description: Show command history.
o Usage: history
o Example: Displays previously executed commands.
28. $ sudo
o Description: Execute a command as another user (usually root).
o Usage: sudo command
o Example: sudo apt-get update
29. $ apt-get
o Description: APT package handling utility (for Debian-based systems).
o Usage: apt-get [options] command
o Example: sudo apt-get install nginx
30. $ yum
o Description: Package manager (for Red Hat-based systems).
o Usage: yum [options] command
o Example: sudo yum install httpd
1. $ awk
o Description: Pattern scanning and processing language.
o Usage: awk 'pattern {action}' file
o Example: awk '{print $1}' /etc/passwd
2. $ sed
o Description: Stream editor for filtering and transforming text.
o Usage: sed [options] 'script' file
o Example: sed 's/old/new/g' file.txt
3. $ tar
o Description: Archive files.
o Usage: tar [options] [archive] [file/directory]
o Options:
▪ -c: Create an archive.
▪ -x: Extract an archive.
▪ -v: Verbose mode.
▪ -f: File name.
▪ -z: Compress with gzip.
▪ -j: Compress with bzip2.
o Examples:
▪ tar -czvf archive.tar.gz /path/to/directory
▪ tar -xzvf archive.tar.gz
4. $ gzip
o Description: Compress files.
o Usage: gzip [options] file
o Example: gzip file.txt
5. $ gunzip
o Description: Decompress files.
o Usage: gunzip [options] file
o Example: gunzip file.txt.gz
6. $ iptables
o Description: Administration tool for IPv4 packet filtering and NAT.
o Usage: iptables [options]
o Example: sudo iptables -L
7. $ docker
o Description: Manage Docker containers.
o Usage: docker [command]
o Commands:
▪ docker run: Run a container.
▪ docker ps: List running containers.
▪ docker stop: Stop a running container.
o Example: docker run -d nginx
8. $ kubectl
o Description: Kubernetes command-line tool.
o Usage: kubectl [command]
o Commands:
▪ kubectl get: List resources.
▪ kubectl apply: Apply a configuration to a resource.
▪ kubectl delete: Delete resources.
o Example: kubectl get pods
9. $ ansible
o Description: Automation tool for managing servers.
o Usage: ansible [command]
o Commands:
▪ ansible-playbook: Run an Ansible playbook.
▪ ansible-inventory: Display or dump the configured inventory.
o Example: ansible-playbook site.yml
10. $ git
o Description: Version control system.
o Usage: git [command]
o Commands:
▪ git clone: Clone a repository.
▪ git commit: Commit changes.
▪ git push: Push changes to a remote repository.
o Example: git clone
11. $ vagrant
o Description: Tool for building and managing virtualized development
environments.
o Usage: vagrant [command]
o Commands:
▪ vagrant init: Initialize a Vagrant environment.
▪ vagrant up: Start the Vagrant environment.
▪ vagrant halt: Stop the Vagrant environment.
o Example: vagrant up
12. $ terraform
o Description: Infrastructure as code tool.
o Usage: terraform [command]
o Commands:
▪ terraform init: Initialize a configuration.
▪ terraform apply:
Apply changes.
▪ terraform destroy: Destroy the infrastructure.
o Example: terraform apply
VI Editor
The VI editor is a powerful text editor available on most Unix-like systems. It operates in
different modes, each serving a specific purpose. Here's a detailed guide to using VI:
VI Modes
1. Normal Mode: This is the default mode when you open VI. In this mode, you can
navigate the file, delete text, and perform other editing tasks.
2. Insert Mode: In this mode, you can insert text into the file. You switch to this mode
from Normal mode.
3. Visual Mode: This mode allows you to select text.
4. Command-Line Mode: Used for executing commands like saving and quitting.
sed is a stream editor used for parsing and transforming text. It processes input line by line
and applies specified commands to each line.
Basic Syntax
1. Substitute (s)
o Description: Replaces the first occurrence of pattern with replacement in
each line.
o Example: Replace apple with orange.
o Only the Nth Occurrence (N): Replaces only the Nth occurrence.
2. Delete (d)
o Description: Deletes lines that match the pattern.
o Example: Delete lines containing error.
3. Print (p)
o Description: Prints lines that match the pattern.
o Example: Print lines containing warning.
4. Append (a)
o Description: Appends text after lines that match the pattern.
o Example: Append End of file after lines containing EOF.
5. Insert (i)
o Description: Inserts text before lines that match the pattern.
o Example: Insert Start of file before lines containing HEADER.
6. Change (c)
o Description: Replaces lines that match the pattern with text.
o Example: Replace lines containing old_text with new_text.
7. Transform (y)
o Description: Replaces characters in old_chars with corresponding characters
in new_chars.
o Example: Replace characters abc with 123.
Advanced Usage
1. Multiple Commands
o Description: Applies multiple sed commands to each line.
o Example: Replace foo with bar, then delete lines containing baz.
2. Address Ranges
o Description: Applies commands only within the specified range of lines.
o Example: Replace apple with orange from lines 2 to 5.
3. Using Patterns
o Description: Applies commands only to lines matching pattern.
o Example: Replace foo with bar only on lines containing baz.
Summary
• sed is a powerful tool for text processing, offering various commands to search,
replace, delete, and manipulate text.
• Understanding sed commands can simplify text processing tasks and automate
transformations.
Permission Symbols
1. r (Read)
o Description: Grants the ability to view the contents of the file.
o Access: When read permission is granted, users can open and view the file's
content but cannot modify it.
o Usage Example: To list the contents of a file or to view a configuration file,
the read permission is necessary.
2. w (Write)
o Description: Allows modification of the file's content.
o Access: Users with write permission can change or overwrite the file's
content. This includes adding or deleting data within the file.
o Usage Example: To edit a text file or update a configuration file, write
permission is required.
3. x (Execute)
o Description: Enables running the file as a program or script.
o Access: When execute permission is granted, users can run the file if it is a
script or binary executable. This does not grant permission to modify or view
the file's content.
o Usage Example: To run a shell script or a compiled program, execute
permission is needed.
Permission Combinations
• Owner (user): The file's owner, who can be granted any combination of r, w, and x
permissions.
• Group: Users who are members of the file's group, with permissions that can differ
from the owner.
• Others: All other users, with permissions that can be set separately from the owner
and group.
Combining Permissions
Permissions are specified for three categories (owner, group, others) and are combined into a
single octal number. For example:
Understanding these permissions helps in correctly setting file access controls to ensure
appropriate access levels are granted to different users.