I am actively using desktop, so files and folders rapidly accumulate on desktop.
I need a bashrc
way that it checks month on the first day then creates a directory with month name, finally sets it desktop
.
I am actively using desktop, so files and folders rapidly accumulate on desktop.
I need a bashrc
way that it checks month on the first day then creates a directory with month name, finally sets it desktop
.
man crontab
man mkdir
and How do I assign last month's date (year and month only - 2016-07) as a variable?find
that finds all files that are older than one month. Here's an example of a find
that deletes (rm
) older files -
you'll need to adapt it to mv
older files into the created directory: Delete files older than X days +First manually change the config by yourself for this month and run this for the next month.
change_desktop()
{
month=$(date +%B)
last_month=$(date '+%B' --date '1 month ago')
mkdir /home/$USER/Desktop/$month
sed -i "s|Desktop/$last_month|Desktop/$month|" ~/.config/user-dirs.dirs
}
This will create the current month's folder in Desktop and then look for the last month in the config and change it to the current month.
I don't know how to run this piece automatically using the ~/.bashrc
, but you can setup a cron job for the user and let it run every month. Just add this code snippet to a file called change_desktop.sh
add the following code :
#!/bin/sh
change_desktop()
{
month=$(date +%B)
last_month=$(date '+%B' --date '1 month ago')
mkdir /home/$USER/Desktop/$month
sed -i "s|Desktop/$last_month|Desktop/$month|" ~/.config/user-dirs.dirs
}
change_desktop
Then create a cron job for the current user like this :
0 0 12 * * sh /home/$USER/change_desktop.sh
If however you want to do this manually, you can add the first code snippet to the ~/.bashrc
and run change_desktop
in your terminal and it will do the job for you, as it is already a function in your ~/.bashrc
.
I have managed to concoct my own script.
new_desktop="$HOME/Desktop/$(LC_ALL=tr_TR.utf8 date +'%B-%Y')"
if [ ! -d "$new_desktop" ]; then
mkdir "$new_desktop"
xdg-user-dirs-update --set DESKTOP "$new_desktop"
nautilus -q
fi
But I doubt about how reliable it is.
$new_desktop
instead of repeating the same expression over and over...
– Tomáš Pospíšek
Nov 29 '17 at 20:21