{"id":2548,"date":"2023-06-28T08:45:40","date_gmt":"2023-06-28T08:45:40","guid":{"rendered":"https:\/\/codeinsightacademy.com\/blog\/?p=2548"},"modified":"2023-07-25T07:09:06","modified_gmt":"2023-07-25T07:09:06","slug":"linux-crash-course","status":"publish","type":"post","link":"https:\/\/codeinsightacademy.com\/blog\/linux\/linux-crash-course\/","title":{"rendered":"Linux Crash Course"},"content":{"rendered":"\n<h2>Day 1: Introduction to Linux<\/h2>\n\n\n\n<p>Topics:<\/p>\n\n\n\n<ol><li>Linux operating system<br>Explanation: Learn about the Linux operating system, its features, and its popularity among developers and system administrators.<\/li><li>Basic Linux commands<br>Explanation: Understand essential Linux commands such as <code>ls<\/code> (list files and directories), <code>cd<\/code> (change directory), <code>pwd<\/code> (print working directory), and <code>mkdir<\/code> (make directory).<\/li><li>File and directory management<br>Explanation: Learn how to create, delete, move, and rename files and directories using commands like <code>touch<\/code>, <code>rm<\/code>, <code>mv<\/code>, and <code>cp<\/code>.<\/li><li>File permissions and ownership<br>Explanation: Understand the concept of file permissions and how to set permissions using <code>chmod<\/code>, as well as changing file ownership using <code>chown<\/code>.<\/li><li>File manipulation and text editing<br>Explanation: Explore commands like <code>cat<\/code> (concatenate and display file contents), <code>less<\/code> (view file contents page by page), and <code>nano<\/code> (a basic text editor).<\/li><\/ol>\n\n\n\n<p>Assignments:<\/p>\n\n\n\n<ol><li>Create a directory named &#8220;my_files&#8221; and navigate into it.<br>Answer: <code>mkdir my_files<\/code> (to create the directory) and <code>cd my_files<\/code> (to navigate into it).<\/li><li>Create a file named &#8220;my_text.txt&#8221; and write some text into it.<br>Answer: <code>touch my_text.txt<\/code> (to create the file) and <code>nano my_text.txt<\/code> (to open the file in the nano text editor and write the text).<\/li><li>List all the files and directories in the current directory.<br>Answer: <code>ls<\/code> (to list files and directories).<\/li><li>Rename the file &#8220;my_text.txt&#8221; to &#8220;new_text.txt&#8221;.<br>Answer: <code>mv my_text.txt new_text.txt<\/code> (to rename the file).<\/li><li>Delete the directory &#8220;my_files&#8221; and all its contents.<br>Answer: <code>rm -r my_files<\/code> (to remove the directory and its contents).<\/li><\/ol>\n\n\n\n<h2>Day 2: Working with Files and Permissions<\/h2>\n\n\n\n<p>Topics:<\/p>\n\n\n\n<ol><li>File manipulation commands<br>Explanation: Explore more file manipulation commands such as <code>head<\/code> (display the beginning of a file), <code>tail<\/code> (display the end of a file), and <code>wc<\/code> (word count).<\/li><li>File permissions and access modes<br>Explanation: Understand the three levels of file permissions (owner, group, others) and how to set permissions using symbolic notation (<code>rwx<\/code>) and numeric notation (<code>777<\/code>).<\/li><li>Changing file ownership and group<br>Explanation: Learn how to change the owner and group of a file using the <code>chown<\/code> and <code>chgrp<\/code> commands.<\/li><li>File compression and archiving<br>Explanation: Discover commands like <code>tar<\/code> (archive files) and <code>gzip<\/code> (compress files) to manage large file collections efficiently.<\/li><li>File searching and filtering<br>Explanation: Learn about commands like <code>find<\/code> (search for files and directories) and <code>grep<\/code> (search for text patterns in files).<\/li><\/ol>\n\n\n\n<p>Assignments:<\/p>\n\n\n\n<ol><li>Create a file named &#8220;sample.txt&#8221; and write some content into it.<br>Answer: <code>touch sample.txt<\/code> (to create the file) and <code>nano sample.txt<\/code> (to open the file in the nano text editor and write the content).<\/li><li>Display the first 5 lines of the file &#8220;sample.txt&#8221;.<br>Answer: <code>head -n 5 sample.txt<\/code> (to display the first 5 lines).<\/li><li>Set the file permissions of &#8220;sample.txt&#8221; to read and write for the owner only.<br>Answer: <code>chmod 600 sample.txt<\/code> (to set the permissions).<\/li><li>Change the owner of &#8220;sample.txt<\/li><\/ol>\n\n\n\n<p>&#8221; to a different user.<br>Answer: <code>chown username sample.txt<\/code> (to change the owner to the specified username).<\/p>\n\n\n\n<ol start=\"5\"><li>Archive the file &#8220;sample.txt&#8221; and compress it into a single file.<br>Answer: <code>tar -czvf sample.tar.gz sample.txt<\/code> (to create the archive and compress it).<\/li><\/ol>\n\n\n\n<h2>Day 3: Introduction to Vim Editor<\/h2>\n\n\n\n<p>Topics:<\/p>\n\n\n\n<ol><li>Introduction to Vim<br>Explanation: Understand the basics of the Vim editor, including its modes (Normal, Insert, Visual), navigation, and command execution.<\/li><li>Opening and saving files<br>Explanation: Learn how to open files in Vim, make changes, and save them using commands like <code>:e<\/code> (open), <code>:w<\/code> (save), and <code>:q<\/code> (quit).<\/li><li>Moving and navigating within files<br>Explanation: Explore various movement commands like <code>h<\/code> (left), <code>j<\/code> (down), <code>k<\/code> (up), <code>l<\/code> (right), and using line numbers to jump to specific locations.<\/li><li>Editing and modifying text<br>Explanation: Understand text editing commands like <code>i<\/code> (insert), <code>o<\/code> (open a new line), <code>x<\/code> (delete a character), and <code>yy<\/code> (copy a line).<\/li><li>Undo and redo operations<br>Explanation: Learn how to undo and redo changes made in Vim using the <code>u<\/code> (undo) and <code>Ctrl+R<\/code> (redo) commands.<\/li><\/ol>\n\n\n\n<p>Assignments:<\/p>\n\n\n\n<ol><li>Open the file &#8220;my_file.txt&#8221; in Vim and navigate to the end of the file.<br>Answer: <code>vim my_file.txt<\/code> (to open the file) and <code>G<\/code> (to move to the end of the file).<\/li><li>Insert a new line after the current line and write some text into it.<br>Answer: Press <code>o<\/code> (to open a new line) and start typing the desired text.<\/li><li>Delete the current line in Vim.<br>Answer: Press <code>dd<\/code> (to delete the current line).<\/li><li>Copy the current line in Vim and paste it below the current line.<br>Answer: Press <code>yy<\/code> (to copy the current line) and then <code>p<\/code> (to paste it below).<\/li><li>Save the changes made to the file and exit Vim.<br>Answer: Press <code>:wq<\/code> (to save and quit).<\/li><\/ol>\n\n\n\n<h2>Day 4: Advanced Vim Editing<\/h2>\n\n\n\n<p>Topics:<\/p>\n\n\n\n<ol><li>Visual mode in Vim<br>Explanation: Learn how to select and manipulate blocks of text using Visual mode, including commands like <code>v<\/code> (characterwise), <code>V<\/code> (linewise), and <code>Ctrl+V<\/code> (blockwise).<\/li><li>Searching and replacing text<br>Explanation: Discover how to search for specific text patterns using <code>\/<\/code> (forward search) and <code>?<\/code> (backward search), as well as replacing text using <code>:s<\/code> (substitute).<\/li><li>Advanced editing commands<br>Explanation: Explore advanced editing commands like <code>x<\/code> (delete a character), <code>r<\/code> (replace a character), <code>J<\/code> (join lines), and <code>.<\/code> (repeat the last command).<\/li><li>Advanced movement and navigation<br>Explanation: Learn advanced movement commands like <code>w<\/code> (jump to the beginning of the next word), <code>b<\/code> (jump to the beginning of the previous word), and <code>gg<\/code> (jump to the first line).<\/li><li>Split windows and tabs in Vim<br>Explanation: Understand how to split the Vim editor window vertically and horizontally using commands like <code>:split<\/code> and <code>:vsplit<\/code>, and navigate between tabs.<\/li><\/ol>\n\n\n\n<p>Assignments:<\/p>\n\n\n\n<ol><li>Open the file &#8220;my_notes.txt&#8221; in Vim and search for the word &#8220;important&#8221;.<br>Answer: <code>vim my_notes.txt<\/code> (to open the file) and <code>\/important<\/code> (to search for the word &#8220;important&#8221;).<\/li><li>Replace all occurrences of the word &#8220;old&#8221; with &#8220;new&#8221; in the current line.<br>Answer: <code>:s\/old\/new\/<\/code> (to perform the substitution).<\/li><li>Join the current line with the line below it.<br>Answer: Press <code>J<\/code> (to join the lines).<\/li><li>Split the Vim editor window vertically.<br>Answer: <code>:vsplit<\/code> (to split the window vertically).<\/li><li>Move the cursor to the beginning of the next word in Vim.<br>Answer: Press <code>w<\/code> (to jump to the beginning of the next word).<\/li><\/ol>\n\n\n\n<h2>Day 5: Vim Customization and Advanced Topics<\/h2>\n\n\n\n<p>Topics:<\/p>\n\n\n\n<ol><li>Vim configuration files<br>Explanation: Understand the <code>.vimrc<\/code> file and how to customize Vim settings, key mappings, and plugins.<\/li><li>Customizing Vim colorschemes<br>Explanation: Learn how to change the colorscheme in Vim to enhance the visual appearance and readability of your code.<\/li><li>Advanced Vim features and plugins<br>Explanation: Explore advanced Vim features like macros, multiple cursors (using plugins), and code completion (using plugins).<\/li><li>Vim navigation shortcuts<br>Explanation: Discover useful navigation shortcuts like <code>Ctrl+U<\/code> (scroll half a page up), <code>Ctrl+D<\/code> (scroll half a page down), and <code>gg<\/code> (jump to the first line).<\/li><li>Vim documentation and help<br>Explanation: Learn how to access Vim documentation and help resources, including built-in help pages and online resources.<\/li><\/ol>\n\n\n\n<p>Assignments:<\/p>\n\n\n\n<ol><li>Customize the Vim settings by adding the following lines to your <code>.vimrc<\/code> file:<\/li><\/ol>\n\n\n\n<ul><li>Set the tab width to 4 spaces.<\/li><li>Enable line numbers.<br>Answer: Open the <code>.vimrc<\/code> file in Vim (<code>vim ~\/.vimrc<\/code>) and add the desired configurations.<\/li><\/ul>\n\n\n\n<ol><li>Change the colorscheme in Vim to a different one.<br>Answer: In Vim, type <code>:colorscheme &lt;colorscheme_name&gt;<\/code> to change the colorscheme.<\/li><li>Create a macro in Vim that inserts a specific code snippet.<br>Answer: Record the macro using <code>q&lt;register&gt;<\/code> and replay it using <code>@&lt;register&gt;<\/code>.<\/li><li>Install a plugin in Vim for code completion or any other desired functionality.<br>Answer: Install the desired plugin using a plugin manager like Vundle or Pathogen.<\/li><li>Access the Vim built-in help and find information on a specific Vim command or feature.<br>Answer: In Vim, type <code>:help &lt;command_or_feature&gt;<\/code> to access the built-in help pages.<\/li><\/ol>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"has-text-align-center\">Shell Scripting<\/h2>\n\n\n\n<p>Apologies for the oversight. Here are the shell scripting assignments along with sample answers for each day:<\/p>\n\n\n\n<p>Day 1:<\/p>\n\n\n\n<ol><li>Write a shell script that takes two numbers as input and prints their sum.<\/li><\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/bin\/bash\n\necho \"Enter the first number: \"\nread num1\n\necho \"Enter the second number: \"\nread num2\n\nsum=$((num1 + num2))\necho \"The sum is: $sum\"<\/pre>\n\n\n\n<ol start=\"2\"><li>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.<\/li><\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/bin\/bash\n\necho \"Enter a filename: \"\nread filename\n\nif [ -e \"$filename\" ]; then\n    echo \"The file '$filename' exists in the current directory.\"\nelse\n    echo \"Error: The file '$filename' does not exist in the current directory.\"\nfi<\/pre>\n\n\n\n<ol start=\"3\"><li>Write a shell script that reads a string from the user and prints it in reverse order.<\/li><\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/bin\/bash\n\necho \"Enter a string: \"\nread input_string\n\nreversed_string=$(echo \"$input_string\" | rev)\necho \"Reversed string: $reversed_string\"<\/pre>\n\n\n\n<ol start=\"4\"><li>Create a script that takes a directory name as input and lists all the files in that directory.<\/li><\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/bin\/bash\n\necho \"Enter a directory name: \"\nread directory\n\nif [ -d \"$directory\" ]; then\n    echo \"Files in $directory:\"\n    ls \"$directory\"\nelse\n    echo \"Error: '$directory' is not a valid directory.\"\nfi<\/pre>\n\n\n\n<ol start=\"5\"><li>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&#8217;s guess.<\/li><\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/bin\/bash\n\nrandom_number=$((RANDOM % 100 + 1))\n\necho \"Guess the number between 1 and 100: \"\nread user_guess\n\nif [ \"$user_guess\" -eq \"$random_number\" ]; then\n    echo \"Congratulations! You guessed the correct number.\"\nelif [ \"$user_guess\" -lt \"$random_number\" ]; then\n    echo \"Try again. The number is higher than your guess.\"\nelse\n    echo \"Try again. The number is lower than your guess.\"\nfi<\/pre>\n\n\n\n<p>Day 2:<\/p>\n\n\n\n<ol><li>Write a shell script that takes a filename as input and checks if it is a regular file or a directory.<\/li><\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/bin\/bash\n\necho \"Enter a filename: \"\nread filename\n\nif [ -f \"$filename\" ]; then\n    echo \"'$filename' is a regular file.\"\nelif [ -d \"$filename\" ]; then\n    echo \"'$filename' is a directory.\"\nelse\n    echo \"Error: '$filename' is neither a regular file nor a directory.\"\nfi<\/pre>\n\n\n\n<ol start=\"2\"><li>Create a script that takes a file containing a list of numbers and calculates their sum.<\/li><\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/bin\/bash\n\nsum=0\nwhile read -r num; do\n    sum=$((sum + num))\ndone &lt; \"$1\"\n\necho \"Sum of numbers in the file: $sum\"<\/pre>\n\n\n\n<ol start=\"3\"><li>Write a shell script that renames all files in a directory with a specific extension to have a prefix &#8220;backup_&#8221; followed by the original filename.<\/li><\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/bin\/bash\n\necho \"Enter the directory name: \"\nread directory\n\necho \"Enter the file extension to rename: \"\nread ext\n\nfor file in \"$directory\"\/*.\"$ext\"; do\n    filename=$(basename \"$file\")\n    mv \"$file\" \"$directory\/backup_$filename\"\ndone<\/pre>\n\n\n\n<ol start=\"4\"><li>Create a script that reads a file and counts the number of lines, words, and characters in it.<\/li><\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/bin\/bash\n\necho \"Enter a filename: \"\nread filename\n\nif [ -f \"$filename\" ]; then\n    line_count=$(wc -l &lt; \"$filename\")\n    word_count=$(wc -w &lt; \"$filename\")\n    char_count=$(wc -c &lt; \"$filename\")\n\n    echo \"Number of lines: $line_count\"\n    echo \"Number of words: $word_count\"\n    echo \"Number of characters: $char_count\"\nelse\n    echo \"Error: '$filename' is not a valid file.\"\nfi<\/pre>\n\n\n\n<ol start=\"5\"><li>Write a shell script that takes a number as input and prints all the prime numbers less than or equal to that number.<\/li><\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/bin\/bash\n\necho \"Enter a number: \"\nread num\n\nif [ \"$num\" -lt 2 ]; then\n    echo \"There are no prime numbers less than 2.\"\nelse\n    echo \"Prime numbers less than or equal to $num:\"\n    for ((i = 2; i &lt;= num; i++)); do\n        is_prime=1\n        for ((j = 2; j &lt;= i \/ 2; j++)); do\n            if ((i % j == 0)); then\n                is_prime=0\n                break\n            fi\n        done\n        if [ \"$is_prime\" -eq 1 ]; then\n            echo \"$i\"\n        fi\n    done\nfi<\/pre>\n\n\n\n<p>Day 3:<\/p>\n\n\n\n<ol><li>Create a shell script that takes a directory name as input and finds all the subdirectories within it.<\/li><\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/bin\/bash\n\necho \"Enter a directory name: \"\nread directory\n\nif [ -d \"$directory\" ]; then\n    echo \"Subdirectories in '$directory':\"\n    find \"$directory\" -type d\nelse\n    echo \"Error: '$directory' is not a valid directory.\"\nfi<\/pre>\n\n\n\n<ol start=\"2\"><li>Write a script that reads a file and removes all the empty lines from it.<\/li><\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/bin\/bash\n\necho \"Enter a filename: \"\nread filename\n\nif [ -f \"$filename\" ]; then\n    sed -i '\/^[[:space:]]*$\/d' \"$filename\"\n    echo \"Empty lines removed from '$filename'.\"\nelse\n    echo \"Error: '$filename' is not a valid file.\"\nfi<\/pre>\n\n\n\n<ol start=\"3\"><li>Create a shell script that takes a string as input and checks if it is a palindrome.<\/li><\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/bin\/bash\n\necho \"Enter a string: \"\nread input_string\n\nreverse_string=$(echo \"$input_string\" | rev)\n\nif [ \"$input_string\" = \"$reverse_string\" ]; then\n    echo \"The string is a palindrome.\"\nelse\n    echo \"The string is not a palindrome.\"\nfi<\/pre>\n\n\n\n<ol start=\"4\"><li>Write a shell script that reads a number as input and checks if it is even or odd.<\/li><\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/bin\/bash\n\necho \"Enter a number: \"\nread num\n\nif ((num % 2 == 0)); then\n    echo \"$num is an even number.\"\nelse\n    echo \"$num is an odd number.\"\nfi<\/pre>\n\n\n\n<ol start=\"5\"><li>Create a shell script that prints the current date and time.<\/li><\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/bin\/bash\n\ncurrent_date=$(date +\"%Y-%m-%d\")\ncurrent_time=$(date +\"%H:%M:%S\")\n\necho \"Current date: $current_date\"\necho \"Current time: $current_time\"<\/pre>\n\n\n\n<p>Day 4:<\/p>\n\n\n\n<ol><li>Write a shell script that takes a directory name as input and deletes all the files in that directory with a &#8220;.tmp&#8221; extension.<\/li><\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/bin\/bash\n\necho \"Enter a directory name: \"\nread directory\n\nif [ -d \"$directory\" ]; then\n    find \"$directory\" -type f -name \"*.tmp\" -delete\n    echo \"All '.tmp' files in '$directory' deleted.\"\nelse\n    echo \"Error: '$directory' is not a valid directory.\"\nfi<\/pre>\n\n\n\n<ol start=\"2\"><li>Create a script that reads a file and replaces all occurrences of a word with another word.<\/li><\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/bin\/bash\n\necho \"Enter a filename: \"\nread filename\n\nif [ -f \"$filename\" ]; then\n    echo \"Enter the word to replace: \"\n    read old_word\n\n    echo \"Enter the new word: \"\n    read new_word\n\n    sed -i \"s\/$old_word\/$new_word\/g\" \"$filename\"\n    echo \"Occurrences of '$old_word' replaced with '$new_word' in '$filename'.\"\nelse\n    echo \"Error: '$filename' is not a valid file.\"\nfi<\/pre>\n\n\n\n<ol start=\"3\"><li>Write a shell script that reads a number as input and checks if it is prime.<\/li><\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/bin\/bash\n\necho \"Enter a number: \"\nread num\n\nif [ \"$num\" -lt 2 ]; then\n    echo \"The number must be greater than or equal to 2 to check for primality.\"\nelse\n    is_prime=1\n    for ((i = 2; i &lt;= num \/ 2; i++)); do\n        if ((num % i == 0)); then\n            is_prime=0\n            break\n        fi\n    done\n\n    if [ \"$is_prime\" -eq 1 ]; then\n        echo \"$num is a prime number.\"\n    else\n        echo \"$num is not a prime number.\"\n    fi\nfi<\/pre>\n\n\n\n<ol start=\"4\"><li>Create a shell script that takes a directory name as input and counts the number of files and subdirectories in it.<\/li><\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/bin\/bash\n\necho \"Enter a directory name: \"\nread directory\n\nif [ -d \"$directory\" ]; then\n    file_count=$(find \"$directory\" -type f | wc -l)\n    dir_count=$(find \"$directory\" -type d | wc -l)\n\n    echo \"Number of files: $file_count\"\n    echo \"Number of subdirectories: $dir_count\"\nelse\n    echo \"Error: '$directory' is not a valid directory.\"\nfi<\/pre>\n\n\n\n<ol start=\"5\"><li>Write a shell script that reads a string as input and converts it to uppercase.<\/li><\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/bin\/bash\n\necho \"Enter a string: \"\nread input_string\n\nupper_case_string=$(echo \"$input_string\" | tr '[:lower:]' '[:upper:]')\n\necho \"Uppercase string: $upper_case_string\"<\/pre>\n\n\n\n<p>Day 5:<\/p>\n\n\n\n<ol><li>Create a shell script that takes two numbers as input and swaps their values.<\/li><\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/bin\/bash\n\necho \"Enter the first number: \"\nread num1\n\necho \"Enter the second number: \"\nread num2\n\necho \"Before swapping: num1 = $num1, num2 = $num2\"\n\n# Swapping using a temporary variable\ntemp=$num1\nnum1=$num2\nnum2=$temp\n\necho \"After swapping: num1 = $num1, num2 = $num2\"<\/pre>\n\n\n\n<ol start=\"2\"><li>Write a script that takes a file and sorts its lines in ascending order.<\/li><\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/bin\/bash\n\necho \"Enter a filename: \"\nread filename\n\nif [ -f \"$filename\" ]; then\n    sort \"$filename\" > sorted_\"$filename\"\n    echo \"Lines in '$filename' sorted in ascending order and saved to 'sorted_$filename'.\"\nelse\n    echo \"Error: '$filename' is not a valid file.\"\nfi<\/pre>\n\n\n\n<ol start=\"3\"><li>Create a shell script that reads a directory name as input and prints the names of the 10 largest files in it.<\/li><\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/bin\/bash\n\necho \"Enter a directory name: \"\nread directory\n\nif [ -d \"$directory\" ]; then\n    echo \"The 10 largest files in '$directory':\"\n    du -ah \"$directory\" | sort -rh | head -n 10\nelse\n    echo \"Error: '$directory' is not a valid directory.\"\nfi<\/pre>\n\n\n\n<ol start=\"4\"><li>Write a shell script that takes a list of filenames as arguments and checks if all of them exist in the current directory.<\/li><\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/bin\/bash\n\nfor filename in \"$@\"; do\n    if [ ! -e \"$filename\" ]; then\n        echo \"Error: '$filename' does not exist in the current directory.\"\n    else\n        echo \"'$filename' exists in the current directory.\"\n    fi\ndone<\/pre>\n\n\n\n<ol start=\"5\"><li>Create a shell script that calculates the factorial of a given number.<\/li><\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/bin\/bash\n\necho \"Enter a number: \"\nread num\n\nfactorial=1\n\nfor ((i = 1; i &lt;= num; i++)); do\n    factorial=$((factorial * i))\ndone\n\necho \"Factorial of $num is: $factorial\"<\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Day 1: Introduction to Linux Topics: Linux operating systemExplanation: Learn about the Linux operating system, its features, and its popularity among developers and system administrators. Basic Linux commandsExplanation: Understand essential Linux commands such as ls (list files and directories), cd (change directory), pwd (print working directory), and mkdir (make directory). File and directory managementExplanation: Learn [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[31],"tags":[],"_links":{"self":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts\/2548"}],"collection":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/comments?post=2548"}],"version-history":[{"count":3,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts\/2548\/revisions"}],"predecessor-version":[{"id":2571,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts\/2548\/revisions\/2571"}],"wp:attachment":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/media?parent=2548"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/categories?post=2548"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/tags?post=2548"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}