Home Previous Buy Me a Beer

Linux Commands

Master essential Linux commands with interactive examples and visual guides.

Tutorial 2: File Management

Learn how to remove files, move directories, set permissions, and create your first bash script.

rm
mv
chmod
nano

Remove hello.txt from the desktop

Working in our firstfolder directory, we'll use the absolute path to remove the file.

terminal
$ rm /home/tom/Desktop/hello.txt
rm command

Move the firstfolder to Desktop

First navigate to home directory, then move the folder to Desktop.

terminal
$ cd ~
$ mv firstfolder/ /home/tom/Desktop/
mv command

Create script.sh in firstfolder

Navigate to the moved directory and create a new script file using nano.

terminal
$ cd Desktop/firstfolder
$ nano script.sh
nano editor

Writing Your First Bash Script

Add this content to your script.sh file in nano:

script.sh
#!/bin/bash
echo "Hello! $(whoami)"
echo "The current date/time is: $(date)"
bash script example

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 the whoami command.
  • 4
    $(date) - Command substitution executing the date command.

Make and Run the Script

First make the script executable, then run it.

terminal
$ chmod a+x script.sh
$ ./script.sh

Expected Output:

Hello! tom
The current date/time is: [current date/time]
running the script

Congratulations!

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