Search in this blog

Showing posts with label file. Show all posts
Showing posts with label file. Show all posts

Thursday, August 2, 2018

Usage examples of find command to search and remove files

Check current directory for *.log files larger than 1Mb:
$ find . -maxdepth 1 -name '*.log' -type f -size +1M
./parallels.log
Check directory tree up to 5 enclosed folders for *.log files larger than 1Mb, and show their size:
$ find . -maxdepth 5 -name '*.log' -type f -size +1M -exec du -h {} \;
1.4M ./parallels.log
 Check directory tree up to 5 enclosed folders for *.log files larger than 1Mb, and remove them forcibly:
find . -maxdepth 5 -name '*.log' -type f -size +1M -exec rm -f {} \;
Or same using the for loop:
$ for i in $(sudo find ./ -type f -name '*.log'); do
       rm -f $i
  done

Tuesday, February 7, 2017

Create a dummy file of specified size

If you need to create a big file of specified size for testing purposes (for testing Glance or Cinder for example), you can follow next few steps:

  • Install fallocate tool from util-linux
    $ sudo apt-get install util-linux
  • Create your dummy file of specified size. Let's do a file of 1Gb size
    $ fallocate -l 1G dummy.iso
Then you can use it, for example upload to Glance:
$ glance image-create --name dummy.iso --disk-format iso --container-format bare --file dummy.iso