Tutorial 2: File Management
Learn how to remove files, move directories, set permissions, and create your first bash script.
Remove hello.txt from the desktop
Working in our firstfolder
directory, we'll use the absolute path to remove the file.
$ rm /home/tom/Desktop/hello.txt

Move the firstfolder to Desktop
First navigate to home directory, then move the folder to Desktop.
$ cd ~ $ mv firstfolder/ /home/tom/Desktop/

Create script.sh in firstfolder
Navigate to the moved directory and create a new script file using nano.
$ cd Desktop/firstfolder $ nano script.sh

Writing Your First Bash Script
Add this content to your script.sh file in nano:
#!/bin/bash echo "Hello! $(whoami)" echo "The current date/time is: $(date)"

Script Explanation
-
1
#!/bin/bash
- This shebang specifies the interpreter to use (Bash). -
2
echo
- Prints messages to the console output. -
3
$(whoami)
- Command substitution executing thewhoami
command. -
4
$(date)
- Command substitution executing thedate
command.
Make and Run the Script
First make the script executable, then run it.
$ chmod a+x script.sh $ ./script.sh
Expected Output:
The current date/time is: [current date/time]

Congratulations!
You've successfully learned how to manage files, set permissions, and create your first bash script!