Linux ターミナル コマンドのファイル ディレクトリ操作と Dos 関連コマンドの比較

目次

序文

基本コマンド(ファイルディレクトリ関連)

cdコマンド

【英語ヘルプ】

【対応するDosコマンド】

pwdコマンド

【英語ヘルプ】

【対応するDosコマンド】

lsコマンド

【英語ヘルプ】

【対応するDosコマンド】

ツリーコマンド

【英語ヘルプ】

【対応するDosコマンド】

mkdirコマンド

【英語ヘルプ】

【対応するDosコマンド】

rmdir/rmコマンド

【英語ヘルプ】

【対応するDosコマンド】

cpコマンド

【英語ヘルプ】

【対応するDosコマンド】

タッチコマンド

【英語ヘルプ】

【対応するDosコマンド】

mvコマンド

【英語ヘルプ】

【対応するDosコマンド】

chmodコマンド

【英語ヘルプ】

【対応するDosコマンド】

要約する


序文

Linux はオープン ソース オペレーティング システムであり、Linux システムを使用するための基礎となるため、そのディレクトリ構造は非常に重要です。この記事では、Linux システムでファイルやディレクトリを操作するための一般的なコマンドをいくつか紹介します。その一部には Dos にも対応するコマンドがあります (同様の機能を参照)。

もう 1 つの違いは、Linux システムのコマンドは大文字と小文字が区別され、通常はすべて小文字であるのに対し、Dos システムのコマンドは大文字と小文字が区別されず、コマンド名の大文字と小文字が混在しても同じです (cd CD cD Cd など)。同じ注文です。

基本コマンド(ファイルディレクトリ関連)

cdコマンド

cd: 現在の作業ディレクトリを変更します。絶対パスまたは相対パスを使用できます。

ルート ディレクトリに入るコマンドは cd /、ユーザーのホーム ディレクトリに入るコマンドは cd ~ です。
このうち「/」と「~」はそれぞれ現在のユーザーのルートディレクトリとホームディレクトリを表します。

絶対パスモードの切り替え:cd /home/user/documents
相対パスモードの切り替え:cd ../user/documents
ここで、絶対パスとはルートディレクトリから始まるパスを指し、相対パスとはカレントディレクトリから始まるパスを指します。

【英語ヘルプ】

hann@HannYang:~$ cd --help
cd: cd [-L|[-P [-e]] [-@]] [dir]
    Change the shell working directory.

    Change the current directory to DIR.  The default DIR is the value of the
    HOME shell variable.

    The variable CDPATH defines the search path for the directory containing
    DIR.  Alternative directory names in CDPATH are separated by a colon (:).
    A null directory name is the same as the current directory.  If DIR begins
    with a slash (/), then CDPATH is not used.

    If the directory is not found, and the shell option `cdable_vars' is set,
    the word is assumed to be  a variable name.  If that variable has a value,
    its value is used for DIR.

    Options:
      -L        force symbolic links to be followed: resolve symbolic
                links in DIR after processing instances of `..'
      -P        use the physical directory structure without following
                symbolic links: resolve symbolic links in DIR before
                processing instances of `..'
      -e        if the -P option is supplied, and the current working
                directory cannot be determined successfully, exit with
                a non-zero status
      -@        on systems that support it, present a file with extended
                attributes as a directory containing the file attributes

    The default is to follow symbolic links, as if `-L' were specified.
    `..' is processed by removing the immediately previous pathname component
    back to a slash or the beginning of DIR.

    Exit Status:
    Returns 0 if the directory is changed, and if $PWD is set successfully when
    -P is used; non-zero otherwise.

【対応するDosコマンド】

cd 同じ名前、同じ機能、形式: cd ディレクトリ パス

カレントディレクトリ名を表示、またはカレントディレクトリを変更します。または長い名前の chdir

CHDIR [/D] [ドライブ:][パス]
CHDIR [..]
CD [/D] [ドライブ:][パス]
CD [..]

  .. 親ディレクトリに変更することを指定します。

「CD drive:」と入力すると、指定したドライブ上の現在のディレクトリが表示されます。
引数を指定せずに「CD」と入力すると、現在のドライブとディレクトリが表示されます。

/D スイッチを使用すると、ドライブの現在のディレクトリを変更するだけでなく、
現在のドライブも変更できます。

コマンド拡張が有効な場合、CHDIR は次のように変化します。

現在のディレクトリ文字列は、ディスク名の大文字と小文字を区別するように変換されます。したがって、
ディスク上のケースが次の場合、 CD C:\TEMP は現在のディレクトリを
C:\Tempに設定します。


CHDIR コマンドはスペースを区切り文字として扱わないため、ディレクトリ名を、スペースを含むが引用符を含まないサブディレクトリ名に変更することができます。例えば:

     cd \winnt\profiles\ユーザー名\プログラム\スタート メニュー

と同じ:

     cd "\winnt\profiles\ユーザー名\プログラム\スタート メニュー"

拡張機能を無効にして、上記のコマンドを入力する必要があります。


pwdコマンド

pwd: 現在の作業ディレクトリのパスを表示します。たとえば、pwd現在の作業ディレクトリへのフルパスが表示されます。

pwd コマンドは、現在の作業ディレクトリ (つまり、現在のディレクトリ) の絶対パスを表示するために使用されます。Linux システムでは、各ユーザーが独自のホーム ディレクトリを持ち、最初にシステムにログインしたとき、そのユーザーがいるディレクトリがユーザー自身のホーム ディレクトリになります。

hann@HannYang:~$ pwd
/home/hann

【英語ヘルプ】

hann@HannYang:~$ pwd --help
pwd: pwd [-LP]
    Print the name of the current working directory.

    Options:
      -L        print the value of $PWD if it names the current working
                directory
      -P        print the physical directory, without any symbolic links

    By default, `pwd' behaves as if `-L' were specified.

    Exit Status:
    Returns 0 unless an invalid option is given or the current directory
    cannot be read.

