LoginSignup
4
5

More than 5 years have passed since last update.

Linux Tips

Last updated at Posted at 2015-02-09

Listeningしているポートを表示する

$ netstat -vatn

npm install

This command reads package.json file and downloads the following tools into the node_modules directory:


The --depth=14 option just tells Git to pull down only the last 14 commits. This makes the download much smaller and faster.

git clone --depth=14 https://github.com/angular/angular-phonecat.git

nodeをアップする前にアンインストールしておく

sudo npm uninstall npm -g
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
sudo rm -rf /usr/local/include/node /Users/$USER/.npm
sudo rm /usr/local/bin/node
sudo rm /usr/local/share/man/man1/node.1
sudo rm /usr/local/lib/dtrace/node.d
brew install node

npmをアップグレード

npm install -g npm

sort -u -t, -k1,1 customer_data.csv

カンマで区切られている(-t,)customer_data.csvファイルにフィールド1(-k1,1)を対象にユニーク(-u)の行がソートされます。


:pwd
:vimgrep websocket **/*.erl | copen

vimの中に現在のディレクトリを確認して、再帰的に全ての*.erlファイルを対象に"websocket"というパターンを検索して、:copenで結果一覧を見る


$ round()
> {
> echo $(printf %.$2f $(echo "scale=$2;(((10^$2)*$1)+0.5)/(10^$2)" | bc))
> };
21:53:05 [wang => ~/Projects/Web-Programming]
$ round 2 3
2.000

$ round "34/5" 5
6.80000

$ round 57/43 3
1.326

$ echo 'scale=9; 57/43' | bc
1.325581395

round()関数がbcコマンドで四捨五入の計算できるようになっています。


Jekyllをインストール

# yum -y install ruby-devel
# yum install gcc
# gem install jekyll
# gem install rdiscount
# easy_install Pygments
# curl -sL https://rpm.nodesource.com/setup | bash -
# yum install -y nodejs

rpmでプログラムをアンインストール

# rpm -qa | grep epel
epel-release-6-8.noarch
# rpm -e epel-release-6-8.noarch

CentosのMysqlの初期パスワードの設定

$ mysqladmin -u root password NEWPASSWORD

Listening(-l)しているTCPポート(-t)を数字のアドレスで表示する(-n)

$ netstat -lnt

Vimがpythonサポートでコンパイルされているかをチェックする

:python import sys; print(sys.version)

In the shell, what is “ 2>&1 ”?

1 is stdout. 2 is stderr.
Here is one way to remember this construct (altough it is not entirely accurate): at first, 2>1 may look like a good way to redirect stderr to stdout. However, it will actually be interpreted as "redirect stderr to a file named 1". & indicates that what follows is a file descriptor and not a filename. So the construct becomes: 2>&1.

--
${:=}のほうはFOOをfooに代入しちゃいます

$ echo ${foo}

$ echo ${foo:-FOO}
FOO
$ echo ${foo}

$ echo ${foo:=FOO}
FOO
$ echo ${foo}
FOO


VimにdGとすると、カーソルのあるところから最下部までを一気に削除する。


時間を更新する
http://www2.nict.go.jp/aeri/sts/tsp/PubNtp/

$ ntpdate ntp.nict.jp


memoファイルの2行目を出力

$ sed -n "2p" memo


youtubeビデオのmp3音声を抽出して、ダウンロード

$ youtube-dl --extract-audio --audio-format mp3 -l https://www.youtube.com/watch?v=1mjlM_RnsVE


sqlファイルを実行して、csvファイルに導出する

$ mysql --default_character_set=utf8 --prompt='\h mysql>' -hHOSTNAME -DDATABASE -uUSER -pPASSWORD < my_request.sql | sed 's/\t/,/g' > out.csv


CloudStackを管理するコマンドツールcloudmonkeyをインストールする手順

$ git clone https://github.com/apache/cloudstack-cloudmonkey.git
$ cd cloudstack-cloudmonkey/
$ python setup.py build
$ sudo python setup.py install

MySQLの中で、時間の差を計算

> select timestampdiff(second, '2015-04-21 21:20:20', '2015-04-21 21:22:20')


ssh-agentに鍵を追加

$ eval `ssh-agent`
$ ssh-add -l
The agent has no identities.
$ ssh-add ~/.ssh/id_rsa

1Gのランダムのファイルを作成

$ dd if=/dev/urandom of=sample.txt bs=1073741824 count=1
1+0 records in
1+0 records out
1073741824 bytes transferred in 106.761266 secs (10057410 bytes/sec)

Macにcapybaraをインストール

$ brew update
$ brew install qt
$ gem install capybara capybara-webkit headless cucumber rspec --no-ri --no-rdoc

sshでgatewayを通して、serverに入りたいときに.ssh/configファイルに下の設定は必要

Host gateway
     HostName        ***.***.***.***
     User            name
     Port            22
     Protocol        2
     IdentityFile    ~/.ssh/id_rsa

 Host server
     HostName        ***.***.***.***
     User            root
     ProxyCommand    ssh -W  %h:%p gateway
     IdentityFile    ~/.ssh/id_rsa

Bashの文字列配列の使い方。配列をloopさせる

#!/usr/bin/env bash

hosts_arr=("21032773-pascal-cen1" "21032773-tesla-deb1")

for host in "${hosts_arr[@]}"; do
     scp ~/.ssh/config "$host:~/.ssh"
done

ローカルGitレポジトリのURLを調べる

git config --get remote.origin.url

ホストの中のすべてのDBをバックアップ

mysqldump -u root -p --opt --all-databases > alldb.sql
mysqldump -u root -p --all-databases --skip-lock-tables > alldb.sql

dmgファイルでMysqlをインストールした後アンインストール

# rm -rf /usr/local/mysql
# rm -rf /usr/local/mysql-5.5.9-osx10.6-x86_64
# rm -rf /Library/StartupItems/MySQLCOM
# rm -rf /Library/PreferencePanes/MySQL.prefPane

pip2.7をインストール

$ sudo easy_install pip
$ sudo pip2.7 install selenium

--
Javaのインストール場所

$ /usr/libexec/java_home -V
Matching Java Virtual Machines (4):
    1.8.0_45, x86_64:   "Java SE 8"     /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home
    1.7.0_79, x86_64:   "Java SE 7"     /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home
    1.6.0_65-b14-462, x86_64:   "Java SE 6"     /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
    1.6.0_65-b14-462, i386:     "Java SE 6"     /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

~/.bash_profileファイルに下の行を追加して、バージョンをスイッチすることができる

export JAVA_HOME=$(/usr/libexec/java_home -v 1.7.0_79)
4
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5