Results 1 to 3 of 3
Dear Linux Forum Community,
Any help would be greatly appreciated, as I have been trying to put together my own solution for sometime... unsuccessfully!
I would like to occasionally run ...
- 08-16-2010 #1Just Joined!
- Join Date
- Aug 2010
- Posts
- 1
Script: Delete files, subsequently copying files
Dear Linux Forum Community,
Any help would be greatly appreciated, as I have been trying to put together my own solution for sometime... unsuccessfully!
I would like to occasionally run a script manually once I've logged into my user account on my Ubuntu minimal installation, before I start my Openbox session using "startx" command.
- Firstly I need the script to delete all files and subdirectories in my home directory, except my "documents", "pictures" and ".fresh" directories.
- Then I need the script to copy all of the contents (files & directories), in the folder ".fresh" to my home directory.
I am sure it's obvious as to what I hope to achieve! Essentially a script that allows me to, before starting my openbox session, returning my setup to just how I liked it when I started out configuring openbox and my apps!
Again, thank you so much for your time.
I understand this is a fairly straightforward task, yet I have proven to myself next to useless in writing such an elementary script.
Thank you for your time!
- 08-16-2010 #2Linux Newbie
- Join Date
- Apr 2007
- Posts
- 119
Here is bash scripting guide that will have all you need to get it done.
- 08-17-2010 #3Just Joined!
- Join Date
- Jul 2006
- Posts
- 6
2nd version:Code:#!/bin/bash if pushd ~; then find -regextype posix-extended -not -regex '\./(documents|pictures|\.fresh)(/.*)?' -exec rm {} \; && \ mv .fresh/* . || \ echo 'something went wrong.' popd fi
Please backup the files first.Code:#!/bin/bash if pushd ~; then if find -type d -regextype posix-extended -not -regex '\./(documents|pictures|\.fresh)(/.*)?' -exec rm -fr {} \;; then if find -type f -regextype posix-extended -not -regex '\./(documents|pictures|\.fresh)(/.*)?' -exec rm -f {} \;; then if compgen -G '.fresh/*' > /dev/null; then mv .fresh/* . || echo 'failed to move files from ./fresh to ~.' fi else echo 'failed to delete files.' fi else echo 'failed to delete directories.' fi popd fi


Reply With Quote