nitinriaan
New Member
Steps for creating user-defined commands:-
1. Enter the command “sudo -i” //which will log in to root
2. Enter the password: now it will be logged n to the root
3. Change the directory to bin type “cd bin”
4. Using the nano command create a file that should be the name of the user-defined command “nano commandName”
5. Write the script that you want to execute and save it
6. Change the permission of the created file to make it executable to all users “chmod +x fileName”
7. Now you log out from the root by typing the exit command.
8. Now run the created command it will run if any error occurs repeat the steps.
We created 3 user-defined commands they are as follows:
i. cat1
ii. mydate
iii. desktop
i. cat1
code:
echo "contents of $1 as follows:"
cat $1
echo "------END------"
ii. mydate
code:
echo "Today's date:"
date +"%d-%m-%y"
echo "Day:"; date +%A
echo "Month:"; date +%B
echo "-----DONE-----"
exec bash
iii.desktop
code:
echo "Welcome to Desktop"
cd ~/Desktop
exec bash
1. Enter the command “sudo -i” //which will log in to root
2. Enter the password: now it will be logged n to the root
3. Change the directory to bin type “cd bin”
4. Using the nano command create a file that should be the name of the user-defined command “nano commandName”
5. Write the script that you want to execute and save it
6. Change the permission of the created file to make it executable to all users “chmod +x fileName”
7. Now you log out from the root by typing the exit command.
8. Now run the created command it will run if any error occurs repeat the steps.
We created 3 user-defined commands they are as follows:
i. cat1
ii. mydate
iii. desktop
i. cat1
code:
echo "contents of $1 as follows:"
cat $1
echo "------END------"
ii. mydate
code:
echo "Today's date:"
date +"%d-%m-%y"
echo "Day:"; date +%A
echo "Month:"; date +%B
echo "-----DONE-----"
exec bash
iii.desktop
code:
echo "Welcome to Desktop"
cd ~/Desktop
exec bash