ファイル・ディレクトリ操作で使うコマンド
ファイル・ディレクトリ操作で使うコマンド
ディレクトリを操作するための基本コマンド
![](https://kanda-it-school-kensyu.com/wp-content/uploads/5bd0ed8f88225e330c099f16c40636cb.png)
pwd (present working directory)コマンドで現在の場所を確認
pwd [オプション]
pwdコマンドの主なオプション
![](https://kanda-it-school-kensyu.com/wp-content/uploads/052c52c7c78d1a4a55e0262bb5825d84.png)
pwdコマンドは、非常によく使う便利なコマンドです。自分がどこにいるのかわからなくなったときは、pwdコマンドをササッと実行すべし!
cd(Change Directory)コマンドでディレクトリを移動
cd [-] [移動先ディレクトリ]
![](https://kanda-it-school-kensyu.com/wp-content/uploads/d9422f3058ddfca4a3841f6eaa6a7a06.png)
どこにいても「cd」と実行すれば、自分のホームに戻れる!
ls(List files)コマンドでファイルやディレクトリの一覧表示
引数に指定されたファイルの情報を表示するコマンド
ディレクトリを指定した場合はディレクトリ内のファイルやディレクトリの情報を表示します
ls [オプション] [ファイル名またはディレクトリ名]
lsコマンドの便利なオプション
![](https://kanda-it-school-kensyu.com/wp-content/uploads/ebacf0769cc5dc08cc7eb4efc1b1788c.png)
【練習】
3つのコマンドを使ってみます
[user01@localhost ~]$ pwd /home/user01 [user01@localhost ~]$ cd / [user01@localhost /]$ pwd / [user01@localhost /]$ ls bin dev home lib64 mnt proc run srv tmp var boot etc lib media opt root sbin sys usr [user01@localhost /]$ ls etc/sysconfig anaconda crond iptables-config netconsole run-parts authconfig ebtables-config irqbalance network (以下省略) [user01@localhost /]$ ls /etc/sysconfig anaconda crond iptables-config netconsole run-parts authconfig ebtables-config irqbalance network (以下省略)
図
![](https://kanda-it-school-kensyu.com/wp-content/uploads/17917eb5931945da0ccb0fcf2767fde3.png)
【練習】
[user01@localhost /]$ ls –l 合計 20 lrwxrwxrwx. 1 root root 7 2月 16 20:00 bin -> usr/bin dr-xr-xr-x. 5 root root 4096 2月 16 20:21 boot drwxr-xr-x 20 root root 3240 2月 19 08:06 dev drwxr-xr-x. 76 root root 8192 2月 19 10:29 etc drwxr-xr-x. 8 root root 114 2月 18 13:14 home lrwxrwxrwx. 1 root root 7 2月 16 20:00 lib -> usr/lib lrwxrwxrwx. 1 root root 9 2月 16 20:00 lib64 -> usr/lib6 (以下省略) [user01@localhost /]$ cd [user01@localhost /]$ pwd /home/user01 [user01@localhost ~]$ ls -a . .. .bash_history .bash_logout .bash_profile .bashrc
図
![](https://kanda-it-school-kensyu.com/wp-content/uploads/769d5972b795b59d0205bbcf1e00105d.png)
ファイルの詳細情報
![](https://kanda-it-school-kensyu.com/wp-content/uploads/8693fa3b7118d42044b98fcaa4938373.png)
ファイルを操作するための基本コマンド
![](https://kanda-it-school-kensyu.com/wp-content/uploads/fb5ba06d06e8caeeaddd161b54b4576a.png)
cat(conCATenate)コマンドでファイル内容を表示する
cat [ファイル名]
/etc/hostsファイルを表示してみましょう
[user01@localhost ~]$cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
図
![](https://kanda-it-school-kensyu.com/wp-content/uploads/69789a21680775621c09d78ac2baf2ef.png)
catコマンドの実行
複数ファイルも指定できます
[user01@localhost ~]$cat /etc/hosts /etc/profile 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 # /etc/profile # System wide environment and startup programs, for login setup # Functions and aliases go in /etc/bashrc # It's NOT a good idea to change this file unless you know what you # are doing. It's much better to create a custom.sh shell script in # /etc/profile.d/ to make custom changes to your environment, as this # will prevent the need for merging in future updates. pathmunge () { (以下省略)
図
![](https://kanda-it-school-kensyu.com/wp-content/uploads/0ea61cb175a022cf33d03b926205de47.png)
lessコマンドで1ページずつ表示する
less [ファイル名]
1ページに収まりきれない大きなファイルをページを送りながら表示するとき便利です。
/etc/servicesファイルを表示してみましょう
[user01@localhost ~]$less /etc/services
![](https://kanda-it-school-kensyu.com/wp-content/uploads/393b04889d27eed76a6821fad1378c66.png)
less コマンドの実行
表示結果
# /etc/services: # $Id: services,v 1.55 2013/04/14 ovasik Exp $ # # Network services, Internet style # IANA services version: last updated 2013-04-10 # # Note that it is presently the policy of IANA to assign a single well-known # port number for both TCP and UDP; hence, most entries here have two entries # even if the protocol doesn't support UDP operations. # Updated from RFC 1700, ``Assigned Numbers'' (October 1994). Not all ports # are included, only the more common ones. # # The latest IANA port assignments can be gotten from # http://www.iana.org/assignments/port-numbers (以下省略)
図
![](https://kanda-it-school-kensyu.com/wp-content/uploads/79a9d40092f1ceed502942e90c827580.png)
less コマンドや cat コマンドの実行
/etc/sysconfig以下のファイルを閲覧する場合を考えてください
[user01@localhost ~]$less /etc/sysconfig/network [user01@localhost ~]$cat /etc/sysconfig/crond [user01@localhost ~]$less /etc/sysconfig/firewalld
![](https://kanda-it-school-kensyu.com/wp-content/uploads/aa8e3a7b823f2b349ef585eb123b828b.png)
同じディレクトリで作業が続く場合は、カレントディレクトリを変更すると便利です
[user01@localhost ~]$cd /etc/sysconfig [user01@localhost sysconfig]$
図
![](https://kanda-it-school-kensyu.com/wp-content/uploads/60aab16d1c155cb8eda4fee07872fd17.png)
[user01@localhost sysconfig]$less network [user01@localhost sysconfig]$cat crond [user01@localhost sysconfig]$less firewalld
図
![](https://kanda-it-school-kensyu.com/wp-content/uploads/e61e43e774af869dc66f060f4dcadd8f.png)