【対応するDosコマンド】

Dos には個別の pwd コマンドはありません。パラメータを指定せずに CD コマンドを使用するだけです。

C:\Users\hann>CD
C:\Users\hann

C:\Users\hann>cD
C:\Users\hann

C:\Users\hann>Cd
C:\Users\hann

C:\Users\hann>cd
C:\Users\hann


lsコマンド

ls: 現在のディレクトリまたは指定されたディレクトリ内のファイルとディレクトリのリストを表示します。

ls コマンドのパラメータは非常に複雑で、デフォルトではファイル名のみの短い形式で表示されますが、パラメータ -l を使用すると、ファイルを含むディレクトリ内のファイルとディレクトリのリストを長い形式で表示することができます。サイズ、権限、所有者、変更時刻など。

【英語ヘルプ】

hann@HannYang:~$ ls --help
Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.

Mandatory arguments to long options are mandatory for short options too.
  -a, --all                  do not ignore entries starting with .
  -A, --almost-all           do not list implied . and ..
      --author               with -l, print the author of each file
  -b, --escape               print C-style escapes for nongraphic characters
      --block-size=SIZE      with -l, scale sizes by SIZE when printing them;
                               e.g., '--block-size=M'; see SIZE format below
  -B, --ignore-backups       do not list implied entries ending with ~
  -c                         with -lt: sort by, and show, ctime (time of last
                               modification of file status information);
                               with -l: show ctime and sort by name;
                               otherwise: sort by ctime, newest first
  -C                         list entries by columns
      --color[=WHEN]         colorize the output; WHEN can be 'always' (default
                               if omitted), 'auto', or 'never'; more info below
  -d, --directory            list directories themselves, not their contents
  -D, --dired                generate output designed for Emacs' dired mode
  -f                         do not sort, enable -aU, disable -ls --color
  -F, --classify             append indicator (one of */=>@|) to entries
      --file-type            likewise, except do not append '*'
      --format=WORD          across -x, commas -m, horizontal -x, long -l,
                               single-column -1, verbose -l, vertical -C
      --full-time            like -l --time-style=full-iso
  -g                         like -l, but do not list owner
      --group-directories-first
                             group directories before files;
                               can be augmented with a --sort option, but any
                               use of --sort=none (-U) disables grouping
  -G, --no-group             in a long listing, don't print group names
  -h, --human-readable       with -l and -s, print sizes like 1K 234M 2G etc.
      --si                   likewise, but use powers of 1000 not 1024
  -H, --dereference-command-line
                             follow symbolic links listed on the command line
      --dereference-command-line-symlink-to-dir
                             follow each command line symbolic link
                               that points to a directory
      --hide=PATTERN         do not list implied entries matching shell PATTERN
                               (overridden by -a or -A)
      --hyperlink[=WHEN]     hyperlink file names; WHEN can be 'always'
                               (default if omitted), 'auto', or 'never'
      --indicator-style=WORD  append indicator with style WORD to entry names:
                               none (default), slash (-p),
                               file-type (--file-type), classify (-F)
  -i, --inode                print the index number of each file
  -I, --ignore=PATTERN       do not list implied entries matching shell PATTERN
  -k, --kibibytes            default to 1024-byte blocks for disk usage;
                               used only with -s and per directory totals
  -l                         use a long listing format
  -L, --dereference          when showing file information for a symbolic
                               link, show information for the file the link
                               references rather than for the link itself
  -m                         fill width with a comma separated list of entries
  -n, --numeric-uid-gid      like -l, but list numeric user and group IDs
  -N, --literal              print entry names without quoting
  -o                         like -l, but do not list group information
  -p, --indicator-style=slash
                             append / indicator to directories
  -q, --hide-control-chars   print ? instead of nongraphic characters
      --show-control-chars   show nongraphic characters as-is (the default,
                               unless program is 'ls' and output is a terminal)
  -Q, --quote-name           enclose entry names in double quotes
      --quoting-style=WORD   use quoting style WORD for entry names:
                               literal, locale, shell, shell-always,
                               shell-escape, shell-escape-always, c, escape
                               (overrides QUOTING_STYLE environment variable)
  -r, --reverse              reverse order while sorting
  -R, --recursive            list subdirectories recursively
  -s, --size                 print the allocated size of each file, in blocks
  -S                         sort by file size, largest first
      --sort=WORD            sort by WORD instead of name: none (-U), size (-S),
                               time (-t), version (-v), extension (-X)
      --time=WORD            with -l, show time as WORD instead of default
                               modification time: atime or access or use (-u);
                               ctime or status (-c); also use specified time
                               as sort key if --sort=time (newest first)
      --time-style=TIME_STYLE  time/date format with -l; see TIME_STYLE below
  -t                         sort by modification time, newest first
  -T, --tabsize=COLS         assume tab stops at each COLS instead of 8
  -u                         with -lt: sort by, and show, access time;
                               with -l: show access time and sort by name;
                               otherwise: sort by access time, newest first
  -U                         do not sort; list entries in directory order
  -v                         natural sort of (version) numbers within text
  -w, --width=COLS           set output width to COLS.  0 means no limit
  -x                         list entries by lines instead of by columns
  -X                         sort alphabetically by entry extension
  -Z, --context              print any security context of each file
  -1                         list one file per line.  Avoid '\n' with -q or -b
      --help     display this help and exit
      --version  output version information and exit

