Categories
Server

Unix: Fast Find and Replace in VIM

I configure a lot of files, and most of the time it’s all about copying an old config file, edit a few variables and save it.
Take for example a NGINX virtualhost file. You already have a website running and you want to run another site with similar configuration.

So you copy the existing virtualhost and give it a name, then opens it and want to change everyting that says “my-first-website” with “my-second-website”.

The following command is doing just that in one shot!

:%s/my-first-website/my-second-website/g

BOOM!

You have notice it’s using some regular expression quantifier “g” to tell VIM to replace all occurence of “my-first-website” with “my-second-website”.

Categories
Server

Have you mooed today?

Ever wondered how you can get a cow in your terminal?
(Linux Easter Eggs)

Here’s how to do it (On Ubuntu):
apt-get install moo

There is a lot more to explore.
I suggest you do a research for Linux Easter Eggs!

Categories
Server

Unix: Remove tons of files

You may not be able to delete lot of files with the command “rm”.
The error could be “Argument list too long”.

One possible solution is to use the “find” command and the “-delete” option.

The following command is deleting all files in the /deleteme directory.
It deletes also all files in subdirectories but leaves subdirectories structure intact.

find /deleteme -type f -print -delete

Categories
Server

MySQL: create database with user and password

The following instructions are to create:

  • one database
  • one user with all privileges on this database

Connect to MySQL with root user.

mysql -u root -p

Create a database and give it a name.
For this example we name it “db_name”.

create database db_name;

Create a user.
For this example we name it “db_users”;

create user db_user;

Now one stone three birds:
– we are giving all privileges to the user “db_user” on all the tables of the database “db_name”.
– we say that the user can login only locally.
– we create the user password.

grant all on db_name.* to 'db_user'@'localhost' identified by 'db_password';

To test it, first log out from root.

exit

Connect as your new user to the new database

mysql -u db_user -p db_name

Congratulations!