ファイル・ディレクトリ操作で使うコマンド
ファイル・ディレクトリ操作で使うコマンド
ディレクトリを操作するための基本コマンド
pwd (present working directory)コマンドで現在の場所を確認
pwdコマンドの主なオプション
pwdコマンドは、非常によく使う便利なコマンドです。自分がどこにいるのかわからなくなったときは、pwdコマンドをササッと実行すべし!
cd(Change Directory)コマンドでディレクトリを移動
どこにいても「cd」と実行すれば、自分のホームに戻れる!
ls(List files)コマンドでファイルやディレクトリの一覧表示
引数に指定されたファイルの情報を表示するコマンド
ディレクトリを指定した場合はディレクトリ内のファイルやディレクトリの情報を表示します
1 | ls [オプション] [ファイル名またはディレクトリ名] |
lsコマンドの便利なオプション
【練習】
3つのコマンドを使ってみます
1 | [user01@localhost ~]$ pwd |
3 | [user01@localhost ~]$ cd / |
4 | [user01@localhost /]$ pwd |
6 | [user01@localhost /]$ ls |
7 | bin dev home lib64 mnt proc run srv tmp var |
8 | boot etc lib media opt root sbin sys usr |
9 | [user01@localhost /]$ ls etc/sysconfig |
10 | anaconda crond iptables-config netconsole run-parts |
11 | authconfig ebtables-config irqbalance network (以下省略) |
12 | [user01@localhost /]$ ls /etc/sysconfig |
13 | anaconda crond iptables-config netconsole run-parts |
14 | authconfig ebtables-config irqbalance network (以下省略) |
図
【練習】
1 | [user01@localhost /]$ ls –l |
3 | lrwxrwxrwx. 1 root root 7 2月 16 20:00 bin -> usr/bin |
4 | dr-xr-xr-x. 5 root root 4096 2月 16 20:21 boot |
5 | drwxr-xr-x 20 root root 3240 2月 19 08:06 dev |
6 | drwxr-xr-x. 76 root root 8192 2月 19 10:29 etc |
7 | drwxr-xr-x. 8 root root 114 2月 18 13:14 home |
8 | lrwxrwxrwx. 1 root root 7 2月 16 20:00 lib -> usr/lib |
9 | lrwxrwxrwx. 1 root root 9 2月 16 20:00 lib64 -> usr/lib6 |
11 | [user01@localhost /]$ cd |
12 | [user01@localhost /]$ pwd |
14 | [user01@localhost ~]$ ls -a |
15 | . .. .bash_history .bash_logout .bash_profile .bashrc |
図
ファイルの詳細情報
ファイルを操作するための基本コマンド
cat(conCATenate)コマンドでファイル内容を表示する
/etc/hostsファイルを表示してみましょう
1 | [user01@localhost ~]$ cat /etc/hosts |
2 | 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 |
3 | ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 |
図
catコマンドの実行
複数ファイルも指定できます
1 | [user01@localhost ~]$ cat /etc/hosts /etc/profile |
2 | 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 |
3 | ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 |
図
lessコマンドで1ページずつ表示する
1ページに収まりきれない大きなファイルをページを送りながら表示するとき便利です。
/etc/servicesファイルを表示してみましょう
1 | [user01@localhost ~]$ less /etc/services |
less コマンドの実行
表示結果
図
less コマンドや cat コマンドの実行
/etc/sysconfig以下のファイルを閲覧する場合を考えてください
1 | [user01@localhost ~]$ less /etc/sysconfig/network |
2 | [user01@localhost ~]$ cat /etc/sysconfig/crond |
3 | [user01@localhost ~]$ less /etc/sysconfig/firewalld |
同じディレクトリで作業が続く場合は、カレントディレクトリを変更すると便利です
1 | [user01@localhost ~]$ cd /etc/sysconfig |
2 | [user01@localhost sysconfig]$ |
図
1 | [user01@localhost sysconfig]$ less network |
2 | [user01@localhost sysconfig]$ cat crond |
3 | [user01@localhost sysconfig]$ less firewalld |
図
NEXT>> シンボリックリンクとハードリンク(ファイルを別名でアクセスする)