Finding files recursively and opening them all at once.

I keep a log of my database schema changes and a lot of queries saved in different files and many times I forget what I named them. So it’s expected that I will have a hard time finding the file where I saved that super-long sql query!

I came up with a solution for that. First I must find all the .sql files that I have saved.

[amado@gravedigger Desktop]$ find -type f -name '*.sql'
./qubeviews.sql
./temp.sql
./feedobjects.sql
./6quberouterdbmods.sql
./sql/mods.sql
./sql/q2.sql
./sql/hybridmods.sql
./sql/temp.sql
./sql/fixthemes.sql
./sql/temp-vidapp.sql

Then it ocurred to me, I can search all of their contents in one command!

[amado@gravedigger Desktop]$ find -type f -name '*.sql' | xargs grep -i 'CREATE'
./qubeviews.sql:create or replace view qqqqqq as select * from ffff where trashed > 0;
./qubeviews.sql:create or replace view qqfff as select * from sssss WHERE trashed = 0;
./sql/mods.sql:CREATE OR REPLACE ALGORITHM=MERGE SQL SECURITY INVOKER VIEW .....
./sql/mods.sql:CREATE OR REPLACE ALGORITHM=MERGE SQL SECURITY INVOKER VIEW ....
...

But, actually, I prefer is to open them all at once in bluefish:


[amado@gravedigger Desktop]$ find -type f -name '*.sql' | xargs bluefish &
[2] 21338
[1]   Done                    find -type f -name '*.sql' | xargs bluefish
[amado@gravedigger Desktop]$ error reading list 1 Error opening file: No such file or directory

** (bluefish:21340): WARNING **: no configfile rcfile-2.0, try to convert config files from older versions

config file migration error 1:Error opening file: No such file or directoryerror reading list 1 Error opening file: No such file or directory
Language statistics for SQL from /usr/share/bluefish/bflang//sql.bflang2
reference size            0.00 Kbytes
largest table  1072 (   268.00 Kbytes)
total tables   1088 (   272.00 Kbytes)
contexts          5 (     0.23 Kbytes)
matches         273 (    12.80 Kbytes)
blocks            2 (     0.06 Kbytes)
scancache integrity check done in 0.016000 ms.

Cheers! Happy coding!