国产毛片a精品毛-国产毛片黄片-国产毛片久久国产-国产毛片久久精品-青娱乐极品在线-青娱乐精品

樓主: changyongid
打印 上一主題 下一主題

一天一個Linux命令

[復制鏈接]
61
 樓主| 發表于 2009-9-10 15:50:26 | 只看該作者
來試一下。。做幾個例子就會用了。。
62
 樓主| 發表于 2009-9-10 15:57:30 | 只看該作者
[changyongid@localhost ~]$ pwd
/home/changyongid
現在在我們用戶的主目錄下

建立一個名為a的目錄
[changyongid@localhost ~]$ mkdir a
然后ls -d 一下,就可以看到a這個目錄了。ls -d 是列出當前路徑下的目錄。

選項 -v
[changyongid@localhost ~]$ mkdir -v a
mkdir: 已創建目錄 “a”
上面的第二行是終端里提示出來的。。這下可以看到使用 -v 選項的作用了吧。。

選項 -p
這是個很有用的選項。記得在某篇文章里說高手都喜歡用帶 -p 的。具體它是什么作用呢?我們使用一下:
注意:現在我已經刪除了剛才建的那個a目錄“rm -rf ./a”
那么,現在我們來建一個目錄b,它在a目錄里面。。。于是很自然的可以想到:
[changyongid@localhost ~]$ mkdir a/b
mkdir: 無法創建目錄 “a/b”: 沒有那個文件或目錄
看到了吧,沒有這個目錄,即我們沒有a目錄,那么也就不能創建a里面的b目錄嘍。。
ok,-p選項的用武之地來了。
[changyongid@localhost ~]$ mkdir -p a/b
[changyongid@localhost ~]$ tree a
a
`-- b

用tree命令來查看a目錄里的結構。可以看到,它里面有個b目錄了。方便了很多了吧。
63
 樓主| 發表于 2009-9-10 16:04:45 | 只看該作者
至于 -m 選項,我們也來使用一下吧。不過僅限這個東西牽到的東西較多。一下子說起來有點麻煩。留到有空了再來說吧。。。
[changyongid@localhost ~]$ ll -d a
drwxrwxr-x 3 changyongid changyongid 4096 09-10 15:56 a
這是剛建的a目錄,如上可看到它的權限。

[changyongid@localhost ~]$ mkdir -m 777 a
[changyongid@localhost ~]$ ll -d a
drwxrwxrwx 2 changyongid changyongid 4096 09-10 16:00 a
可以看到,用-m參數,再建立目錄a,它的權限就全開了。。
注:777是權限的一種表達方式。下面的rwx分別表試一個文件的讀、寫、可執行 權限。
那么7的二進制也就是111,正好對應rwx。那么對應位為1就表示這個權限開了。
那么 777也就表示rwx rwx rwx嘍。。。這三組是不同的。分別對應了 屬主用戶 、 屬主的組、其他。

好吧好吧。先說到這里,再說下去話又多了。可以上網查一下,比我說的清楚。
64
發表于 2009-9-13 11:03:11 | 只看該作者
周末不更新?
65
 樓主| 發表于 2009-9-13 17:58:06 | 只看該作者
這周末回學校了。。畢業 后第一次回校。。
又走了走平時經常走的那些校園小道,又想起畢業時同學們一起在“跳騷市場”賣舊貨的情景,見了一些還在校園里的好友。
校園依然親切,卻已不再有從前的那種感覺了。因為人都不在了……

我仍然會偶爾夢見學校,夢見那些可愛的同學們。
我還是沒有適應完全離開
66
 樓主| 發表于 2009-9-13 18:38:28 | 只看該作者
[changyongid@Fedora ~]$ rmdir --help
Usage: rmdir [OPTION]... DIRECTORY...
rmdir 選項...   目錄....
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
輸出版本信息,并退出

說明:如果目錄為空的話,則會刪除該目錄,-p時,必須每級的目錄都為空,否則不能刪除。
67
 樓主| 發表于 2009-9-13 18:47:39 | 只看該作者
例:
先建立目錄。用mkdir
  1. [changyongid@Fedora test]$ mkdir -p a/b/c
復制代碼
這樣,可以看一下現在目錄結構
  1. [changyongid@Fedora test]$ tree a
  2. a
  3. `-- b
  4.     `-- c

  5. 2 directories, 0 files
復制代碼
那么,我們先刪除c目錄。
  1. [changyongid@Fedora test]$ rmdir a/b/c
  2. [changyongid@Fedora test]$ tree a
  3. a
  4. `-- b

  5. 1 directory, 0 files
