Category Archives: Terminal

How to Export Mongo collection without mongoexport command

As we know we can export mongo collection or mutliple collections using mongoexport command
but sometime you don’t have access for mongoexport command for given user.
So you can export mongo collection without using mongoexport command as below.
1. Rurn following command in shell

mongo | tee collection.json

2. And then run following command

db.collection.find({}).forEach(function(f){print(tojson(f,'',true))})

3. Now open file collection.json file and remove extra lines from file(like use db statements etc or command itself)
from start and end of file

Git Ignore File mod changes

I was working with git and facing file mod changes issues every time.
Then i google it and found a way to ignore file mod changes as below
Run following command to ignore file mod changes

git config core.fileMode false

If you want to run this globally for current logged in user then run following command
in terminal

git config --global core.filemode false

How to recover mysql root password

If you are using linux then you can do this very easily
I have not done this on windows machine
First of all get path of mysqld
run following command

which

And it will output like this
/usr/sbin/mysqld
Remember path can be changed
now stop mysql server using following command

sudo service mysql stop

now start mysql with option –skip-grant-tables, –skip-networking as below

sudo /usr/sbin/mysqld --skip-grant-tables  --skip-networking &

Now open new terminal
and run following commands

sudo mysql
FLUSH PRIVILEGES;
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');

Reference:
http://dev.mysql.com/doc/refman/5.6/en/resetting-permissions.html

How to create virtual host using ubuntu/nginx

Create server block file named tutorials.local under path
/etc/nginx/sites-available
and put following contents:

server {
        listen 127.0.0.10:80;
        root /var/www/html/tutorials;
        server_name tutorials.local;
        index index.html index.htm index.php;
        charset utf-8;
    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }
        location = /favicon.ico { access_log off; log_not_found off; }
        location = /robots.txt { access_log off; log_not_found off; }

   access_log off;

   sendfile off;

  client_max_body_size 100m;

 location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        #fastcgi_pass  127.0.0.1:9000;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param REQUEST_SCHEME $scheme;
        fastcgi_intercept_errors off;
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;
    }

    location ~ /\.ht {
        deny all;
    }
}

now run following command in terminal

sudo ln -s /etc/nginx/sites-available/tutorials.local /etc/nginx/sites-enabled/

Now restart nginx

sudo service nginx restart
Create hosts entry
sudo vi /etc/hosts

and add following at the end of file

127.0.0.10 tutorials.local

How to change git url

I was searching about how to change url for git repo.
Then i came to a stackoverflow post http://stackoverflow.com/questions/2432764/change-the-uri-url-for-a-remote-git-repository/2432799#2432799
Its pretty easy to change url with only one command:

git remote set-url origin newurl

And thats it, you can verify newly set url by entering following command:

git remote show origin

How to upload file from local to remote machine or vise versa

How to upload file from local to remote machine??

By using following command we can upload file from local machine to remote machine using terminal.

scp filename.zip username@remote.machine:/destination-derectory

This will use port 22 by default. But if you have to specify custom port then you can use following command.

scp -P 2000 filename.zip username@remote.machine:/destination-derectory

 
By using following command we can download file from remote machine to local machine using terminal.

scp -P 22 user@remoteMachineAddressORIP:/fileDestinatio LocalMachineFolderPAth