2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Linux】コマンド集

Last updated at Posted at 2023-06-24

今回はLinuxのコマンドについてまとめました。
以下にコマンドと内容を記載します。

前提

  • はじめは以下のような構成になっています。
sample/
    └─	linux_sample/
            └─	command.txt
            └─	.hidden.txt
  • 基本的にlinux_sampleディレクトリでコマンドを実行していきます。
  • ホームディレクトリは/Users/meです。

コマンド

cdコマンド

$ cd ディレクトリ名

ディレクトリに移動

例:linux_sample/からsample/に移動

linux_sample $ cd ..
sample $

..はひとつ上の階層を表す

cdだけの場合はホームディレクトリに移動する

pwdコマンド

$ pwd

現在の階層パスを表示

例:現在の階層パスを表示

linux_sample $ pwd
/Users/me/XXX/YYY/sample/linux_sample

lsコマンド

$ ls

カレントディレクトリにあるファイル・ディレクトリを表示
(-aをつけると隠しファイル・隠しディレクトリも表示)

例:linux_sample/にあるファイルをすべて表示

linux_sample $ ls -a
.		..		.DS_Store	.hidden.txt	command.txt

mkdirコマンド

$ mkdir ディレクトリ名

ディレクトリを作成

例:dir1/を作成

linux_sample $ mkdir dir1
linux_sample $ ls
command.txt	dir1

rmdirコマンド

$ rmdir ディレクトリ名

空のディレクトリを削除

dir1/を削除

linux_sample $ rmdir dir1
linux_sample $ ls
command.txt

catコマンド

$ cat ファイル名

ファイルの中身を全て表示

command.txtの中身を表示

linux_sample $ cat command.txt
Hello World

lessコマンド

$ less ファイル名

ファイルの中身の一部を表示(続きはEnterで表示される)
そのため、ファイルの中身が長い場合はcatよりこっちの方がいいかも
Vimモードになるので、最後は:qなどで抜ける

tailsコマンド

$ tails ファイル名

ファイルの中身の末尾10行を表示
-n 行数をつけると表示する行数を指定できる

touchコマンド

$ touch ファイル名

ファイルを作成

例:command2.txtを作成

linux_sample $ touch command2.txt
linux_sample $ ls
command.txt	command2.txt

rmコマンド

$ rm ファイル名

ファイルを削除
-rをつけるとディレクトリを削除

GUIでの削除と違いゴミ箱に行かず完全に消去されるため、復元できない

例:command2.txtを削除

linux_sample $ rm command2.txt
linux_sample $ ls
command.txt

mvコマンド

  • 名前変更
$ mv 変更前ファイル・ディレクトリ名 変更後ファイル・ディレクトリ名

ファイル・ディレクトリ名を変更

例:command.txtをcommand1.txtに変更

linux_sample $ mv command.txt command1.txt
linux_sample $ ls
command1.txt
  • 移動
$ mv ファイル・ディレクトリ名 移動先ディレクトリ

ファイル・ディレクトリを移動

cpコマンド

$ cp コピー元ファイル名 コピー後ファイル名

ファイルを名前を指定してコピー

ディレクトリのコピーはできない

commmand1.txtのコピー

linux_sample $ cp command1.txt command1_copy.txt
linux_sample $ ls
command1.txt		command1_copy.txt

lnコマンド

$ ln 元ファイル・ディレクトリ名 リンク名 

例:command1.txtのリンクを作成

linux_sample $ ln command1.txt command1-link.txt
linux_sample $ ls
command1-link.txt	command1.txt		command1_copy.txt
linux_sample $ cat command1_copy.txt
Hello World

findコマンド

$ find ファイル名・ディレクトリ名

ファイルを検索

例:command1.txtを検索

linux_sample $ find command1.txt
command1.txt

chmodコマンド

$ chmod オプション ファイル名・ディレクトリ名

権限を変更

command1.txtをすべてのユーザーに対して読み出し権限のみにする

chmod 444 command1.txt

chownコマンド

$ chown 所有者or所有者:グループ ファイル名orディレクトリ名

所有権を変更

例:linux_sampleディレクトリの所有者をyamadaに変更する

chown yamada linux_sample

psコマンド

$ ps

起動しているプロセスを表示

例:起動しているプロセスを表示

linux_sample $ ps
  PID TTY           TIME CMD
  522 ttys000    0:00.03 -bash
  545 ttys001    0:00.03 -bash
  601 ttys002    0:00.02 -bash
  614 ttys003    0:00.67 -bash
29659 ttys004    0:00.02 -bash

killコマンド

$ kill プロセスID

プロセスを終了させる

例:プロセスの終了

$ ps ax | grep gedit
16619 ?        Sl     0:01 gedit
$ kill 16619
2
0
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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?