The SIZE argument is an integer and optional unit (example: 10K is 10*1024).
Units are K,M,G,T,P,E,Z,Y (powers of 1024) or KB,MB,... (powers of 1000).

The TIME_STYLE argument can be full-iso, long-iso, iso, locale, or +FORMAT.
FORMAT is interpreted like in date(1).  If FORMAT is FORMAT1<newline>FORMAT2,
then FORMAT1 applies to non-recent files and FORMAT2 to recent files.
TIME_STYLE prefixed with 'posix-' takes effect only outside the POSIX locale.
Also the TIME_STYLE environment variable sets the default style to use.

Using color to distinguish file types is disabled both by default and
with --color=never.  With --color=auto, ls emits color codes only when
standard output is connected to a terminal.  The LS_COLORS environment
variable can change the settings.  Use the dircolors command to set it.

Exit status:
 0  if OK,
 1  if minor problems (e.g., cannot access subdirectory),
 2  if serious trouble (e.g., cannot access command-line argument).

GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
Report ls translation bugs to <https://translationproject.org/team/>
Full documentation at: <https://www.gnu.org/software/coreutils/ls>
or available locally via: info '(coreutils) ls invocation'

【対応するDosコマンド】

DIR [ドライブ:][パス][ファイル名] [/A[[:]属性]] [/B​​] [/C] [/D] [/L] [/N] [/O[[:]並べ替え順序
  ] ] [/P] [/Q] [/R] [/S] [/T[[:]タイムフィールド]] [/W] [/X] [/4]

  [ドライブ:][パス][ファイル名] は、
              リストするドライブ、ディレクトリ、ファイルを指定します。

  /A 指定された属性を持つファイルを表示します。
  属性 D ディレクトリ R 読み取り専用ファイル
               H 隠しファイル A すぐにアーカイブできるファイル
               S システム ファイル I コンテンツのないインデックス ファイル
               L 再解析ポイント O オフライン ファイル
               - 「no」の接頭辞
  /B 空の形式を使用する (ヘッダー情報や概要なし) )。
  /C ファイル サイズで千の区切り記号を表示します。これはデフォルト値です。区切り文字の表示を無効にするには、/-C を使用します
              。
  /D ブロードと同じですが、ファイルは列ごとにソートされます。
  /L 小文字を使用します。
  /N ファイル名が右端にある新しい長いリスト形式。
  /O ファイルをソート順にリストします。
  並べ替え順序 N 名前順 (アルファベット順) S サイズ順 (最小値から最大値)
               E 拡張子順 (アルファベット順) D 日付/時刻順 (最初から最後)
               G グループ ディレクトリを最初 - 逆順にプレフィックス
  /P (各情報画面の後に一時停止) 。
  /Q ファイルの所有者を表示します。
  /R ファイルの代替データ ストリームを表示します。
  /S 指定したディレクトリとすべてのサブディレクトリ内のファイルを表示します。
  /T 文字フィールドの表示または並べ替えに使用される時刻を制御します。 期間
  C 作成時刻
              A 最終アクセス時刻
              W 最終書き込み時刻
  /W ワイド リスト形式を使用します。
  /X 8dot3 以外のファイル名に対して生成された短縮名を表示します。形式は /N で、
              長い名前の前に短い名前が挿入されます。短縮名がない場合は、空白が表示されます
              。
  /4 は年を 4 桁で表示します