復制代碼
看到最后一行是顯示“1 directory, 0 files”這樣的信息。
現在已經刪除了c目錄了。因為這個目錄為空,直接rmdir就刪除掉了。

現在刪除b目錄,刪除之前,我們在b目錄里面放置一個文件。看目錄非空時會怎么樣。
  1. [changyongid@Fedora test]$ touch a/b/test
  2. [changyongid@Fedora test]$ tree a
  3. a
  4. `-- b
  5.     `-- test

  6. 1 directory, 1 file
復制代碼
看到了,已經在b里建了一個文件test。
  1. [changyongid@Fedora test]$ rmdir a/b/
  2. rmdir: failed to remove `a/b/': Directory not empty
復制代碼
看到了吧,無法刪除。如此的話。我們就不能刪除b目錄了。

大家看到這里,會不會有一個疑問,當我們要刪除一個目錄,包括目錄里面的所有文件我們都要一起刪除,這怎么辦呢?
68
 樓主| 發表于 2009-9-13 18:50:13 | 只看該作者
對于樓上提出的疑問,用rm就可以了。rm命令比較強大,相比之下,rmdir命令的作用就顯得很單薄了。幾乎很少用到,一般用rm就可以了。對于rm。放到以后再 講。

ps:才發現公社還有貼代碼的功能。真是淺薄了。
69
 樓主| 發表于 2009-9-13 19:03:28 | 只看該作者
前兩個命令是針對目錄操作的。很多時候,我們進入了一個目錄,第一件事情就是要看一下這個目錄里面有些什么文件,又有哪些子目錄。
或是,在我們當前的位置,想查看另外路徑的某目錄里的信息,但此時又不想進入該目錄。咋末辦呢?

對于第一個問題,答案就是ls命令。即,下面將要說明的。
對于第二個問題,其實,這個問題在我們之前的學習中一定也碰到過了。這里先說明一下。
對于路徑,在Linux里有 相對路徑 和 絕對路徑 之分。
乍一聽起來,還真有點玄乎,其實很簡單。我們要訪問某個文件或目錄(其實目錄也是一種文件,Linux里,一切皆為文件),而此文件在別的路徑徑下,我們如何訪問到呢?
舉個例子:
          我們有一個目錄a,其里面的結構如下:
  1. [changyongid@Fedora test]$ tree a
  2. a
  3. |-- b
  4. |   `-- test
  5. `-- c

  6. 2 directories, 1 file
復制代碼
即a里有兩個目錄,b和c。(b里有一個test文件)
現在我們在c目錄里。那么我們如何訪問到test文件呢?

1.通過相對路徑。即相對于我們當前目錄的路徑。
那么我們用vim訪問test文件的話,命令就可以這么寫
  1. [changyongid@Fedora c]$ vim ../b/test
復制代碼
.. 表示父目錄。這就是相對路徑
2.通過絕對路徑。絕對路徑,就是一個文件在文件系統里面的固定的位置,它跟當前我們在哪個位置無關。所以絕對路徑是以 / 開頭的。
查看一下當前目錄的絕對路徑還記得么?pwd
70
 樓主| 發表于 2009-9-13 19:06:02 | 只看該作者
接著,再來看看ls
可以help一下,但是ls 的命令參數太多了。以至于我們無法在一屏里面完整的看出。這個時候我們可以用less。
這個我們已經學過了。看到了吧,之前學過的命令都是很重要的。
  1. [changyongid@Fedora c]$ ls --help
  2. \Usage: ls [OPTION]... [FILE]...
  3. List information about the FILEs (the current directory by default).
  4. Sort entries alphabetically if none of -cftuvSUX nor --sort.

  5. Mandatory arguments to long options are mandatory for short options too.
  6.   -a, --all                  do not ignore entries starting with .
  7.   -A, --almost-all           do not list implied . and ..
  8.       --author               with -l, print the author of each file
  9.   -b, --escape               print octal escapes for nongraphic characters
  10.       --block-size=SIZE      use SIZE-byte blocks
  11.   -B, --ignore-backups       do not list implied entries ending with ~
  12.   -c                         with -lt: sort by, and show, ctime (time of last
  13.                                modification of file status information)
  14.                                with -l: show ctime and sort by name
  15.                                otherwise: sort by ctime
  16.   -C                         list entries by columns
  17.       --color[=WHEN]         control whether color is used to distinguish file
  18.                                types.  WHEN may be `never', `always', or `auto'
  19.   -d, --directory            list directory entries instead of contents,
  20.                                and do not dereference symbolic links
  21.   -D, --dired                generate output designed for Emacs' dired mode
  22.   -f                         do not sort, enable -aU, disable -ls --color
  23.   -F, --classify             append indicator (one of */=>@|) to entries
  24.       --file-type            likewise, except do not append `*'
  25.       --format=WORD          across -x, commas -m, horizontal -x, long -l,
  26.                                single-column -1, verbose -l, vertical -C
  27.       --full-time            like -l --time-style=full-iso
  28.   -g                         like -l, but do not list owner
  29.       --group-directories-first
  30.                              group directories before files.
  31.                                augment with a --sort option, but any
  32.                                use of --sort=none (-U) disables grouping
  33.   -G, --no-group             in a long listing, don't print group names
  34.   -h, --human-readable       with -l, print sizes in human readable format
  35.                                (e.g., 1K 234M 2G)
  36.       --si                   likewise, but use powers of 1000 not 1024
  37.   -H, --dereference-command-line
  38.                              follow symbolic links listed on the command line
  39.       --dereference-command-line-symlink-to-dir
  40.                              follow each command line symbolic link
  41.                              that points to a directory
  42.       --hide=PATTERN         do not list implied entries matching shell PATTERN
  43.                                (overridden by -a or -A)
  44.       --indicator-style=WORD  append indicator with style WORD to entry names:
  45.                                none (default), slash (-p),
  46.                                file-type (--file-type), classify (-F)
  47.   -i, --inode                print the index number of each file
  48.   -I, --ignore=PATTERN       do not list implied entries matching shell PATTERN
  49.   -k                         like --block-size=1K
  50.   -l                         use a long listing format
  51.   -L, --dereference          when showing file information for a symbolic
  52.                                link, show information for the file the link
  53.                                references rather than for the link itself
  54.   -m                         fill width with a comma separated list of entries
  55.   -n, --numeric-uid-gid      like -l, but list numeric user and group IDs
  56.   -N, --literal              print raw entry names (don't treat e.g. control
  57.                                characters specially)
  58.   -o                         like -l, but do not list group information
  59.   -p, --indicator-style=slash
  60.                              append / indicator to directories
  61.   -q, --hide-control-chars   print ? instead of non graphic characters
  62.       --show-control-chars   show non graphic characters as-is (default
  63.                              unless program is `ls' and output is a terminal)
  64.   -Q, --quote-name           enclose entry names in double quotes
  65.       --quoting-style=WORD   use quoting style WORD for entry names:
  66.                                literal, locale, shell, shell-always, c, escape
  67.   -r, --reverse              reverse order while sorting
  68.   -R, --recursive            list subdirectories recursively
  69.   -s, --size                 print the allocated size of each file, in blocks
  70.   -S                         sort by file size
  71.       --sort=WORD            sort by WORD instead of name: none -U,
  72.                              extension -X, size -S, time -t, version -v
  73.       --time=WORD            with -l, show time as WORD instead of modification
  74.                              time: atime -u, access -u, use -u, ctime -c,
  75.                              or status -c; use specified time as sort key
  76.                              if --sort=time
  77.       --time-style=STYLE     with -l, show times using style STYLE:
  78.                              full-iso, long-iso, iso, locale, +FORMAT.
  79.                              FORMAT is interpreted like `date'; if FORMAT is
  80.                              FORMAT1FORMAT2, FORMAT1 applies to
  81.                              non-recent files and FORMAT2 to recent files;
  82.                              if STYLE is prefixed with `posix-', STYLE
  83.                              takes effect only outside the POSIX locale
  84.   -t                         sort by modification time
  85.   -T, --tabsize=COLS         assume tab stops at each COLS instead of 8
  86.   -u                         with -lt: sort by, and show, access time
  87.                                with -l: show access time and sort by name
  88.                                otherwise: sort by access time
  89.   -U                         do not sort; list entries in directory order
  90.   -v                         sort by version
  91.   -w, --width=COLS           assume screen width instead of current value
  92.   -x                         list entries by lines instead of by columns
  93.   -X                         sort alphabetically by entry extension
  94.   -1                         list one file per line

  95. SELinux options:

  96.   --lcontext                 Display security context.   Enable -l. Lines
  97.                              will probably be too wide for most displays.
  98.   -Z, --context              Display security context so it fits on most
  99.                              displays.  Displays only mode, user, group,
  100.                              security context and file name.
  101.   --scontext                 Display only security context and file name.
  102.       --help     display this help and exit
  103.       --version  output version information and exit

  104. SIZE may be (or may be an integer optionally followed by) one of following:
  105. kB 1000, K 1024, MB 1000*1000, M 1024*1024, and so on for G, T, P, E, Z, Y.

  106. By default, color is not used to distinguish types of files.  That is
  107. equivalent to using --color=none.  Using the --color option without the
  108. optional WHEN argument is equivalent to using --color=always.  With
  109. --color=auto, color codes are output only if standard output is connected
  110. to a terminal (tty).  The environment variable LS_COLORS can influence the
  111. colors, and can be set easily by the dircolors command.

  112. Exit status:
  113. 0  if OK,
  114. 1  if minor problems (e.g., cannot access subdirectory),
  115. 2  if serious trouble (e.g., cannot access command-line argument).
復制代碼
71
 樓主| 發表于 2009-9-13 19:06:26 | 只看該作者
本帖最后由 changyongid 于 2009-9-13 21:02 編輯

重復發了一行。編輯掉……
72
 樓主| 發表于 2009-9-13 19:10:56 | 只看該作者
從樓上可以看到,ls的參數太多了,以至于我們懷疑是否有必要一行一行的看下去?

這絕對是有必要的。為什么呢?
因為ls是Linux里面用到最多的命令之一。使用的頻率如此之高,還是非常有必要好好的掌握一下,這會對我們以后的使用Linux時的效率大大提高。
73
 樓主| 發表于 2009-9-13 21:31:00 | 只看該作者
ls ,即 list的意思。

格式: ls [OPTION]... [FILE]...
列出文件的詳細信息。默認時列出當前目錄的詳細信息,即當前目錄里的內容。

  -a, --all                  顯示目錄里的所有文件,包括隱藏文件
  -A, --almost-all           與a差不多,但不列出. 和..   。這兩個分別表式當前目錄和上一級目錄。

  -b, --escape              把文件名中不可輸出的字符用反斜杠加字符編號的形式列出

  -B, --ignore-backups       不顯示以 ~ 結尾的文件(這些一般是備份文件)
  -c                       以修改時間排序
  -C                         按列出輸,縱向排序

  -d, --directory           只顯示目錄文件,而不顯示其他的文件。

  -g                         如 -l,但不顯示所屬用戶
      --group-directories-first
                             group directories before files.
                               augment with a --sort option, but any
                               use of --sort=none (-U) disables grouping
  -G, --no-group             不顯示組信息
  -h, --human-readable       with -l, print sizes in human readable format
                               (e.g., 1K 234M 2G)

  -i, --inode                顯示節點信息

  -l                         列出詳細的信息
  -L                  列出鏈接文件名而不顯示鏈接到的文件
  -n, --numeric-uid-gid     如 -l ,但顯示用戶和組時,不是顯示他們的名字,而是id號
  -N,           不限制文件長度
  -o                        除組以外的詳細信息
  -p, --indicator-style=slash
                            在每個文件名后附上一個字符以說明該文件的類型。*表示普通文件  /表示目錄  @表示符號鏈接  |表示FIFOs  =表示套接字

  -q, --hide-control-chars   用?代替不可輸出的字符

  -Q,      把輸出的文件名用引號括起來
  -r, --reverse            對目錄反向排序
  -R, --recursive           列出所有子目錄下的文件
  -s, --size                 在每個文件名旁邊輸出該文件的大小
  -S                        以文件大小排序

  -t                        以修改時間排序

  -u                       以訪問時間排序
  -U                        不排序
  
  -1                        逐行顯示

暫且列這么多吧。真是挺多的。
74
 樓主| 發表于 2009-9-13 21:39:03 | 只看該作者
  1. 可以試一下以下幾個選項
  2. ls -l
  3. ls -a
  4. ls -la
  5. ls -sh
  6. ls -i
  7. ls -1
  8. 這里就不一一列出來了
復制代碼
75
 樓主| 發表于 2009-9-15 09:25:45 | 只看該作者
OH shit!
I can not input chinese now,and i am sorry for my poor english.
76
 樓主| 發表于 2009-9-16 08:36:05 | 只看該作者
it is ok now!
77
 樓主| 發表于 2009-9-16 08:51:40 | 只看該作者
cp
格式:cp [OPTION]... [-T] SOURCE DEST
           cp [OPTION]... SOURCE... DIRECTORY
           cp [OPTION]... -t DIRECTORY SOURCE...

功能:將 SOURCE 復制(copy)到 DEST ,或者將多個 SOURCE 復制到 DEST

OPTION說明:
  -a, --archive                作用等同于 -dR --preserve=all (一般在拷貝目錄時用)

  -d                                拷貝時保留鏈接
  -f, --force                     強制拷貝,不需要提示
  -i, --interactive            與用戶交互,在覆蓋文件之前請求用戶的確認。

  -l, --link                        鏈接文件,而不是拷貝

  -n, --no-clobber           不覆蓋已存在的文件

  -p                                復制后的文件將保留原文件的權限、屬主、修改時間等

  -R, -r, --recursive       遞歸作用于整個目錄,包括目錄下的所有文件和子目錄。在對整個目錄進行操作時用。


  -t, --target-directory=DIRECTORY  指定目標路徑
78
 樓主| 發表于 2009-9-16 08:56:33 | 只看該作者
實例:
             假設當前目錄有個test.c文件。

  1. [changyongid@localhost test]$ ls
  2. test.c
  3. [changyongid@localhost test]$ cp test.c tt                      //直接復制。后面的路徑可以是另外的目錄里
  4. [changyongid@localhost test]$ ls
  5. test.c  tt
  6. [changyongid@localhost test]$ cp -l test.c ll             //用-l 鏈接一下,可以看到實際上是做了個硬鏈接
  7. [changyongid@localhost test]$ ll
  8. total 0
  9. -rw-rw-r-- 2 changyongid changyongid 0 2009-09-16 08:53 ll
  10. -rw-rw-r-- 2 changyongid changyongid 0 2009-09-16 08:53 test.c
  11. -rw-rw-r-- 1 changyongid changyongid 0 2009-09-16 08:54 tt
復制代碼
79
 樓主| 發表于 2009-9-16 08:59:33 | 只看該作者
由于cp過于是默認覆蓋已存在文件的,所以直接使用這個命令時會有一點危險。在~/.bashrc里面用alias將其替換成 cp -i 即可,加上-i參數,每次要覆蓋之前,它都會提示,這樣就安全了一些,防止誤操作。
80
 樓主| 發表于 2009-9-16 19:51:18 | 只看該作者
命令 : rm
使用 : rm [選項]... 文件...
說明 : 刪除文件

  -f, --force      強制刪除,不需要提示
  -i                  每次刪除行為之前,都提示刪除動作(需要用戶確認刪除)
  -I                  當一次刪除文件數為3個或3個以上時,或在遞歸刪除一個目錄時,只提示一次.與 -i 相比,這個選項即保障了安全又避免了刪除多個文件時的多次打擾。

  -r, -R, --recursive  遞歸刪除目錄和其中的文件
  -v, --verbose         交互動作,顯示正在進行的動作
   
默認情況下,rm命令不會刪除目錄。使用 -r 或 -R 選項來刪除目錄和目錄內的文件。

如果一個文件名以“-”開頭,比如“-foo”,用下面兩個命令中任一個來刪除:
  rm -- -foo

  rm ./-foo

注意,當使用rm來刪除文件時,被刪除的文件是可恢復的。也就是說rm只刪除了它的索引結點而已。如果想要真正的刪除,不可恢復,可以考慮使用shred。

我們刪除一個文件,可以直接的rm刪除。
刪除一個目錄,可使用 rm -rf ... 注意,此處的f是強制。

默認的情況下,我們的刪除是不會提示信息的,顯然這樣是有些危險的。我就曾經犯過一個錯誤,錯將/bin/目錄里面的內容全部刪除掉了,結果可想而知。當然,我當時犯的錯誤跟我使用超級用戶root有直接的關系。
為了使我們的操作更安全,可以在.bashrc里用alias添加一行
rm='rm -i'
這樣,每次我們使用rm命令時都相當于使用 rm -i ,那么每次刪除都需要我們的確認了。這樣做是有一定好處的,當然還要考慮到個人的習慣問題。
您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

關于我們  -  服務條款  -  使用指南  -  站點地圖  -  友情鏈接  -  聯系我們
電子工程網 © 版權所有   京ICP備16069177號 | 京公網安備11010502021702
快速回復 返回頂部 返回列表
主站蜘蛛池模板: 青青国产成人久久91 | 久久精品店 | 久久久久久久久久久久久久久久久 | 大伊香蕉精品一线视频 | 日韩一区二区三区四区不卡 | 久久精品国产曰本波多野结衣 | 精品一区二区三区在线成人 | jav008.app| 羞羞视频免费观看入口 | 在线日韩欧美一区二区三区 | 午夜成本人动漫在线观看 | 欧美精品在线一区二区三区 | 美女中出视频 | 日本三级欧美三级人妇视频黑白配 | 色婷婷综合缴情综六月 | 惩罚美女妲己的尤老师 | 亚洲精品中文字幕无乱码麻豆 | 亚洲网站黄色 | 91精品国产高清久久久久久 | 欧美一区二区三区免费观看视频 | 日韩大片免费观看 | 午夜啪啪福利视频 | 四虎4444hu4影视最新地址 | 日韩欧美在线播放视频 | 污视频18高清在线观看 | 精品视频在线免费观看 | 国产成人手机在线 | 日韩在线毛片 | 四虎网站最新地址 | 奇米视频7777| 黄在线观看在线播放720p | 国内精品手机在线观看视频 | www.日本精品 | 国内精品久久久久影院一蜜桃 | 午夜激情在线 | 玖玖国产| 高清一区二区在线观看 | 免费视频一区 | 欧洲福利视频 | 亚洲国产一区在线二区三区 | 花季传媒3.0.3每天免费3次 |