deleting specific files in a directory
deleting specific files in a directory
am 03.10.2007 15:50:44 von camotito
Hi,
I am not good using unix-like systems yet. Yesterday I compile a
program in a wrong directory, now I have dozens of files and new
directories in a directory where i also have very few important files
and one important directory.
Could you give just a clue of how to get rid of a lot of all the new
files and directories but keeping my important files. They have just a
couple of hours difference in the modified time field. I tried with
find . -mtime 0 but that acts on files that were modified within a
day, so my important files are included too...
Thanks!
camotito
Re: deleting specific files in a directory
am 03.10.2007 16:18:51 von Stephane CHAZELAS
2007-10-03, 13:50(-00), camotito:
> Hi,
>
> I am not good using unix-like systems yet. Yesterday I compile a
> program in a wrong directory, now I have dozens of files and new
> directories in a directory where i also have very few important files
> and one important directory.
> Could you give just a clue of how to get rid of a lot of all the new
> files and directories but keeping my important files. They have just a
> couple of hours difference in the modified time field. I tried with
> find . -mtime 0 but that acts on files that were modified within a
> day, so my important files are included too...
[...]
Do:
ls -t | sed "s/.*/rm -rf '&'/" > file
Then edit "file" to remove the lines you don't want.
Then run "sh file".
The above assumes none of the filenames contain any single quote
or newline character.
--
Stéphane
Re: deleting specific files in a directory
am 03.10.2007 16:30:43 von Cyrus Kriticos
camotito wrote:
>
> I am not good using unix-like systems yet. Yesterday I compile a
> program in a wrong directory, now I have dozens of files and new
> directories in a directory where i also have very few important files
> and one important directory.
> Could you give just a clue of how to get rid of a lot of all the new
> files and directories but keeping my important files. They have just a
> couple of hours difference in the modified time field. I tried with
> find . -mtime 0 but that acts on files that were modified within a
> day, so my important files are included too...
>
First copy your source code to /tmp/compile and compile it again.
Then:
$ cd /tmp/compile
$ find . -maxdepth 1 -exec echo rm -rf PATH_TO_IMPORTANT_DIR/{} \;
Check output and then remove "echo" and ignore the error:
rm: cannot remove `.' or `..'
--
Best regards | "The only way to really learn scripting is to write
Cyrus | scripts." -- Advanced Bash-Scripting Guide
Re: deleting specific files in a directory
am 03.10.2007 16:37:35 von Bill Marcum
On 2007-10-03, camotito wrote:
> Hi,
>
> I am not good using unix-like systems yet. Yesterday I compile a
> program in a wrong directory, now I have dozens of files and new
> directories in a directory where i also have very few important files
> and one important directory.
> Could you give just a clue of how to get rid of a lot of all the new
> files and directories but keeping my important files. They have just a
> couple of hours difference in the modified time field. I tried with
> find . -mtime 0 but that acts on files that were modified within a
> day, so my important files are included too...
>
If you have GNU or BSD find, you can use find -mmin. Otherwise you can
use touch and find -newer. Or, you could move the few important files
to a new directory.