https://www.garron.me/en/bits/find-string-recursively-in-all-files-linux-mac-grep.html
1 |
grep -r "string" . |
If you want to search for the string without caring about upper or lower case.
1 |
grep -ri "string" . |
https://www.garron.me/en/bits/find-string-recursively-in-all-files-linux-mac-grep.html
1 |
grep -r "string" . |
If you want to search for the string without caring about upper or lower case.
1 |
grep -ri "string" . |
ref – http://stackoverflow.com/questions/1806868/linux-replacing-spaces-in-the-file-names
for f in *.png; do echo mv “$f” “${f/_*_/_}”; done
ubuntu:
rm -rf lampp
ref – http://stackoverflow.com/questions/4811738/cron-job-log-how-to-log
http://stackoverflow.com/questions/15395479/why-ive-got-no-crontab-entry-on-os-x-when-using-vim
30 * * * * /Users/rickytsao/Desktop/run_email_to_admin >> /Users/rickytsao/Desktop/chron-log.txt
http://askubuntu.com/questions/86822/how-can-i-copy-the-contents-of-a-folder-to-another-folder-in-a-different-directo
For local paths:
1 |
cp -a node-apn-TEST_LIVE-gary/. node-apn-TEST_LIVE-dean/ |
For full paths:
1 |
cp -a /home/projects/node-apn-TEST_LIVE-gary/. /home/projects/node-apn-TEST_LIVE-dean |
ref – http://www.mkyong.com/mongodb/how-to-install-mongodb-on-ubuntu/
This guide shows you how to install MongoDB on Ubuntu.
Ubuntu 12.10
MongoDB 2.2.3
1. Add 10gen package to source.list.d
Ubuntu 12 comes with a “mongo” package, but not the latest version.
$ sudo apt-cache search mongodb
mongodb
mongodb-clients
mongodb-dev
mongodb-server
It’s recommended to add 10gen package to /etc/apt/sources.list.d, as it contains the latest stable MongoDB. Create a /etc/apt/sources.list.d/mongo.list file, and declared the 10gen distro.
$ sudo vim /etc/apt/sources.list.d/mongo.list
/etc/apt/sources.list.d/mongo.list
##10gen package location
deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen
2. Add GPG Key
10gen package required GPG key, imports it :
$ sudo apt-key adv –keyserver keyserver.ubuntu.com –recv 7F0CEB10
If you didn’t imports the GPG key, apt-get update will hits following error message :
GPG error: http://downloads-distro.mongodb.org dist Release:
The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY 9ECBEC467F0CEB10
3. Update package
Update your apt-get list.
$ sudo apt-get update
Search “mongodb” again, a new 10gen package is appearing now. Get the “mongodb-10gen“, it contains the latest stable MongoDB.
$ sudo apt-cache search mongodb
mongodb
mongodb-clients
mongodb-dev
mongodb-server
mongodb-10gen
mongodb18-10gen
mongodb20-10gen
4. Install mongodb-10gen
Everything is ready, now you can Install MongoDB :
note see (http://stackoverflow.com/questions/12480935/install-mongodb-10gen-failed-with-apt-get) if you get an overwrite error.
$ sudo apt-get install mongodb-10gen
5. Where is MongoDB?
MongoDB is installed and started.
$ ps -ef | grep mongo
mongodb 5262 1 0 15:27 ? 00:00:14 /usr/bin/mongod –config /etc/mongodb.conf
mkyong 5578 3994 0 16:29 pts/0 00:00:00 grep –color=auto mongo
$ mongo -version
MongoDB shell version: 2.2.3
All MongoDB executable files are stored at /usr/bin/
$ ls -ls /usr/bin | grep mongo
4220 -rwxr-xr-x 1 root root 4317928 Feb 2 08:11 mongo
10316 -rwxr-xr-x 1 root root 10563336 Feb 2 08:11 mongod
10320 -rwxr-xr-x 1 root root 10563664 Feb 2 08:11 mongodump
10284 -rwxr-xr-x 1 root root 10526736 Feb 2 08:11 mongoexport
10324 -rwxr-xr-x 1 root root 10567768 Feb 2 08:11 mongofiles
10296 -rwxr-xr-x 1 root root 10539056 Feb 2 08:11 mongoimport
10272 -rwxr-xr-x 1 root root 10514544 Feb 2 08:11 mongooplog
10272 -rwxr-xr-x 1 root root 10518512 Feb 2 08:11 mongoperf
10320 -rwxr-xr-x 1 root root 10563632 Feb 2 08:11 mongorestore
6644 -rwxr-xr-x 1 root root 6802848 Feb 2 08:11 mongos
10312 -rwxr-xr-x 1 root root 10556560 Feb 2 08:11 mongostat
10272 -rwxr-xr-x 1 root root 10515856 Feb 2 08:11 mongotop
The “mongodb control script” is generated at /etc/init.d/mongodb
$ ls -ls /etc/init.d | grep mongo
0 lrwxrwxrwx 1 root root 21 Feb 2 08:11 mongodb -> /lib/init/upstart-job
The MongoDB config file is at /etc/mongodb.conf
/etc/mongodb.conf
# mongodb.conf
# Where to store the data.
# Note: if you run mongodb as a non-root user (recommended) you may
# need to create and set permissions for this directory manually,
# e.g., if the parent directory isn’t mutable by the mongodb user.
dbpath=/var/lib/mongodb
#where to log
logpath=/var/log/mongodb/mongodb.log
logappend=true
#port = 27017
#……
6. Controlling MongoDB
Some commands to control the MongoDB.
Starting MongoDB
$ sudo service mongodb start
Stoping MongoDB
$ sudo service mongodb stop
Restarting MongoDB
$ sudo service mongodb restart
$ mongo
MongoDB shell version: 3.0.4
connecting to: test
> show dbs
bookAPI 0.078GB
local 0.078GB
my_database_name 0.078GB
Don’t worry about “connecting to” … that’s just the default database Mongo decides to use if you don’t specify one on the command line, which we didn’t because it’s not important right now. It doesn’t actually even create the “test” database unless you add a record. It’d be totally fine to just work in that database for right now, but let’s make one of our own. In your Mongo console, type the following:
1 |
use test1 |
Now we’re using the database “test1.” Nothing actually exists yet. To make the database exist, we have to add some data. We’re going to start off by doing that right inside of the Mongo client.
MongoDB uses JSON for its structure.
Let’s add a record to our collection. Note that we are currently ‘on’ database test1. So whatever we insert will be into database ‘test1’. Our data format will thus look like this:
1 |
db.usercollection.insert({ "username" : "testuser1" }) |
Something important to note here: that “db” stands for our database, which as mentioned above we’ve defined as “test1”. The “usercollection” is the name of our collection in this database. Its kind of like ‘table’ in a SQL database. Every JSON we insert is like a row. Note that there wasn’t a step where we created the “usercollection” collection. That’s because the first time we add to it, it’s going to be auto-created. OK, Hit enter. Assuming everything went right, you should see … nothing. That’s not very exciting, so type this:
1 |
db.usercollection.find().pretty() |
You access the table name by saying ‘db’ for current database, then db.tableName, which in our case is users, so it would be db.users. Finally, we use find() to display all data so in the end it would be:
db.users.find()
output:
{ “_id” : ObjectId(“559261a6250879f91747a6a5”), “name” : “MODULUS ADMIN”, “age” : 42, “roles” : [ “admin”, “moderator”, “user” ], “__v” : 0 }
>
> db.users.find( { age: { $gt: 25 } } )
{ “_id” : ObjectId(“559261a6250879f91747a6a5”), “name” : “MODULUS ADMIN”, “age” : 42, “roles” : [ “admin”, “moderator”, “user” ], “__v” : 0 }
> db.users.find( { age: { $gt: 43 } } )
>
1 |
db.yourCollection.remove( { } ) |
> db.users.remove({name:”MODULUS ADMIN”})
WriteResult({ “nRemoved” : 1 })
> db.users.find()
>
> db.users.count()
0
If the collection does not exist, the insert() method creates the collection.
> db.users.insert( { name: “ricky”, age: 35, roles:”admin” } )
db.{collection name}.drop()
use my_database_name
switched to db my_database_name
> db.dropDatabase()
{ “dropped” : “my_database_name”, “ok” : 1 }
first show all database
> show dbs;
PersonDatabase 0.078GB
local 0.078GB
Then pick a database to use
> use PersonDatabase;
switched to db PersonDatabase
Then show all collections inside that database
> show collections
people
system.indexes
Then do db.{collection name}.find()
> db.people.find()
{ “_id” : ObjectId(“55939a0800f3e7343974a41f”), “name” : “Ricky-dude”, “username” : “rtsao”, “password” : “compaq”, “admin” : true, “__v” : 0 }
{ “_id” : ObjectId(“55939adc2b0f71473b38b3d6”), “name” : “Ricky-dude”, “username” : “hadoken”, “password” : “compaq”, “admin” : true, “__v” : 0 }
{ “_id” : ObjectId(“55939b81648f93fd3bb1f4f1”), “name” : “Ricky-dude”, “username” : “shoryuken”, “password” : “compaq”, “admin” : true, “__v” : 0 }
db.badmintonEvents.insert({ “attendee_name” : “badminton_2-18-2016”, “date” : ISODate(“2016-02-18T00:00:00Z”), “description” : “8:00pm at baishizhou” })
ref – http://www.mkyong.com/mongodb/how-to-install-mongodb-on-mac-os-x/
First download the mongo database file from its website. Be default, your mac should put it into your ~/Download folder. Then open up a terminal.
You cd into the download directory. Then you unzip the tgz file. Then you move the folder into directory /usr/local/mongdb
cd ~/Download
$ tar xzf mongodb-osx-x86_64-2.2.3.tgz
$ sudo mv mongodb-osx-x86_64-2.2.3 /usr/local/mongodb
You should now see the mongodb folder with bin and data in the directory /usr/local/mongdb.
By default, MongoDB write/store data into the /data/db folder, you need to create this folder manually and assign proper permission. We make the directory, then check who the current User is. Then give permission to the current user for directory /data/db
$ sudo mkdir -p /data/db
$ whoami
rickytsao
$ sudo chown rickytsao /data/db
Now, the directory /data/db is ready for mongodb data writes.
Now we need to open up our .bash_profile and add a PATH entry. This is so that we can run mongod, and mongo from the /usr/local/mongodb/bin directory without having to type out the whole path.
$ cd ~
$ pwd
/Users/rickytsao
$ touch .bash_profile
$ vim .bash_profile
Then type in the following into the .bash_profile file:
export MONGO_PATH=/usr/local/mongodb
export PATH=$PATH:$MONGO_PATH/bin
restart terminal, then:
$ mongo -version
MongoDB shell version: 2.2.3
In terminal 1:
$ mongod
MongoDB starting : pid=34022 port=27017 dbpath=/data/db/ 64-bit host=mkyong.local
//…
waiting for connections on port 27017
In terminal 2:
$ mongo
MongoDB shell version: 2.2.3
connecting to: test
> show dbs
local (empty)
If you happen to get a “rlimits warning”, just type just type “ulimit -n 2048” or use something higher.
npm install mongoose –save
Move file ‘home.js’ from parent dir to current dir
../ means parent directory 1 level
. means current directory
ref – http://stackoverflow.com/questions/11177954/how-do-i-completely-uninstall-node-js-and-reinstall-from-beginning-mac-os-x
Homebrew is a package manager for the Mac — it makes installing most open source sofware (like Node) as simple as writing brew install node. You can learn more about Homebrew at the Homebrew website. To install Homebrew just open Terminal and type:
1 |
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" |
You’ll see messages in the Terminal explaining what you need to do to complete the installation process.
result:
Press RETURN to continue or any other key to abort
==> /usr/bin/sudo /bin/chmod g+rwx /usr/local/lib/pkgconfig /usr/local/share/man/man3 /usr/local/share/man/man5 /usr/local/share/man/man7
WARNING: Improper use of the sudo command could lead to data loss
or the deletion of important system files. Please double-check your
typing when using sudo. Type “man sudo” for more information.
To proceed, enter your password, or type Ctrl-C to abort.
Password:
==> /usr/bin/sudo /bin/mkdir /Library/Caches/Homebrew
==> /usr/bin/sudo /bin/chmod g+rwx /Library/Caches/Homebrew
==> Downloading and installing Homebrew…
remote: Counting objects: 3590, done.
remote: Compressing objects: 100% (3433/3433), done.
remote: Total 3590 (delta 28), reused 667 (delta 19), pack-reused 0
Receiving objects: 100% (3590/3590), 2.86 MiB | 322.00 KiB/s, done.
Resolving deltas: 100% (28/28), done.
From https://github.com/Homebrew/homebrew
* [new branch] master -> origin/master
Checking out files: 100% (3594/3594), done.
HEAD is now at 231c429 unac: fix audit warnings
==> Installation successful!
==> Next steps
Run brew help
to get started
Rickys-MacBook-Pro:~ $
If its your first time installing nodeJS, then skip this part go on to the standard installation instructions below
However, if you have previous versions of nodeJS installed, you need to remove previous node folders and files.
Usually every time you do an install, and if there are any issues, it will print out for you…something like this:
brew link
step did not complete successfullyJust solve the error, do a “brew uninstall node”, and start the installation all over again.
Installing Node.js and NPM is pretty straightforward using Homebrew. Homebrew handles downloading, unpacking and installing Node and NPM on your system. The whole process (after you have XCode and Homebrew installed) should only take you a few minutes.
Open the Terminal app and type brew install node
Sit back and wait. Homebrew downloads some files and installs them. And that’s it.
After you entered the command you should see the installation go under way:
==> Downloading https://homebrew.bintray.com/bottles/node-0.12.4.yosemite.bottle.tar.
Already downloaded: /Library/Caches/Homebrew/node-0.12.4.yosemite.bottle.tar.gz
==> Pouring node-0.12.4.yosemite.bottle.tar.gz
==> Caveats
Bash completion has been installed to:
/usr/local/etc/bash_completion.d
==> Summary
🍺 /usr/local/Cellar/node/0.12.4: 2590 files, 28M
Rickys-MacBook-Pro:~ rickytsao$
After installation, check what version of Node and NPM you’ve just installed:
To see if Node is installed, type node -v in Terminal. This should print the version number so you’ll see something like this v0.10.31.
To see if NPM is installed, type npm -v in Terminal. This should print the version number so you’ll see something like this 1.4.27
New versions of Node and NPM come out frequently. You can use Homebrew to update the software it installs.
Make sure Homebrew has the latest version of the Node package. In Terminal type brew update
Upgrade Node: brew upgrade node
You can use Homebrew to uninstall packages that it installed: brew uninstall node