find . -name config.rb -print0 | xargs -0 grep 'search-thing'
unix
There are 6 posts tagged unix (this is page 1 of 2).
Find to find files newer than
find . -newermt '14 days ago' ## minutes/hours etc.. see date input formats
Json file processing unix tool
When you to view/edit a large json file on the unix command line you can use the jq
tool
pkg install jq
It can be used to pretty-print json
jq . file.json
Or to perform queries on it. (https://stedolan.github.io/jq/manual/)
Quick way to delete to many files in the current directory (argument list to long)
find . -type f -delete
When it's really you can use the folowing perl command to delete all files. (I had a situation with 3 milion files)
cd /folder/to/delete-files
perl -e 'for(<*>){((stat)[9]<(unlink))}'
Reference: https://www.slashroot.in/which-is-the-fastest-method-to-delete-files-in-linux
Cron Job to clear Rails Cache
The rails file cache is something that keeps growing.
Here are some 'handy' snippets.
Delete all files older then 7 days. (replace -delete with -print to test it)
find ./tmp/cache/ -type f -mtime +7 -delete
Delete all empty folders. (mindepth prevents the deletion of the root folder)
find ./tmp/cache/ -type d -empty -delete -mindepth 1
The whenever.rb
I use
job_type :command_in_path, "cd :path && :task :output"
every :day, at: "0:40" do
command_in_path "find ./tmp/cache/ -type f -mtime +7 -delete"
end
every :day, at: "1:10" do
command_in_path "find ./tmp/cache/ -type d -empty -delete -mindepth 1"
end