スイッチは DIRCMD 環境変数で事前に設定できます。接頭辞付きスイッチは、接頭辞 - (ダッシュ) を付けることで
置き換えられます。たとえば、/-W。


ツリーコマンド

Tree: 現在のディレクトリ内のファイルとディレクトリのリストをツリー構造で表示します。

【英語ヘルプ】

hann@HannYang:~$ tree --help
usage: tree [-acdfghilnpqrstuvxACDFJQNSUX] [-H baseHREF] [-T title ]
        [-L level [-R]] [-P pattern] [-I pattern] [-o filename] [--version]
        [--help] [--inodes] [--device] [--noreport] [--nolinks] [--dirsfirst]
        [--charset charset] [--filelimit[=]#] [--si] [--timefmt[=]<f>]
        [--sort[=]<name>] [--matchdirs] [--ignore-case] [--fromfile] [--]
        [<directory list>]
  ------- Listing options -------
  -a            All files are listed.
  -d            List directories only.
  -l            Follow symbolic links like directories.
  -f            Print the full path prefix for each file.
  -x            Stay on current filesystem only.
  -L level      Descend only level directories deep.
  -R            Rerun tree when max dir level reached.
  -P pattern    List only those files that match the pattern given.
  -I pattern    Do not list files that match the given pattern.
  --ignore-case Ignore case when pattern matching.
  --matchdirs   Include directory names in -P pattern matching.
  --noreport    Turn off file/directory count at end of tree listing.
  --charset X   Use charset X for terminal/HTML and indentation line output.
  --filelimit # Do not descend dirs with more than # files in them.
  --timefmt <f> Print and format time according to the format <f>.
  -o filename   Output to file instead of stdout.
  ------- File options -------
  -q            Print non-printable characters as '?'.
  -N            Print non-printable characters as is.
  -Q            Quote filenames with double quotes.
  -p            Print the protections for each file.
  -u            Displays file owner or UID number.
  -g            Displays file group owner or GID number.
  -s            Print the size in bytes of each file.
  -h            Print the size in a more human readable way.
  --si          Like -h, but use in SI units (powers of 1000).
  -D            Print the date of last modification or (-c) status change.
  -F            Appends '/', '=', '*', '@', '|' or '>' as per ls -F.
  --inodes      Print inode number of each file.
  --device      Print device ID number to which each file belongs.
  ------- Sorting options -------
  -v            Sort files alphanumerically by version.
  -t            Sort files by last modification time.
  -c            Sort files by last status change time.
  -U            Leave files unsorted.
  -r            Reverse the order of the sort.
  --dirsfirst   List directories before files (-U disables).
  --sort X      Select sort: name,version,size,mtime,ctime.
  ------- Graphics options -------
  -i            Don't print indentation lines.
  -A            Print ANSI lines graphic indentation lines.
  -S            Print with CP437 (console) graphics indentation lines.
  -n            Turn colorization off always (-C overrides).
  -C            Turn colorization on always.
  ------- XML/HTML/JSON options -------
  -X            Prints out an XML representation of the tree.
  -J            Prints out an JSON representation of the tree.
  -H baseHREF   Prints out HTML format with baseHREF as top directory.
  -T string     Replace the default HTML title and H1 header with string.
  --nolinks     Turn off hyperlinks in HTML output.
  ------- Input options -------
  --fromfile    Reads paths from files (.=stdin)
  ------- Miscellaneous options -------
  --version     Print version and exit.
  --help        Print usage and this help message and exit.
  --            Options processing terminator.

【対応するDosコマンド】

同名の関数ツリーと同様に、Linux のツリーパラメータはより豊富です

ドライブまたはパスのフォルダー構造をグラフィカルに表示します。

TREE [ドライブ:][パス] [/F] [/A]

   /F 各フォルダー内のファイル名を表示します。
   /A 拡張文字の代わりに ASCII 文字を使用します。


mkdirコマンド

mkdir: 新しいディレクトリを作成します。例: という
mkdir new_directory名前の新しいディレクトリnew_directory

【英語ヘルプ】

hann@HannYang:~$ cd --help
cd: cd [-L|[-P [-e]] [-@]] [dir]
    Change the shell working directory.

    Change the current directory to DIR.  The default DIR is the value of the
    HOME shell variable.

    The variable CDPATH defines the search path for the directory containing
    DIR.  Alternative directory names in CDPATH are separated by a colon (:).
    A null directory name is the same as the current directory.  If DIR begins
    with a slash (/), then CDPATH is not used.

    If the directory is not found, and the shell option `cdable_vars' is set,
    the word is assumed to be  a variable name.  If that variable has a value,
    its value is used for DIR.

    Options:
      -L        force symbolic links to be followed: resolve symbolic
                links in DIR after processing instances of `..'
      -P        use the physical directory structure without following
                symbolic links: resolve symbolic links in DIR before
                processing instances of `..'
      -e        if the -P option is supplied, and the current working
                directory cannot be determined successfully, exit with
                a non-zero status
      -@        on systems that support it, present a file with extended
                attributes as a directory containing the file attributes

    The default is to follow symbolic links, as if `-L' were specified.
    `..' is processed by removing the immediately previous pathname component
    back to a slash or the beginning of DIR.

    Exit Status:
    Returns 0 if the directory is changed, and if $PWD is set successfully when
    -P is used; non-zero otherwise.

【対応するDosコマンド】

mkdir は同じ名前と機能を持つか、短い名前 md を使用します。

ディレクトリを作成します。

MKDIR [ドライブ:]パス
MD [ドライブ:]パス

コマンド拡張が有効な場合、MKDIR は次のように変更されます。

MKDIR は、必要に応じてパス内に中間ディレクトリを作成します。例: \a が
存在しないと仮定すると、次のようになります。

    mkdir \a\b\c\d

そして:

    mkdir \a
    chdir \a
    mkdir b
    chdir b
    mkdir c
    chdir c
    mkdir d

同じ。拡張機能が無効になっている場合は、「mkdir \a\b\c\d」と入力する必要があります。


rmdir/rmコマンド

rmdir: 空のディレクトリを削除します。例: という
rmdir empty_directory名前の空のディレクトリは削除されますempty_directory

rm: ファイルまたはディレクトリを削除するために使用されます。ディレクトリとそのすべてのサブファイルおよびサブディレクトリを削除したい場合は、-r パラメータを指定して rm コマンドを使用できます (例: rm -r example)。

【英語ヘルプ】

hann@HannYang:~$ rmdir --help
Usage: rmdir [OPTION]... DIRECTORY...
Remove the DIRECTORY(ies), if they are empty.

      --ignore-fail-on-non-empty
                  ignore each failure that is solely because a directory
                    is non-empty
  -p, --parents   remove DIRECTORY and its ancestors; e.g., 'rmdir -p a/b/c' is
                    similar to 'rmdir a/b/c a/b a'
  -v, --verbose   output a diagnostic for every directory processed
      --help     display this help and exit
      --version  output version information and exit

GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
Report rmdir translation bugs to <https://translationproject.org/team/>
Full documentation at: <https://www.gnu.org/software/coreutils/rmdir>
or available locally via: info '(coreutils) rmdir invocation'
hann@HannYang:~$ rm --help
Usage: rm [OPTION]... [FILE]...
Remove (unlink) the FILE(s).

  -f, --force           ignore nonexistent files and arguments, never prompt
  -i                    prompt before every removal
  -I                    prompt once before removing more than three files, or
                          when removing recursively; less intrusive than -i,
                          while still giving protection against most mistakes
      --interactive[=WHEN]  prompt according to WHEN: never, once (-I), or
                          always (-i); without WHEN, prompt always
      --one-file-system  when removing a hierarchy recursively, skip any
                          directory that is on a file system different from
                          that of the corresponding command line argument
      --no-preserve-root  do not treat '/' specially
      --preserve-root[=all]  do not remove '/' (default);
                              with 'all', reject any command line argument
                              on a separate device from its parent
  -r, -R, --recursive   remove directories and their contents recursively
  -d, --dir             remove empty directories
  -v, --verbose         explain what is being done
      --help     display this help and exit
      --version  output version information and exit

By default, rm does not remove directories.  Use the --recursive (-r or -R)
option to remove each listed directory, too, along with all of its contents.

To remove a file whose name starts with a '-', for example '-foo',
use one of these commands:
  rm -- -foo

  rm ./-foo

Note that if you use rm to remove a file, it might be possible to recover
some of its contents, given sufficient expertise and/or time.  For greater
assurance that the contents are truly unrecoverable, consider using shred.

GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
Report rm translation bugs to <https://translationproject.org/team/>
Full documentation at: <https://www.gnu.org/software/coreutils/rm>
or available locally via: info '(coreutils) rm invocation'

【対応するDosコマンド】

rmdir と rd は Dos では同じコマンドですが、Linux では rmdir と rm は 2 つの異なるコマンドです。

ディレクトリを削除します。

RMDIR [/S] [/Q] [ドライブ:]パス
RD [/S] [/Q] [ドライブ:]パス

    /S
            ディレクトリ自体に加えて、指定したディレクトリの下にあるすべてのサブディレクトリとファイルを削除します。ディレクトリツリーを削除するために使用されます。

    /Q 静かモード、/S を指定すると、確認を求めずにディレクトリ ツリーを削除します


cpコマンド

cp: ファイルまたはディレクトリをコピーします。

cp: ファイルまたはディレクトリをコピーします。たとえば、cp file1 file2コピーしますディレクトリとその内容をコピーするには、のようなオプションを使用する必要がありますfile1file2-rcp -r dir1 dir2

cp コマンドは、ファイルまたはディレクトリをコピーするために使用されます。たとえば、 cp コマンドを使用して、「example」という名前のディレクトリを現在のディレクトリにコピーできます。コマンドは cp -r example です。

【英語ヘルプ】

hann@HannYang:~$ cd --help
cd: cd [-L|[-P [-e]] [-@]] [dir]
    Change the shell working directory.

    Change the current directory to DIR.  The default DIR is the value of the
    HOME shell variable.

    The variable CDPATH defines the search path for the directory containing
    DIR.  Alternative directory names in CDPATH are separated by a colon (:).
    A null directory name is the same as the current directory.  If DIR begins
    with a slash (/), then CDPATH is not used.

    If the directory is not found, and the shell option `cdable_vars' is set,
    the word is assumed to be  a variable name.  If that variable has a value,
    its value is used for DIR.

    Options:
      -L        force symbolic links to be followed: resolve symbolic
                links in DIR after processing instances of `..'
      -P        use the physical directory structure without following
                symbolic links: resolve symbolic links in DIR before
                processing instances of `..'
      -e        if the -P option is supplied, and the current working
                directory cannot be determined successfully, exit with
                a non-zero status
      -@        on systems that support it, present a file with extended
                attributes as a directory containing the file attributes

    The default is to follow symbolic links, as if `-L' were specified.
    `..' is processed by removing the immediately previous pathname component
    back to a slash or the beginning of DIR.

    Exit Status:
    Returns 0 if the directory is changed, and if $PWD is set successfully when
    -P is used; non-zero otherwise.

【対応するDosコマンド】

copy の主な機能は同じで、Linux では略して cp と呼ばれます。

1 つ以上のファイルを別の場所にコピーします。

コピー [/D] [/V] [/N] [/Y | /-Y] [/Z] [/L] [/A | /B ] ソース [/A | /B]
     [+ ソース [/A | /B] [+ ...]] [宛先 [/A | /B]]

  source はコピーするファイルを指定します。
  /A ASCII テキスト ファイルを示します。
  /Bはバイナリファイルを意味します。
  /D 作成される宛先ファイルの復号化を許可します
  。 destination 新しいファイルのディレクトリまたはファイル名、あるいはその両方を指定します。
  /V 新しいファイルが正しく書き込まれたことを検証します。
  /N 8dot3 以外の名前のファイルをコピーする場合は、
               可能な限り短いファイル名を使用します。
  /Y 既存のオブジェクト ファイルを上書きするかどうかを確認するプロンプトを使用しません
               。
  /-Y
               プロンプトを使用して、既存のオブジェクト ファイルを上書きするかどうかを確認します。
  /Z ネットワーク上のファイルを再起動可能モードでコピーします。
/L ソースがシンボリック リンクの場合、
               ソース リンクが指す実際のファイルではなく、リンクをターゲットにコピーします。

コマンド ライン スイッチ /Y は、COPYCMD 環境変数に事前に設定できます。
これは、コマンド ラインで /-Y によってオーバーライドされる場合があります。COPY
コマンドがバッチ スクリプトで実行されない限り、デフォルトは
上書き時にプロンプ​​トを表示する必要があります。

ファイルを追加するには、ターゲットに 1 つのファイルを指定し、
ソースに複数のファイルを指定します (ワイルドカードまたは file1+file2+file3 形式)。


タッチコマンド

touch: 新しい空のファイルを作成するか、既存のファイルのアクセス時刻と変更時刻を更新します。たとえば、という名前の新しい
touch file1ファイルfile1が作成されたり、アクセス時刻や変更時刻touch file1が更新されたりします。file1

【英語ヘルプ】

hann@HannYang:~$ touch --help
Usage: touch [OPTION]... FILE...
Update the access and modification times of each FILE to the current time.

A FILE argument that does not exist is created empty, unless -c or -h
is supplied.

A FILE argument string of - is handled specially and causes touch to
change the times of the file associated with standard output.

Mandatory arguments to long options are mandatory for short options too.
  -a                     change only the access time
  -c, --no-create        do not create any files
  -d, --date=STRING      parse STRING and use it instead of current time
  -f                     (ignored)
  -h, --no-dereference   affect each symbolic link instead of any referenced
                         file (useful only on systems that can change the
                         timestamps of a symlink)
  -m                     change only the modification time
  -r, --reference=FILE   use this file's times instead of current time
  -t STAMP               use [[CC]YY]MMDDhhmm[.ss] instead of current time
      --time=WORD        change the specified time:
                           WORD is access, atime, or use: equivalent to -a
                           WORD is modify or mtime: equivalent to -m
      --help     display this help and exit
      --version  output version information and exit

Note that the -d and -t options accept different time-date formats.

GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
Report touch translation bugs to <https://translationproject.org/team/>
Full documentation at: <https://www.gnu.org/software/coreutils/touch>
or available locally via: info '(coreutils) touch invocation'

【対応するDosコマンド】

同じ名前の対応するファイルがない場合は、copy コマンドを使用して新しい空のファイルを作成できます。

copy con newfile.txt では、手動で Ctrl+Z を入力して Enter キーを押す必要があります。

さらに、 echo . > newfile.txt を使用することもでき、このコマンドは 1 つのステップで完了します。エコーの後のピリオド記号の間にスペースがあってはならず、スペースがある場合はポイントがファイルに書き込まれることに
注意してください

C:\Users\hann>echo > 新しいファイル.txt

C:\Users\hann>「newfile.txt」と入力


C:\Users\hann>dir newfile.txt
 ドライブ C のボリュームは、
 シリアル番号 1E34-A256 の Windows ボリュームです。

 C:\Users\hann のディレクトリ

2023/08/26 12:16 3 newfile.txt
               1 ファイル 3 バイト
               0 ディレクトリ 123,609,210,880 利用可能なバイト

欠点: 空行を含むゼロ以外のバイトの「空の」ファイルが作成される


mvコマンド

mv: ファイルまたはディレクトリを移動または名前変更します。

mv: ファイルまたはディレクトリを移動します。名前の変更にも使用できます。たとえば、名前を に
mv file1 file2 変更し、 を削除しますディレクトリとその内容を移動するには、などのオプションを使用する必要がありますfile1file2file1
-rmv -r dir1 dir2

【英語ヘルプ】

hann@HannYang:~$ cd --help
cd: cd [-L|[-P [-e]] [-@]] [dir]
    Change the shell working directory.

    Change the current directory to DIR.  The default DIR is the value of the
    HOME shell variable.

    The variable CDPATH defines the search path for the directory containing
    DIR.  Alternative directory names in CDPATH are separated by a colon (:).
    A null directory name is the same as the current directory.  If DIR begins
    with a slash (/), then CDPATH is not used.

    If the directory is not found, and the shell option `cdable_vars' is set,
    the word is assumed to be  a variable name.  If that variable has a value,
    its value is used for DIR.

    Options:
      -L        force symbolic links to be followed: resolve symbolic
                links in DIR after processing instances of `..'
      -P        use the physical directory structure without following
                symbolic links: resolve symbolic links in DIR before
                processing instances of `..'
      -e        if the -P option is supplied, and the current working
                directory cannot be determined successfully, exit with
                a non-zero status
      -@        on systems that support it, present a file with extended
                attributes as a directory containing the file attributes

    The default is to follow symbolic links, as if `-L' were specified.
    `..' is processed by removing the immediately previous pathname component
    back to a slash or the beginning of DIR.

    Exit Status:
    Returns 0 if the directory is changed, and if $PWD is set successfully when
    -P is used; non-zero otherwise.

【対応するDosコマンド】

ファイルを移動し、ファイルとディレクトリの名前を変更します。

少なくとも 1 つのファイルを移動するには:
MOVE [/Y | /-Y] [ドライブ:][パス]ファイル名1[,...] 宛先

ディレクトリの名前を変更するには:
MOVE [/Y | /-Y] [ドライブ:][パス]dirname1 dirname2

  [ドライブ:][パス]ファイル名1 移動するファイルの場所と名前を指定します。
  destination はファイルの新しい場所を指定します。ターゲットは、ドライブ文字
                          とコロン、ディレクトリ名、またはその組み合わせで構成できます。ファイルを 1 つだけ移動し
                          、移動中に名前を変更する場合は、ファイル名を含めることもできます。
  [ドライブ:][パス]dirname1 名前を変更するディレクトリを指定します。
  dirname2 は、ディレクトリの新しい名前を指定します。

  /Y 既存の宛先ファイルの上書きを確認するプロンプトを抑制します。
  /-Y 既存のオブジェクト ファイルを上書きするかどうかの確認を求めます。

コマンド ライン スイッチ /Y は、COPYCMD 環境変数に指定できます。
これは、コマンドラインで /-Y に置き換えることができます。デフォルトでは、
MOVE コマンドがバッチ スクリプト内から実行されない限り、上書きを求めるプロンプトが表示されます。

Dos にはファイルに個別に名前を付けるための別のコマンド ren があります

ファイルの名前を変更します。

RENAME [ドライブ:][パス]ファイル名1 ファイル名2。
REN [ドライブ:][パス]ファイル名1 ファイル名2。

対象ファイルに新しいドライブやパスを指定することはできないことに注意してください。


chmodコマンド

chmod: ファイルまたはディレクトリのアクセス許可を変更します。たとえば、読み取り、書き込み、および実行が可能になるように権限をchmod 755 file1変更します。file1

【英語ヘルプ】

hann@HannYang:~$ cd --help
cd: cd [-L|[-P [-e]] [-@]] [dir]
    Change the shell working directory.

    Change the current directory to DIR.  The default DIR is the value of the
    HOME shell variable.

    The variable CDPATH defines the search path for the directory containing
    DIR.  Alternative directory names in CDPATH are separated by a colon (:).
    A null directory name is the same as the current directory.  If DIR begins
    with a slash (/), then CDPATH is not used.

    If the directory is not found, and the shell option `cdable_vars' is set,
    the word is assumed to be  a variable name.  If that variable has a value,
    its value is used for DIR.

    Options:
      -L        force symbolic links to be followed: resolve symbolic
                links in DIR after processing instances of `..'
      -P        use the physical directory structure without following
                symbolic links: resolve symbolic links in DIR before
                processing instances of `..'
      -e        if the -P option is supplied, and the current working
                directory cannot be determined successfully, exit with
                a non-zero status
      -@        on systems that support it, present a file with extended
                attributes as a directory containing the file attributes

    The default is to follow symbolic links, as if `-L' were specified.
    `..' is processed by removing the immediately previous pathname component
    back to a slash or the beginning of DIR.

    Exit Status:
    Returns 0 if the directory is changed, and if $PWD is set successfully when
    -P is used; non-zero otherwise.

【対応するDosコマンド】

両側のファイルシステム属性は異なりますが、属性機能のみが似ています

ファイルのプロパティを表示または変更します。

属性 [+R | -R] [+A | -A] [+S | -S] [+H | -H] [+O | -O] [+I | -I] [+X | -X] [+P | -P] [+U | -U]
       [ドライブ:][パス][ファイル名] [/S [/D]] [/L]

  + プロパティを設定します。
  - プロパティをクリアします。
  R 読み取り専用のファイル属性。
  アーカイブ ファイルのプロパティ。
  S システムファイルの属性。
  H ファイル属性を非表示にします。
  O オフライン属性。
  I コンテンツインデックスファイル属性がありません。
   X クリーンアップ ファイル属性がありません。
  V 整合性属性。
  P 固定プロパティ。
  U は非固定プロパティです。
  [ドライブ:][パス][ファイル名] は、
      属性に対して処理するファイルを指定します。
  /S現在のフォルダーとすべてのサブフォルダー内の
      一致するファイルを処理します。
  /D はフォルダーも処理します。
  /L シンボリック リンクと
      シンボリック リンク ターゲットの属性を処理します


要約する

上記で紹介した基本的なコマンドは、基本的に Dos と Linux システムの両方で使用できるため、これらのコマンドを使い慣れると、ユーザーが自分のファイルやディレクトリをより便利に管理できるようになります。もちろん、more コマンドなど、ファイルを表示するためのコマンドもあり、両方のシステムにこのコマンドがあり、さらに、Linux の cat は dos の TYPE に対応します。

一般に、Linux に比べて外部コマンドが豊富で、find、stat、grep など、Dos には対応するコマンドがない強力な外部コマンドもあります (自作の小規模な非公式のものを除く)。 。

おすすめ

転載: blog.csdn.net/boysoft2002/article/details/132497309