目錄
前言
基礎(chǔ)命令(文件目錄相關(guān)的)
cd命令
【英文幫助】
【對(duì)應(yīng)Dos命令】
pwd命令
【英文幫助】
【對(duì)應(yīng)Dos命令】
ls命令
【英文幫助】
【對(duì)應(yīng)Dos命令】
tree命令
【英文幫助】
【對(duì)應(yīng)Dos命令】
mkdir命令
【英文幫助】
【對(duì)應(yīng)Dos命令】
rmdir/rm命令
【英文幫助】
【對(duì)應(yīng)Dos命令】
cp命令
【英文幫助】
【對(duì)應(yīng)Dos命令】
touch命令
【英文幫助】
【對(duì)應(yīng)Dos命令】
mv命令
【英文幫助】
【對(duì)應(yīng)Dos命令】
chmod命令
【英文幫助】
【對(duì)應(yīng)Dos命令】
總結(jié)
前言
Linux是一個(gè)開源的操作系統(tǒng),它的目錄結(jié)構(gòu)非常重要,因?yàn)樗鞘褂肔inux系統(tǒng)的一個(gè)基礎(chǔ)。本文將介紹一些操作Linux系統(tǒng)中文件、目錄的常用命令,其中有些命令在Dos中也有命令相對(duì)應(yīng)(指發(fā)揮的功能類似的)。
另外有一點(diǎn)區(qū)別: Linux系統(tǒng)下命令是大小寫敏感的,一般是全小寫的;Dos系統(tǒng)下命令是不區(qū)分大小寫的,命令名大小寫混裝都是相同的,如 cd CD cD Cd就是同一個(gè)命令。
基礎(chǔ)命令(文件目錄相關(guān)的)
cd命令
cd:切換當(dāng)前工作目錄。可以使用絕對(duì)路徑或相對(duì)路徑。
進(jìn)入根目錄的命令是:cd /,進(jìn)入用戶的home目錄的命令是:cd ~。
其中,“/”、“~” 分別表示根目錄和當(dāng)前用戶的home目錄。
絕對(duì)路徑方式的切換:cd /home/user/documents
相對(duì)路徑方式的切換:cd ../user/documents
其中,絕對(duì)路徑指從根目錄起始的路徑;相對(duì)路徑指從當(dāng)前目錄起始的路徑。
【英文幫助】
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.
【對(duì)應(yīng)Dos命令】
cd 同名同功能,格式: cd 目錄路徑
顯示當(dāng)前目錄名或改變當(dāng)前目錄?;蛘哂瞄L(zhǎng)名稱 chdir
CHDIR [/D] [drive:][path]
CHDIR [..]
CD [/D] [drive:][path]
CD [..]
? .. ? 指定要改成父目錄。
鍵入 CD drive: 顯示指定驅(qū)動(dòng)器中的當(dāng)前目錄。
不帶參數(shù)只鍵入 CD,則顯示當(dāng)前驅(qū)動(dòng)器和目錄。
使用 /D 開關(guān),除了改變驅(qū)動(dòng)器的當(dāng)前目錄之外,
還可改變當(dāng)前驅(qū)動(dòng)器。
如果命令擴(kuò)展被啟用,CHDIR 會(huì)如下改變:
當(dāng)前的目錄字符串會(huì)被轉(zhuǎn)換成使用磁盤名上的大小寫。所以,
如果磁盤上的大小寫如此,CD C:\TEMP 會(huì)將當(dāng)前目錄設(shè)為
C:\Temp。
CHDIR 命令不把空格當(dāng)作分隔符,因此有可能將目錄名改為一個(gè)
帶有空格但不帶有引號(hào)的子目錄名。例如:
? ? ?cd \winnt\profiles\username\programs\start menu
與下列相同:
? ? ?cd "\winnt\profiles\username\programs\start menu"
在擴(kuò)展停用的情況下,你必須鍵入以上命令。
pwd命令
pwd:顯示當(dāng)前工作目錄的路徑。例如,pwd
將顯示當(dāng)前工作目錄的完整路徑。
pwd命令用于顯示當(dāng)前工作目錄(即當(dāng)前所在的目錄)的絕對(duì)路徑。在Linux系統(tǒng)中,每個(gè)用戶都有自己的home目錄,剛登陸系統(tǒng)時(shí),所在的目錄就是用戶自己的home目錄。
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.
【對(duì)應(yīng)Dos命令】
Dos下沒(méi)有單獨(dú)的pwd命令,用CD命令不加參數(shù)即可:
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:顯示當(dāng)前或指定目錄中的文件和目錄列表。
ls 命令參數(shù)極其復(fù)雜,默認(rèn)為短格式顯示,只有文件名,詳細(xì)格式可以用參數(shù) -l ,以長(zhǎng)格式詳細(xì)顯示目錄中的文件和目錄列表,包括文件大小、權(quán)限、所有者、修改時(shí)間等信息。
【英文幫助】
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'
【對(duì)應(yīng)Dos命令】
DIR [drive:][path][filename] [/A[[:]attributes]] [/B] [/C] [/D] [/L] [/N]
? [/O[[:]sortorder]] [/P] [/Q] [/R] [/S] [/T[[:]timefield]] [/W] [/X] [/4]
? [drive:][path][filename]
? ? ? ? ? ? ? 指定要列出的驅(qū)動(dòng)器、目錄和/或文件。
? /A ? ? ? ? ?顯示具有指定屬性的文件。
? 屬性 ? ? ? ? D ?目錄 ? ? ? ? ? ? ? ?R ?只讀文件
? ? ? ? ? ? ? ?H ?隱藏文件 ? ? ? ? ? ?A ?準(zhǔn)備存檔的文件
? ? ? ? ? ? ? ?S ?系統(tǒng)文件 ? ? ? ? ? ?I ?無(wú)內(nèi)容索引文件
? ? ? ? ? ? ? ?L ?重新分析點(diǎn) ? ? ? ? ?O ?脫機(jī)文件
? ? ? ? ? ? ? ?- ?表示“否”的前綴
? /B ? ? ? ? ?使用空格式(沒(méi)有標(biāo)題信息或摘要)。
? /C ? ? ? ? ?在文件大小中顯示千位數(shù)分隔符。這是默認(rèn)值。用 /-C 來(lái)
? ? ? ? ? ? ? 禁用分隔符顯示。
? /D ? ? ? ? ?跟寬式相同,但文件是按欄分類列出的。
? /L ? ? ? ? ?用小寫。
? /N ? ? ? ? ?新的長(zhǎng)列表格式,其中文件名在最右邊。
? /O ? ? ? ? ?用分類順序列出文件。
? 排列順序 ? ? N ?按名稱(字母順序) ? ? S ?按大小(從小到大)
? ? ? ? ? ? ? ?E ?按擴(kuò)展名(字母順序) ? D ?按日期/時(shí)間(從先到后)
? ? ? ? ? ? ? ?G ?組目錄優(yōu)先 ? ? ? ? ? - ?反轉(zhuǎn)順序的前綴
? /P ? ? ? ? ?在每個(gè)信息屏幕后暫停。
? /Q ? ? ? ? ?顯示文件所有者。
? /R ? ? ? ? ?顯示文件的備用數(shù)據(jù)流。
? /S ? ? ? ? ?顯示指定目錄和所有子目錄中的文件。
? /T ? ? ? ? ?控制顯示或用來(lái)分類的時(shí)間字符域
? 時(shí)間段 ? ? ?C ?創(chuàng)建時(shí)間
? ? ? ? ? ? ? A ?上次訪問(wèn)時(shí)間
? ? ? ? ? ? ? W ?上次寫入的時(shí)間
? /W ? ? ? ? ?用寬列表格式。
? /X ? ? ? ? ?顯示為非 8dot3 文件名產(chǎn)生的短名稱。格式是 /N 的格式,
? ? ? ? ? ? ? 短名稱插在長(zhǎng)名稱前面。如果沒(méi)有短名稱,在其位置則
? ? ? ? ? ? ? 顯示空白。
? /4 ? ? ? ? ?以四位數(shù)字顯示年份
可以在 DIRCMD 環(huán)境變量中預(yù)先設(shè)定開關(guān)。通過(guò)添加前綴 - (破折號(hào))
來(lái)替代預(yù)先設(shè)定的開關(guān)。例如,/-W。
tree命令
tree:以樹形結(jié)構(gòu)顯示當(dāng)前目錄中的文件和目錄列表。
【英文幫助】
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.
【對(duì)應(yīng)Dos命令】
同名類似功能 tree,linux的tree參數(shù)更豐富
以圖形顯示驅(qū)動(dòng)器或路徑的文件夾結(jié)構(gòu)。
TREE [drive:][path] [/F] [/A]
? ?/F ? 顯示每個(gè)文件夾中文件的名稱。
? ?/A ? 使用 ASCII 字符,而不使用擴(kuò)展字符。
mkdir命令
mkdir:創(chuàng)建一個(gè)新的目錄。例如:mkdir new_directory
將創(chuàng)建一個(gè)名為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.
【對(duì)應(yīng)Dos命令】
mkdir 同名同功能,或者用短名稱 md。
創(chuàng)建目錄。
MKDIR [drive:]path
MD [drive:]path
如果命令擴(kuò)展被啟用,MKDIR 會(huì)如下改變:
如果需要,MKDIR 會(huì)在路徑中創(chuàng)建中級(jí)目錄。例如: 假設(shè) \a 不
存在,那么:
? ? mkdir \a\b\c\d
與:
? ? mkdir \a
? ? chdir \a
? ? mkdir b
? ? chdir b
? ? mkdir c
? ? chdir c
? ? mkdir d
相同。如果擴(kuò)展被停用,則需要鍵入 mkdir \a\b\c\d。
rmdir/rm命令
rmdir:刪除一個(gè)空目錄。例如:rmdir empty_directory
將刪除名為empty_directory
的空目錄。
rm:用于刪除文件或目錄。如果我們想刪除一個(gè)目錄及其所有子文件和子目錄,可以使用rm命令加上-r參數(shù),例如: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'
【對(duì)應(yīng)Dos命令】
Dos下rmdir和rd是同一個(gè)命令,linux下rmdir和rm是兩個(gè)不同的命令。
刪除一個(gè)目錄。
RMDIR [/S] [/Q] [drive:]path
RD [/S] [/Q] [drive:]path
? ? /S ? ? ?除目錄本身外,還將刪除指定目錄下的所有子目錄和
? ? ? ? ? ? 文件。用于刪除目錄樹。
? ? /Q ? ? ?安靜模式,帶 /S 刪除目錄樹時(shí)不要求確認(rèn)
cp命令
cp:復(fù)制一個(gè)文件或目錄。
cp:復(fù)制文件或目錄。例如,cp file1 file2
將復(fù)制file1
到file2
。要復(fù)制目錄及其內(nèi)容,需要使用-r
選項(xiàng),如cp -r dir1 dir2
。
cp命令用于復(fù)制文件或目錄。例如,我們可以使用cp命令將一個(gè)名為“example”的目錄復(fù)制到當(dāng)前目錄中,命令是: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.
【對(duì)應(yīng)Dos命令】
copy 主要功能相同,linux中簡(jiǎn)稱為cp。
將一份或多份文件復(fù)制到另一個(gè)位置。
COPY [/D] [/V] [/N] [/Y | /-Y] [/Z] [/L] [/A | /B ] source [/A | /B]
? ? ?[+ source [/A | /B] [+ ...]] [destination [/A | /B]]
? source ? ? ? 指定要復(fù)制的文件。
? /A ? ? ? ? ? 表示一個(gè) ASCII 文本文件。
? /B ? ? ? ? ? 表示一個(gè)二進(jìn)位文件。
? /D ? ? ? ? ? 允許解密要?jiǎng)?chuàng)建的目標(biāo)文件
? destination ?為新文件指定目錄和/或文件名。
? /V ? ? ? ? ? 驗(yàn)證新文件寫入是否正確。
? /N ? ? ? ? ? 復(fù)制帶有非 8dot3 名稱的文件時(shí),
? ? ? ? ? ? ? ?盡可能使用短文件名。
? /Y ? ? ? ? ? 不使用確認(rèn)是否要覆蓋現(xiàn)有目標(biāo)文件
? ? ? ? ? ? ? ?的提示。
? /-Y ? ? ? ? ?使用確認(rèn)是否要覆蓋現(xiàn)有目標(biāo)文件
? ? ? ? ? ? ? ?的提示。
? /Z ? ? ? ? ? 用可重新啟動(dòng)模式復(fù)制已聯(lián)網(wǎng)的文件。
/L ? ? ? ? ? 如果源是符號(hào)鏈接,請(qǐng)將鏈接復(fù)制
? ? ? ? ? ? ? ?到目標(biāo)而不是源鏈接指向的實(shí)際文件。
命令行開關(guān) /Y 可以在 COPYCMD 環(huán)境變量中預(yù)先設(shè)定。
這可能會(huì)被命令行上的 /-Y 替代。除非 COPY
命令是在一個(gè)批處理腳本中執(zhí)行的,默認(rèn)值應(yīng)為
在覆蓋時(shí)進(jìn)行提示。
要附加文件,請(qǐng)為目標(biāo)指定一個(gè)文件,為源指定
數(shù)個(gè)文件(用通配符或 file1+file2+file3 格式)。
touch命令
touch:創(chuàng)建一個(gè)新的空文件或更新現(xiàn)有文件的訪問(wèn)和修改時(shí)間。例如,touch file1
將創(chuàng)建一個(gè)名為file1
的新文件,或touch file1
將更新file1
的訪問(wèn)和修改時(shí)間。
【英文幫助】
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'
【對(duì)應(yīng)Dos命令】
沒(méi)有同名對(duì)應(yīng)的,可以用copy命令實(shí)現(xiàn)創(chuàng)建新的空文件
copy con newfile.txt??需要手輸 ctrl+Z 加 回車。
另外可用 echo. > newfile.txt,這個(gè)命令一步到位。
注意echo后有句點(diǎn)符號(hào)中間不能有空格,有空格就把點(diǎn)寫進(jìn)文件了。
C:\Users\hann>echo. > newfile.txt
C:\Users\hann>type newfile.txt
C:\Users\hann>dir newfile.txt
?驅(qū)動(dòng)器 C 中的卷是 Windows
?卷的序列號(hào)是 1E34-A256
?C:\Users\hann 的目錄
2023/08/26 ?12:16 ? ? ? ? ? ? ? ? 3 newfile.txt
? ? ? ? ? ? ? ?1 個(gè)文件 ? ? ? ? ? ? ?3 字節(jié)
? ? ? ? ? ? ? ?0 個(gè)目錄 123,609,210,880 可用字節(jié)
缺點(diǎn): 創(chuàng)建了非0字節(jié)的“空”文件,有空行存在
mv命令
mv:移動(dòng)或重命名一個(gè)文件或目錄。
mv:移動(dòng)文件或目錄,也可用于重命名。例如,mv file1 file2?
將把file1
重命名為file2
,并刪除file1
。
要移動(dòng)目錄及其內(nèi)容,需要使用-r
選項(xiàng),如mv -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.
【對(duì)應(yīng)Dos命令】
移動(dòng)文件并重命名文件和目錄。
要移動(dòng)至少一個(gè)文件:
MOVE [/Y | /-Y] [drive:][path]filename1[,...] destination
要重命名一個(gè)目錄:
MOVE [/Y | /-Y] [drive:][path]dirname1 dirname2
? [drive:][path]filename1 指定你想移動(dòng)的文件位置和名稱。
? destination ? ? ? ? ? ? 指定文件的新位置。目標(biāo)可包含一個(gè)驅(qū)動(dòng)器號(hào)
? ? ? ? ? ? ? ? ? ? ? ? ? 和冒號(hào)、一個(gè)目錄名或組合。如果只移動(dòng)一個(gè)文件
? ? ? ? ? ? ? ? ? ? ? ? ? 并在移動(dòng)時(shí)將其重命名,你還可以包括文件名。
? [drive:][path]dirname1 ?指定要重命名的目錄。
? dirname2 ? ? ? ? ? ? ? ?指定目錄的新名稱。
? /Y ? ? ? ? ? ? ? ? ? ? ?取消確認(rèn)覆蓋一個(gè)現(xiàn)有目標(biāo)文件的提示。
? /-Y ? ? ? ? ? ? ? ? ? ? 對(duì)確認(rèn)覆蓋一個(gè)現(xiàn)有目標(biāo)文件發(fā)出提示。
命令行開關(guān) /Y 可以出現(xiàn)在 COPYCMD 環(huán)境變量中。這可以用命令行上
的 /-Y 替代。默認(rèn)值是,除非 MOVE 命令是從一個(gè)批腳本內(nèi)
執(zhí)行的,覆蓋時(shí)都發(fā)出提示。
Dos另有單獨(dú)命名文件的命令 ren
重命名文件。
RENAME [drive:][path]filename1 filename2.
REN [drive:][path]filename1 filename2.
請(qǐng)注意,你不能為目標(biāo)文件指定新的驅(qū)動(dòng)器或路徑。
chmod命令
chmod:更改文件或目錄的權(quán)限。例如,chmod 755 file1
將更改file1
的權(quán)限,使其可讀、可寫和可執(zhí)行。
【英文幫助】
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.
【對(duì)應(yīng)Dos命令】
兩邊的文件系統(tǒng)屬性不一樣,只有attrib功能比較類似
顯示或更改文件屬性。
ATTRIB [+R | -R] [+A | -A] [+S | -S] [+H | -H] [+O | -O] [+I | -I] [+X | -X] [+P | -P] [+U | -U]
? ? ? ?[drive:][path][filename] [/S [/D]] [/L]
? + ? 設(shè)置屬性。
? - ? 清除屬性。
? R ? 只讀文件屬性。
? A ? 存檔文件屬性。
? S ? 系統(tǒng)文件屬性。
? H ? 隱藏文件屬性。
? O ? 脫機(jī)屬性。
? I ? 無(wú)內(nèi)容索引文件屬性。
? ?X ? 無(wú)清理文件屬性。
? V ? 完整性屬性。
? P ? 固定屬性。
? U ? 非固定屬性。
? [drive:][path][filename]
? ? ? 指定屬性要處理的文件。
? /S ?處理當(dāng)前文件夾及其所有子文件夾中
? ? ? 的匹配文件。
? /D ?也處理文件夾。
? /L ?處理符號(hào)鏈接和
? ? ? 符號(hào)鏈接目標(biāo)的屬性
總結(jié)
以上介紹的這些基礎(chǔ)命令基本上Dos,Linux兩系統(tǒng)都有,熟悉這些命令可以幫助用戶更加方便地管理自己的文件和目錄。當(dāng)然還有文件查看類的命令,比如 more命令兩系統(tǒng)都有這個(gè)命令;另外?linux 的 cat 對(duì)應(yīng) dos 的 TYPE。文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-675774.html
總的來(lái)說(shuō),相比較還是Linux的外部命令更豐富一點(diǎn),還有 find, stat, grep 等等這些功能強(qiáng)大的外部命令在Dos里沒(méi)有相對(duì)應(yīng)的命令(小眾的非官方的自己編寫的除外)。文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-675774.html
到了這里,關(guān)于Linux 終端命令之文件目錄操作,對(duì)比Dos相關(guān)命令的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!