1. Write a bash script createDirectories.sh that when the script is executed with three given arguments (one is directory name and second is start number of directories and third is the end number of directories ) it creates specified number of directories with a dynamic directory name. Here's a bash script named createDirectories.sh
that takes three arguments as input and creates a specified number of directories with dynamic names:
how the script works:- The script checks if the correct number of arguments provided. If not, it prints an error message and exits. The script assigns the input arguments to variables for ease of use. The script uses a loop to create directories with dynamic names. The loop starts at the start_num
value and continues until the end_num
value is reached. It creates directories with names in the format <directory name>_<number>
using the mkdir
command. The script prints a success message once all directories have been created. To run the script, save the above code in a file named createDirectories.sh
make the file executable using the command chmod +x
createDirectories.sh
and then execute the script with the three required arguments as follows:
For eg , to create 5 directories named "example_dir_1" through "example_dir_5", run:
Create a Script to backup all your work done till now
To create a script that backs up all your work done till now, you can use the tar
command to create a compressed archive of your entire home directory. o automate this process, you can create a bash script that runs the above commands.
Save this code in a file named backup_script.sh
and make the file executable using the command chmod +x backup_script.sh
. Then, you can run the script by executing ./backup_script.sh
in a terminal window.
Read About Cron and Crontab, to automate the backup Script
Cron is a utility that allows you to schedule tasks to run automatically at specific intervals. Cron is used on Unix-based operating systems such as Linux to schedule tasks that run periodically, such as backups, updates, and maintenance tasks.
Crontab is the configuration file used by the cron utility to schedule tasks. The crontab file contains a list of commands to be executed at specified intervals. Each line of the crontab file specifies a task to be run, along with the time and frequency at which it should be run.
Create 2 users and just display their Usernames
To create two users in Linux, you can use the adduser
command. Here's an example of how to create two users named "user1" and "user2":
After running these commands, you will be prompted to enter a password and other information for each user.
To display the usernames of these two users, you can use the cut
command to extract the first field (the username) from the output of the cat
command on the /etc/passwd
file,
This command will display the usernames of all users that have "user" in their name. If you want to display only the usernames of "user1" and "user2", modify the command like this
This command will display the usernames of all users that have "user" in their name. If you want to display only the usernames of "user1" and "user2", modify the command like this:
This command will display only the usernames of "user1" and "user2".
Thanks for the reading ,hope this article helpful !!
Sanjana :)
###