codea.live
Search…
Projects
Courses
Discord Projects
1PG
2PG
6PG
DBots
Bash
Bash - The Basics
Bash - Do More With Less
RPi 101
Overview
Challenges
Bash - Trash Command
Log Uptime
Hosting
Raspberry Pi
Hosting Services
Internal Pinging
Powered By
GitBook
Bash - Trash Command
Make a trash command in bash, which sends files to a recyle bin, instead of deleting them.
For the solution, we will separate each task into separate commands, and then
combine
then into one trash command.
Move Files Into Trash Folder
Make Trash Folder
In the default directory, we will make a directory for storing trash, then a directory for storing logs.
$
mkdir
~/trash ~/logs
Move Items to Trash
This will move a file to trash. We will
make this configurable
later.
$
mv
file_name.txt ~/trash
Log Actions in a File
Add a Timestamp
This will return a timestamp in the format:
HH:MM:SS
.
$
date
|
cut
--delimiter
" "
--fields
4
13
:37:13
Log Files
$
date
1
>>
timestamp
​
https://help.codea.live/raspberry-pi-hosting/challenges#challenge-make-a-trash-command
​
[Bonus] Make It a Script
Add Script to PATH
$
$
mkdir
~/bin
~/bin/trash
$FILE_NAME
=
""
​
How to add a directory to the PATH?
Ask Ubuntu
RPi 101 - Previous
Challenges
Next - RPi 101
Log Uptime
Last modified
1yr ago
Copy link
Outline
Move Files Into Trash Folder
Make Trash Folder
Move Items to Trash
Log Actions in a File
Add a Timestamp
Log Files
[Bonus] Make It a Script
Add Script to PATH