テキストの操作
vi/vim/view コマンド
ファイルを編集する。
$ vi example.txtキーバインドは次のとおり。
i: 挿入モードEsc: コマンドモード:q!: 保存せず強制終了:wq: 保存して終了:0: カーソルを先頭に移動:$: カーソルを末尾に移動:123: カーソルを指定した行数に移動:set number: 行数を表示/abc: 下方向に指定した文字列を検索?abc: 上方向に指定した文字列を検索n: 次を検索N: 逆順に次を検索x: カーソルの位置にある文字を削除dd: カーソルのある行を削除u: 1 つ前の状態に戻すyy: カーソルのある行をコピーp: 貼り付け
ファイルを表示する。
$ view /vagrant/Vagrantfilecat コマンド
ファイルを表示する。
$ cat /vagrant/Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
~
$ cat /vagrant/Vagrantfile | wc
70 457 3092ファイルを連結する。
$ cat /vagrant/Vagrantfile /vagrant/Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
~
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
~
$ cat /vagrant/Vagrantfile /vagrant/Vagrantfile | wc
140 914 6184less コマンド
テキストを表示する。
less /vagrant/Vagrantfileキーバインドは次のとおり。
q: 終了↓: 1 行進む↑: 1 行戻るf: 1 画面進むb: 1 画面戻るd: 1 / 2 画面進むu: 1 / 2 画面戻るg: 先頭へ移動G: 末尾へ移動123g: 指定した行数へ移動/abc: 下方向に指定した文字列を検索?abc: 上方向に指定した文字列を検索n: 次を検索N: 逆順に次を検索-N: 行番号を表示
more コマンド
テキストを表示する。
more /vagrant/Vagrantfilehead コマンド
テキストの先頭( 10 行)を表示する。
$ head /vagrant/Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation atテキストの先頭( 5 行)を表示する。
$ head -5 /vagrant/Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles fortail コマンド
テキストの末尾( 10 行)を表示する。
$ tail /vagrant/Vagrantfile
# information on available options.
# Enable provisioning with a shell script. Additional provisioners such as
# Ansible, Chef, Docker, Puppet and Salt are also available. Please see the
# documentation for more information about their specific syntax and use.
# config.vm.provision "shell", inline: <<-SHELL
# apt-get update
# apt-get install -y apache2
# SHELL
endテキストの末尾( 5 行)を表示する。
$ tail -5 /vagrant/Vagrantfile
# config.vm.provision "shell", inline: <<-SHELL
# apt-get update
# apt-get install -y apache2
# SHELL
endテキストの末尾を監視する。
$ tail -f /var/log/syslogwc コマンド
テキストの行数、単語数をカウントする。
wc /vagrant/Vagrantfile
70 457 3092 /vagrant/Vagrantfileテキストの行数をカウントする。
wc -l /vagrant/Vagrantfile
70 /vagrant/Vagrantfilesort コマンド
テキストの行をソートする。
$ sort /vagrant/Vagrantfile
#
#
#
~
テキストの行を逆順にソートする。
$ sort -r /vagrant/Vagrantfile
# your network.
# you're doing.
# within the machine from a port on the host machine. In the example below,
# within the machine from a port on the host machine and only allow access
# vi: set ft=ruby :
~
テキストをソートし、重複した行を削除する。
$ sort -u /vagrant/Vagrantfile
#
# accessing "localhost:8080" will access port 80 on the guest machine.
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# Ansible, Chef, Docker, Puppet and Salt are also available. Please see the
~
-r オプションでテキストの行を数値でソートする。
-k オプションでソートに使用する項目を指定する。
$ ls -al | sort -nr -k 5
-rw------- 1 vagrant vagrant 25931 Jan 29 18:45 .bash_history
-rw------- 1 vagrant vagrant 9223 Jan 29 18:30 .viminfo
drwxr-xr-x 3 root root 4096 Aug 15 2019 ..
drwxr-xr-x 2 vagrant vagrant 4096 Jan 28 14:34 .vim
drwxr-xr-x 10 vagrant vagrant 4096 Jan 30 01:13 .
~
uniq コマンド
テキストの重複した行を削除する。
$ sort /vagrant/Vagrantfile | uniqテキストの重複した行のみを表示する。
$ sort /vagrant/Vagrantfile | uniq -d
#
# Create a forwarded port mapping which allows access to a specific portテキストの重複していない行のみを表示する。
$ sort /vagrant/Vagrantfile | uniq -ufile コマンド
ファイルの形式を表示する。
$ file /vagrant/Vagrantfile
/vagrant/Vagrantfile: ASCII text, with CRLF line terminators