Ask Your Question

Removing files in Sage shell using pattern matching

asked 2018-03-03 16:29:45 -0500

ninho gravatar image

updated 2018-03-03 16:30:00 -0500

I have a Sage project with includes some files ending in .sage and some ending in .py. So, I have also created a Makefile to preparse the Sage files, and inside my Makefile I have a clean command, which I want to delete all the files generated after the build process, but keep my own .py files. Therefore, I wrote something like this inside my Makefile:

    shopt -s extglob; 
    rm !(||*.sage)

So, simply, when someone calls make clean I want it to delete all the .py and .pyc files generated after the make process, but keep the two .py files that are written by myself, and also keep all the Sage files. The problem is that it executes the first statement is executed successfully and it activates extended pattern matching. But then, the second state fails at (, it says that it got an unexpected character. To my knowledge, once the extended pattern matching is activated the above shown remove command should work. Any ideas what the problem might be and how to achieve what I want?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2018-03-04 05:49:16 -0500

tmonteil gravatar image

You can replace the two lines with a find command:

    find -type f ! -name ! -name ! -name "*.sage" -exec ls {} \;

Note that it will also look at the subdirectories. Once you are happy with that, you can replace ls with rm.

edit flag offensive delete link more


Thanks, this seems to work nicely!

ninho gravatar imageninho ( 2018-03-04 07:42:10 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2018-03-03 16:29:45 -0500

Seen: 25 times

Last updated: Mar 04