Bash Script Step-by-Step Explanation
Script Code
#!/bin/bash
mkdir [Link] # make a directory named [Link]
cd [Link] # change directory to [Link]
touch [Link] # create file1 using touch command
touch [Link] # create file2 using touch command
touch [Link] # create file3 using touch command
echo "This is [Link]" > [Link] # overwrite the data in [Link]
echo "This is [Link]" > [Link] # overwrite the data in [Link]
echo "This is [Link]" > [Link] # overwrite the data in [Link]
cat [Link] [Link] [Link] > [Link] # combine all file output and store in com
wc [Link] # check the word count of [Link]
ls -l [Link] # check the file permissions
chmod 444 [Link] # change user permissions to read only
ls -l [Link] # check the file permissions again
chmod 777 [Link] # change user permissions to read, write and execute
ls -l [Link] # check the file permissions again
echo "hello combined file" >> [Link] # append to [Link]
cat [Link] # display the output of [Link]
Step-by-Step Description
Step 1: Create a directory named [Link] to store all files.
Step 2: Move into (change directory to) [Link].
Step 3: Create three empty text files: [Link], [Link], and [Link]
using the touch command.
Step 4: Write unique sample text into each of the three files using the echo
command, overwriting any existing content.
Step 5: Combine all three files into one ([Link]) using cat. This file
will contain the contents of the first, second, and third files in sequence.
Step 6: Use wc [Link] to display the word, line, and byte count of
[Link].
1
Figure 1: Text Editor
Figure 2: Output
Step 7: Use ls -l [Link] to list detailed file information, including
permissions.
Step 8: Change [Link] permissions to read-only for everyone (chmod
444), then re-check with ls -l.
Step 9: Change [Link] permissions back to read, write, and execute
for everyone (chmod 777), then check again with ls -l.
Step 10: Append the line “hello combined file” to the end of [Link]
with echo and >>.
Step 11: Use cat [Link] to display the final content of [Link].