Day 1: Introduction to Linux
Topics:
- Linux operating system
Explanation: Learn about the Linux operating system, its features, and its popularity among developers and system administrators. - Basic Linux commands
Explanation: Understand essential Linux commands such asls
(list files and directories),cd
(change directory),pwd
(print working directory), andmkdir
(make directory). - File and directory management
Explanation: Learn how to create, delete, move, and rename files and directories using commands liketouch
,rm
,mv
, andcp
. - File permissions and ownership
Explanation: Understand the concept of file permissions and how to set permissions usingchmod
, as well as changing file ownership usingchown
. - File manipulation and text editing
Explanation: Explore commands likecat
(concatenate and display file contents),less
(view file contents page by page), andnano
(a basic text editor).
Assignments:
- Create a directory named “my_files” and navigate into it.
Answer:mkdir my_files
(to create the directory) andcd my_files
(to navigate into it). - Create a file named “my_text.txt” and write some text into it.
Answer:touch my_text.txt
(to create the file) andnano my_text.txt
(to open the file in the nano text editor and write the text). - List all the files and directories in the current directory.
Answer:ls
(to list files and directories). - Rename the file “my_text.txt” to “new_text.txt”.
Answer:mv my_text.txt new_text.txt
(to rename the file). - Delete the directory “my_files” and all its contents.
Answer:rm -r my_files
(to remove the directory and its contents).
Day 2: Working with Files and Permissions
Topics:
- File manipulation commands
Explanation: Explore more file manipulation commands such ashead
(display the beginning of a file),tail
(display the end of a file), andwc
(word count). - File permissions and access modes
Explanation: Understand the three levels of file permissions (owner, group, others) and how to set permissions using symbolic notation (rwx
) and numeric notation (777
). - Changing file ownership and group
Explanation: Learn how to change the owner and group of a file using thechown
andchgrp
commands. - File compression and archiving
Explanation: Discover commands liketar
(archive files) andgzip
(compress files) to manage large file collections efficiently. - File searching and filtering
Explanation: Learn about commands likefind
(search for files and directories) andgrep
(search for text patterns in files).
Assignments:
- Create a file named “sample.txt” and write some content into it.
Answer:touch sample.txt
(to create the file) andnano sample.txt
(to open the file in the nano text editor and write the content). - Display the first 5 lines of the file “sample.txt”.
Answer:head -n 5 sample.txt
(to display the first 5 lines). - Set the file permissions of “sample.txt” to read and write for the owner only.
Answer:chmod 600 sample.txt
(to set the permissions). - Change the owner of “sample.txt
” to a different user.
Answer: chown username sample.txt
(to change the owner to the specified username).
- Archive the file “sample.txt” and compress it into a single file.
Answer:tar -czvf sample.tar.gz sample.txt
(to create the archive and compress it).
Day 3: Introduction to Vim Editor
Topics:
- Introduction to Vim
Explanation: Understand the basics of the Vim editor, including its modes (Normal, Insert, Visual), navigation, and command execution. - Opening and saving files
Explanation: Learn how to open files in Vim, make changes, and save them using commands like:e
(open),:w
(save), and:q
(quit). - Moving and navigating within files
Explanation: Explore various movement commands likeh
(left),j
(down),k
(up),l
(right), and using line numbers to jump to specific locations. - Editing and modifying text
Explanation: Understand text editing commands likei
(insert),o
(open a new line),x
(delete a character), andyy
(copy a line). - Undo and redo operations
Explanation: Learn how to undo and redo changes made in Vim using theu
(undo) andCtrl+R
(redo) commands.
Assignments:
- Open the file “my_file.txt” in Vim and navigate to the end of the file.
Answer:vim my_file.txt
(to open the file) andG
(to move to the end of the file). - Insert a new line after the current line and write some text into it.
Answer: Presso
(to open a new line) and start typing the desired text. - Delete the current line in Vim.
Answer: Pressdd
(to delete the current line). - Copy the current line in Vim and paste it below the current line.
Answer: Pressyy
(to copy the current line) and thenp
(to paste it below). - Save the changes made to the file and exit Vim.
Answer: Press:wq
(to save and quit).
Day 4: Advanced Vim Editing
Topics:
- Visual mode in Vim
Explanation: Learn how to select and manipulate blocks of text using Visual mode, including commands likev
(characterwise),V
(linewise), andCtrl+V
(blockwise). - Searching and replacing text
Explanation: Discover how to search for specific text patterns using/
(forward search) and?
(backward search), as well as replacing text using:s
(substitute). - Advanced editing commands
Explanation: Explore advanced editing commands likex
(delete a character),r
(replace a character),J
(join lines), and.
(repeat the last command). - Advanced movement and navigation
Explanation: Learn advanced movement commands likew
(jump to the beginning of the next word),b
(jump to the beginning of the previous word), andgg
(jump to the first line). - Split windows and tabs in Vim
Explanation: Understand how to split the Vim editor window vertically and horizontally using commands like:split
and:vsplit
, and navigate between tabs.
Assignments:
- Open the file “my_notes.txt” in Vim and search for the word “important”.
Answer:vim my_notes.txt
(to open the file) and/important
(to search for the word “important”). - Replace all occurrences of the word “old” with “new” in the current line.
Answer::s/old/new/
(to perform the substitution). - Join the current line with the line below it.
Answer: PressJ
(to join the lines). - Split the Vim editor window vertically.
Answer::vsplit
(to split the window vertically). - Move the cursor to the beginning of the next word in Vim.
Answer: Pressw
(to jump to the beginning of the next word).
Day 5: Vim Customization and Advanced Topics
Topics:
- Vim configuration files
Explanation: Understand the.vimrc
file and how to customize Vim settings, key mappings, and plugins. - Customizing Vim colorschemes
Explanation: Learn how to change the colorscheme in Vim to enhance the visual appearance and readability of your code. - Advanced Vim features and plugins
Explanation: Explore advanced Vim features like macros, multiple cursors (using plugins), and code completion (using plugins). - Vim navigation shortcuts
Explanation: Discover useful navigation shortcuts likeCtrl+U
(scroll half a page up),Ctrl+D
(scroll half a page down), andgg
(jump to the first line). - Vim documentation and help
Explanation: Learn how to access Vim documentation and help resources, including built-in help pages and online resources.
Assignments:
- Customize the Vim settings by adding the following lines to your
.vimrc
file:
- Set the tab width to 4 spaces.
- Enable line numbers.
Answer: Open the.vimrc
file in Vim (vim ~/.vimrc
) and add the desired configurations.
- Change the colorscheme in Vim to a different one.
Answer: In Vim, type:colorscheme <colorscheme_name>
to change the colorscheme. - Create a macro in Vim that inserts a specific code snippet.
Answer: Record the macro usingq<register>
and replay it using@<register>
. - Install a plugin in Vim for code completion or any other desired functionality.
Answer: Install the desired plugin using a plugin manager like Vundle or Pathogen. - Access the Vim built-in help and find information on a specific Vim command or feature.
Answer: In Vim, type:help <command_or_feature>
to access the built-in help pages.
Shell Scripting
Apologies for the oversight. Here are the shell scripting assignments along with sample answers for each day:
Day 1:
- Write a shell script that takes two numbers as input and prints their sum.
#!/bin/bash echo "Enter the first number: " read num1 echo "Enter the second number: " read num2 sum=$((num1 + num2)) echo "The sum is: $sum"
- Create a shell script that reads a filename from the user and checks if it exists in the current directory. If the file exists, display a message confirming its existence; otherwise, display an error message.
#!/bin/bash echo "Enter a filename: " read filename if [ -e "$filename" ]; then echo "The file '$filename' exists in the current directory." else echo "Error: The file '$filename' does not exist in the current directory." fi
- Write a shell script that reads a string from the user and prints it in reverse order.
#!/bin/bash echo "Enter a string: " read input_string reversed_string=$(echo "$input_string" | rev) echo "Reversed string: $reversed_string"
- Create a script that takes a directory name as input and lists all the files in that directory.
#!/bin/bash echo "Enter a directory name: " read directory if [ -d "$directory" ]; then echo "Files in $directory:" ls "$directory" else echo "Error: '$directory' is not a valid directory." fi
- Write a shell script that generates a random number between 1 and 100 and asks the user to guess the number. Provide appropriate feedback based on the user’s guess.
#!/bin/bash random_number=$((RANDOM % 100 + 1)) echo "Guess the number between 1 and 100: " read user_guess if [ "$user_guess" -eq "$random_number" ]; then echo "Congratulations! You guessed the correct number." elif [ "$user_guess" -lt "$random_number" ]; then echo "Try again. The number is higher than your guess." else echo "Try again. The number is lower than your guess." fi
Day 2:
- Write a shell script that takes a filename as input and checks if it is a regular file or a directory.
#!/bin/bash echo "Enter a filename: " read filename if [ -f "$filename" ]; then echo "'$filename' is a regular file." elif [ -d "$filename" ]; then echo "'$filename' is a directory." else echo "Error: '$filename' is neither a regular file nor a directory." fi
- Create a script that takes a file containing a list of numbers and calculates their sum.
#!/bin/bash sum=0 while read -r num; do sum=$((sum + num)) done < "$1" echo "Sum of numbers in the file: $sum"
- Write a shell script that renames all files in a directory with a specific extension to have a prefix “backup_” followed by the original filename.
#!/bin/bash echo "Enter the directory name: " read directory echo "Enter the file extension to rename: " read ext for file in "$directory"/*."$ext"; do filename=$(basename "$file") mv "$file" "$directory/backup_$filename" done
- Create a script that reads a file and counts the number of lines, words, and characters in it.
#!/bin/bash echo "Enter a filename: " read filename if [ -f "$filename" ]; then line_count=$(wc -l < "$filename") word_count=$(wc -w < "$filename") char_count=$(wc -c < "$filename") echo "Number of lines: $line_count" echo "Number of words: $word_count" echo "Number of characters: $char_count" else echo "Error: '$filename' is not a valid file." fi
- Write a shell script that takes a number as input and prints all the prime numbers less than or equal to that number.
#!/bin/bash echo "Enter a number: " read num if [ "$num" -lt 2 ]; then echo "There are no prime numbers less than 2." else echo "Prime numbers less than or equal to $num:" for ((i = 2; i <= num; i++)); do is_prime=1 for ((j = 2; j <= i / 2; j++)); do if ((i % j == 0)); then is_prime=0 break fi done if [ "$is_prime" -eq 1 ]; then echo "$i" fi done fi
Day 3:
- Create a shell script that takes a directory name as input and finds all the subdirectories within it.
#!/bin/bash echo "Enter a directory name: " read directory if [ -d "$directory" ]; then echo "Subdirectories in '$directory':" find "$directory" -type d else echo "Error: '$directory' is not a valid directory." fi
- Write a script that reads a file and removes all the empty lines from it.
#!/bin/bash echo "Enter a filename: " read filename if [ -f "$filename" ]; then sed -i '/^[[:space:]]*$/d' "$filename" echo "Empty lines removed from '$filename'." else echo "Error: '$filename' is not a valid file." fi
- Create a shell script that takes a string as input and checks if it is a palindrome.
#!/bin/bash echo "Enter a string: " read input_string reverse_string=$(echo "$input_string" | rev) if [ "$input_string" = "$reverse_string" ]; then echo "The string is a palindrome." else echo "The string is not a palindrome." fi
- Write a shell script that reads a number as input and checks if it is even or odd.
#!/bin/bash echo "Enter a number: " read num if ((num % 2 == 0)); then echo "$num is an even number." else echo "$num is an odd number." fi
- Create a shell script that prints the current date and time.
#!/bin/bash current_date=$(date +"%Y-%m-%d") current_time=$(date +"%H:%M:%S") echo "Current date: $current_date" echo "Current time: $current_time"
Day 4:
- Write a shell script that takes a directory name as input and deletes all the files in that directory with a “.tmp” extension.
#!/bin/bash echo "Enter a directory name: " read directory if [ -d "$directory" ]; then find "$directory" -type f -name "*.tmp" -delete echo "All '.tmp' files in '$directory' deleted." else echo "Error: '$directory' is not a valid directory." fi
- Create a script that reads a file and replaces all occurrences of a word with another word.
#!/bin/bash echo "Enter a filename: " read filename if [ -f "$filename" ]; then echo "Enter the word to replace: " read old_word echo "Enter the new word: " read new_word sed -i "s/$old_word/$new_word/g" "$filename" echo "Occurrences of '$old_word' replaced with '$new_word' in '$filename'." else echo "Error: '$filename' is not a valid file." fi
- Write a shell script that reads a number as input and checks if it is prime.
#!/bin/bash echo "Enter a number: " read num if [ "$num" -lt 2 ]; then echo "The number must be greater than or equal to 2 to check for primality." else is_prime=1 for ((i = 2; i <= num / 2; i++)); do if ((num % i == 0)); then is_prime=0 break fi done if [ "$is_prime" -eq 1 ]; then echo "$num is a prime number." else echo "$num is not a prime number." fi fi
- Create a shell script that takes a directory name as input and counts the number of files and subdirectories in it.
#!/bin/bash echo "Enter a directory name: " read directory if [ -d "$directory" ]; then file_count=$(find "$directory" -type f | wc -l) dir_count=$(find "$directory" -type d | wc -l) echo "Number of files: $file_count" echo "Number of subdirectories: $dir_count" else echo "Error: '$directory' is not a valid directory." fi
- Write a shell script that reads a string as input and converts it to uppercase.
#!/bin/bash echo "Enter a string: " read input_string upper_case_string=$(echo "$input_string" | tr '[:lower:]' '[:upper:]') echo "Uppercase string: $upper_case_string"
Day 5:
- Create a shell script that takes two numbers as input and swaps their values.
#!/bin/bash echo "Enter the first number: " read num1 echo "Enter the second number: " read num2 echo "Before swapping: num1 = $num1, num2 = $num2" # Swapping using a temporary variable temp=$num1 num1=$num2 num2=$temp echo "After swapping: num1 = $num1, num2 = $num2"
- Write a script that takes a file and sorts its lines in ascending order.
#!/bin/bash echo "Enter a filename: " read filename if [ -f "$filename" ]; then sort "$filename" > sorted_"$filename" echo "Lines in '$filename' sorted in ascending order and saved to 'sorted_$filename'." else echo "Error: '$filename' is not a valid file." fi
- Create a shell script that reads a directory name as input and prints the names of the 10 largest files in it.
#!/bin/bash echo "Enter a directory name: " read directory if [ -d "$directory" ]; then echo "The 10 largest files in '$directory':" du -ah "$directory" | sort -rh | head -n 10 else echo "Error: '$directory' is not a valid directory." fi
- Write a shell script that takes a list of filenames as arguments and checks if all of them exist in the current directory.
#!/bin/bash for filename in "$@"; do if [ ! -e "$filename" ]; then echo "Error: '$filename' does not exist in the current directory." else echo "'$filename' exists in the current directory." fi done
- Create a shell script that calculates the factorial of a given number.
#!/bin/bash echo "Enter a number: " read num factorial=1 for ((i = 1; i <= num; i++)); do factorial=$((factorial * i)) done echo "Factorial of $num is: $factorial"