Magento2: Re generate css file in pub/static folder

Before deleting pub/static make a backup of pub/static/.htaccess and restore it again. otherwise your all css and js will show 404 error!

  1. Remove pub/static (keep the .htaccess backed up and copy it again)
  2. Remove var/cache
  3. Remove var/composer_home
  4. Remove var/generation
  5. Remove var/page_cache
  6. Remove var/view_preprocessed
  7. Run php bin/magento setup:static-content:deploy

answers here don't mention that you shouldn't delete the .htaccess in the pub/static folder.

to delete all files except the .htacces enter the pub/static directory and run

find . -depth -name .htaccess -prune -o -delete

then you can run

rm -rf var/cache/ var/generation/ var/page_cache/ var/view_preprocessed/ 

I have just delete the css files from pub/static folder and run the command:

php bin/magento setup:static-content:deploy

It will re generate the same file with latest changes.