文書の過去の版を表示しています。
よく使うLinuxコマンド
パッケージ管理関連
パッケージ インストール/アップデート/アンインストール [yum]
インストール済パッケージの一覧表示
$ sudo yum list installed 読み込んだプラグイン:fastestmirror, refresh-packagekit Loading mirror speeds from cached hostfile * fedora: ftp.iij.ad.jp * livna: rpm.livna.org * rpmfusion-free: mirror.yandex.ru * rpmfusion-free-updates: mirror.yandex.ru * rpmfusion-nonfree: mirror.yandex.ru * rpmfusion-nonfree-updates: mirror.yandex.ru * updates: ftp.iij.ad.jp インストール済みパッケージ 389-admin.x86_64 1.1.8-4.fc11 @updates 389-admin-console.noarch 1.1.4-1.fc11 @updates 389-admin-console-doc.noarch 1.1.4-1.fc11 @updates ~省略~
インストール
$ sudo yum install package_name
アップデート
$ sudo yum update package_name
アンインストール
$ sudo yum remove package_name
一時的にリポジトリを有効化
$ sudo yum --enablerepo=remi install package_name
パッケージ インストール/アップデート/アンインストール [rpm]
インストール済パッケージの一覧表示
$ rpm -qa
grep との組み合わせ
$ rpm -qa | grep kernel kernel-headers-2.6.19-1.2911.fc6 kernel-2.6.19-1.2911.fc6 kernel-devel-2.6.19-1.2911.fc6
インストール
$ rpm -ivh filename.rpm
vhオプションは処理状況を表示する。
アップデート
$ rpm -Uvh filename.rpm
アンインストール
$rpm -e filename.rpm
パッケージに含まれるファイルの一覧表示
$ rpm -ql phpMyAdmin /etc/httpd/conf.d/phpMyAdmin.conf /etc/phpMyAdmin /etc/phpMyAdmin/config.inc.php /usr/share/doc/phpMyAdmin-2.11.11.1 /usr/share/doc/phpMyAdmin-2.11.11.1/CREDITS /usr/share/doc/phpMyAdmin-2.11.11.1/Documentation.txt 〜省略〜
パッケージの詳細情報を表示
$ rpm -qi python Name : python Relocations: (not relocatable) Version : 2.4.3 Vendor: CentOS Release : 27.el5_5.3 Build Date: 2010年11月12日 03時36分24秒 Install Date: 2010年12月17日 17時52分09秒 Build Host: builder10.centos.org Group : Development/Languages Source RPM: python-2.4.3-27.el5_5.3.src.rpm Size : 22130370 License: PSF - see LICENSE Signature : DSA/SHA1, 2010年11月12日 09時22分06秒, Key ID a8a447dce8562897 URL : http://www.python.org/ Summary : 対話式、オブジェクト指向のインタープリタ言語 Description : Python is an interpreted, interactive, object-oriented programming language often compared to Tcl, Perl, Scheme or Java. Python includes modules, classes, exceptions, very high level dynamic data types and dynamic typing. Python supports interfaces to many system calls and libraries, as well as to various windowing systems (X11, Motif, Tk, Mac and MFC). Programmers can write new built-in modules for Python in C or C++. Python can be used as an extension language for applications that need a programmable interface. This package contains most of the standard Python modules, as well as modules for interfacing to the Tix widget set for Tk and RPM. Note that documentation for Python is provided in the python-docs package.
強制インストール
$rpm -ivh --force --nodeps {ファイル名}:強制インストール(新規インストール & 依存関係無視)
ログイン関連
一時的にユーザを切り替える[su -]
suコマンドはユーザを切り替えて新たなシェルを起動する。
注意:
rootになる際に[su -]の[-]を付け忘れると、現在のユーザの環境が引き継がれてrootに切り替わる。
その為、スーパーユーザなのにcommand not foundと言われることになる。
書式:
su [-flmp] [-c command] [-s shell] [-] [--help] [--version] [user [arg...]]
オプション | 説明 |
---|---|
-c command | ユーザ切り替え後にcommandを実行して元のシェルに戻る。 |
-f | スタートアップファイル(.cshrc)を読み込まない。 |
-, -l | ログインシェルを使用しユーザを切り替える。指定したユーザの環境がロードされる。 |
-m, -p | 環境変数‘HOME’、‘USER’、‘LOGNAME’、‘SHELL’を変更しない。 |
-s shell | /etc/passwdに設定されたuserのシェルの代わりにshellを実行する。 |
–help | 使用方法を表示する。 |
–version | バージョンを表示する。 |
user [arg…] | userを指定する。argはログインシェルに渡す引数を指定する。 |
実行例:
$ su - <- userが未指定なのでrootになる。 パスワード: ********** <- パスワードは表示されない。 # exit <- 終了するには exit または logout を入力する。 logout
圧縮ファイルの圧縮/解凍[tar]
tar.gz(圧縮)
$ tar zcvf filename.tar.gz targetdir/
tar.gz(解凍)
$ tar zxvf filename.tar.gz
tar.bz2(圧縮)
$ tar jcvf filename.tar.bz2 targetdir/
tar.bz2(解凍)
$ tar jxvf filename.tar.bz2
split (ファイルの分割)
$ split -b "数値" "分割したいfile名" "変更後のファイルの接頭語"
※ ファイルのバイト数で変換したい場合 -b 数値 を使用。 数値の最後にmをつけるとメガバイト、kをつけるとキロバイトで数値指定可能 例) split -b 8m “分割したいfile名” “変更後のファイルの接頭語” → 8メガバイトで分割 参考URL: http://www.k4.dion.ne.jp/~mms/unix/linux_com/split.html
特定のディレクトリやファイルを除外
$ tar jcvf filename.tar.bz2 targetdir/ --exclude /exclude/dirname
ファイル&ディレクトリ関連
ディレクトリの作成[mkdir]
書式:
$ mkdir [-pv] [-m mode] [--help] [--version] [--] directory...
オプション | 説明 |
---|---|
-p | directory に指定されたパスに存在しない親フォルダが含まれる場合はエラーとせずに作成する。 |
-v | 作成したディレクトリごとにメッセージ表示。-p と一緒に使用する。 |
-m mode | 作成されるディレクトリのアクセス権を指定する。mode は chmod と同じ。 |
実行例:
$ mkdir tmp $ mkdir -m 755 cgi-bin $ mkdir -pv usr/bin mkdir: created directory `usr' mkdir: created directory `usr/bin'
ファイルの削除[rm]
$ rm fileName.ext rm: remove 通常ファイル 'fileName.ext'? y[Enter]
ファイルの削除(確認なし) [rm -f]
$ rm -f fileName.ext
ディレクトリをサブディレクトリを含めて削除[rm -r]
$ rm -r directoryName rm: descend into directory 'directoryName'? y[Enter] rm: descend into directory 'directoryName/subDirectory'? y[Enter] ...
ディレクトリをサブディレクトリを含めて削除(確認なし)[rm -rf]
$ rm -rf directoryName
ディレクトリの容量
$ du -h -s dir_name 1.6G dir_name
シンボルリンクをはる[ln]
$ ln -s [src] [dist]
例:
$ ln -s /var/www www_root $ ls -al lrwxrwxrwx 1 tomoyan tomoyan 42 11月 1 13:15 2012 www_root-> /var/www $ ln -s /var/www $ ls -al lrwxrwxrwx 1 tomoyan tomoyan 42 11月 1 13:15 2012 www-> /var/www
前方/後方移動が可能なファイル表示[less]
lessコマンドはmoreコマンドに似ているが、とても高機能なページャである。
書式:
less -? less --help less -V less --version less [-[+]aBcCdeEfgGiImMnNqQrsSuUVWwXZ] [-b bufs] [-h lines] [-j line] [-k keyfile] [-K character set] [-{oO} logfile] [-p pattern] [-P prompt] [-t tag] [-T tagsfile] [-x tab] [-y lines] [-[z] lines] [+[+]cmd] [--] [filename]...
オプションの詳細は、man lessを参照。
実行例:
$ less filename.txt <- ファイルの内容が表示されて、↑↓キーで前方/後方移動ができる。 〜省略〜 (END) q <- 表示を終了するにはqキーを入力する。 $ ls -al | less <- コマンドの出力結果を、↑↓キーで移動表示ができる。 〜省略〜 (END) q <- 表示を終了するにはqキーを入力する。 $ less /usr <- ls -al | less と同じ。 合計 408 drwxr-xr-x 16 root root 4096 2008-12-08 14:47 ./ drwxr-xr-x 25 root root 4096 2009-01-22 21:10 ../ drwxr-xr-x 2 root root 4096 2007-06-08 17:07 X11R6/ drwxr-xr-x 2 root root 94208 2009-01-19 21:53 bin/ 〜省略〜 /usr (END) q <- 表示を終了するにはqキーを入力する。
ファイルのみ、ディレクトリのみに chmod
ファイルのみ
$ sudo sh -c 'find . -type f -print | xargs chmod 644'
ディレクトリのみ
$ sudo sh -c 'find . -type d -print | xargs chmod 755'
メール
メールを読む
# mail Heirloom Mail version 12.4 7/29/08. Type ? for help. "/var/spool/mail/root": 13 messages > 1 Cron Daemon Tue Jun 23 12:10 27/1028 "Cron <root@monster> run-part" 2 logwatch@monster Tue Jun 23 13:27 44/1622 "Logwatch for monster (Linux)" 3 logwatch@monster Thu Jun 25 11:04 59/1953 "Logwatch for monster (Linux)" 4 logwatch@monster Thu Jun 25 12:37 59/1953 "Logwatch for monster (Linux)" 5 Mail Delivery Su Fri Jun 26 00:52 77/2443 "Returned mail: see transcrip" 6 logwatch@monster Fri Jun 26 03:10 148/4540 "Logwatch for monster (Linux)" 7 logwatch@monster Sat Jun 27 11:06 115/3263 "Logwatch for monster (Linux)" 8 logwatch@monster Sun Jun 28 03:45 142/4391 "Logwatch for monster (Linux)" 9 logwatch@monster Tue Jul 7 03:17 88/2575 "Logwatch for monster (Linux)" 10 logwatch@monster Wed Jul 8 03:13 105/3058 "Logwatch for monster (Linux)" 11 logwatch@monster Thu Jul 9 03:26 97/2783 "Logwatch for monster (Linux)" 12 logwatch@monster Fri Jul 10 03:13 78/2304 "Logwatch for monster (Linux)" 13 logwatch@monster Sat Jul 11 06:49 102/2945 "Logwatch for monster (Linux)" & t <- メッセージの表示は t コマンドを入力 Message 1: From root@monster.fireball.local Tue Jun 23 12:10:53 2009 Return-Path: <root@monster.fireball.local> Date: Tue, 23 Jun 2009 01:01:36 +0900 From: root@monster.fireball.local (Cron Daemon) To: root@monster.fireball.local Subject: Cron <root@monster> run-parts /etc/cron.hourly Content-Type: text/plain; charset=UTF-8 Auto-Submitted: auto-generated X-Cron-Env: <SHELL=/bin/bash> X-Cron-Env: <PATH=/sbin:/bin:/usr/sbin:/usr/bin> X-Cron-Env: <MAILTO=root> X-Cron-Env: <HOME=/> X-Cron-Env: <LOGNAME=root> X-Cron-Env: <USER=root> Status: RO /etc/cron.hourly/0anacron: cat: /var/spool/anacron/cron.daily: No such file or directory & q <- mailコマンドを終了するには q コマンドを入力