Linux 使用笔记(二)

1.Rails Error: ImageMagick/GraphicsMagick is not installed

1
2
brew install graphicsmagick
brew install ImageMagick

Reference:http://stackoverflow.com/questions/29377651/rails-error-imagemagick-graphicsmagick-is-not-installed

2.Transfer file via scp (or sftp) between two Mac

Via scp:
1.Enable Enable SSH System Preferences > Sharing > enable the “Remote Login” feature

2.type scp command

1
scp VirtualBox-5.0.4-102546-OSX.dmg dongmeiliang@192.168.1.255:/Users/dongmeiliang/Documents/
继续阅读

Vim 使用笔记

1.查看帮助

1
:help

2.查看quickref

1
:help quickref

3.语法高亮

1
2
:syn-on      :syntax on              start using syntax highlighting
:syn-off      :syntax off             stop using syntax highlighting

4.Move cursor to its last position

The quickest way is to hit either:

1
2
3
4
5
''
(two apostrophes) or:

``
(two backticks).

5.Show line number

1
:set number

6.Auto indent

1
:set autoindent

7.Set background

1
2
:set background=dark
:set background=light

8.Common move command

1
2
3
4
0, ^ line head
$, g_ line foot
ctl + f forword page
ctl + b back page

9.用vim编辑一个文件,改动了很多内容;最终要保存时却发现没有权限

1
:w !sudo tee % > /dev/null

Reference:http://www.caiyiting.com/blog/2014/vim-sudo.html

10.替换文字时有特殊字符怎么办?

A:用 \ 转义。

1
%s/\/Users\/dongmeiliang\/Sites/\/home\/meiliang\/public_html/g

11.How to reload current file when it has been changed outside of Vim?

A::e , more info at :help :e

12.How to delete all lines of file in Vim?

A:

  1. Type gg to move the cursor to the first line of the file, if it is not already there.
  2. Type dG to delete all the lines.

Reference:How to delete all lines of file in Vim

13.How to select all lines of file in Vim?

A: ggVG

Reference:How do i select all text in Vi/Vim?

扩展阅读

MySQL 使用笔记

1.查看所有的用户

1
2
3
4
5
6
7
$ mysql -u user -p

As of MySQL 5.7.6, use this statement:
mysql> SELECT User, Host, HEX(authentication_string) FROM mysql.user;

Before MySQL 5.7.6, use this statement:
mysql> SELECT User, Host, Password FROM mysql.user;

2.查看用户的权限

1
mysql > SHOW GRANTS FOR 'username'@'localhost';

3.为用户添加操作某个数据库的权限

1
2
mysql > GRANT select, insert, update, delete, index, alter, create ON db2.* TO 'jeffrey'@'localhost';
mysql > GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER ON `xiao_chun`.* TO `xiaochun`@`localhost`;

4.Default options are read from the following files in the given order:

  1. /etc/my.cnf
  2. /etc/mysql/my.cnf
  3. /usr/local/mysql/etc/my.cnf
  4. ~/.my.cnf

5.

1
2
3
4
5
6
mysql > CREATE TABLE IF NOT EXISTS categories (
  id SMALLINT NOT NULL AUTO_INCREMENT,
  category VARCHAR(30) NOT NULL,
  PRIMARY KEY (id),
  UNIQUE KEY category (category)
)ENGINE = MyISAM DEFAULT CHARSET = utf8;
  • VARCHAR(30):can hold up to 30 characters.
  • A UNIQUE index creates a constraint such that all values in the index must be distinct. An error occurs if you try to add a new row with a key value that matches an existing row. For all engines, a UNIQUE index permits multiple NULL values for columns that can contain NULL.
  • DEFAULT CHARSET
继续阅读