數據倉庫001 - 復習Linux shell命令 - pwd mkdir mv tail -f xxx.log 和 ail -F xxx.log




 

1.  [root@localhost ~]#  的含義 ?

   【登錄的用戶  機器的名稱 家目錄】

2. 查看當前光標所在的目錄   pwd

[root@localhost ~]# pwd
/root

 

3. 切換目錄 cd

[root@localhost ~]# cd /home
[root@localhost home]# pwd
/home

  root用戶 家目錄 /root 規定
  xxx用戶 家目錄 /home/xxx 默認

回退家目錄 的三種方法: 

[root@localhost home]# cd -
/root
[root@localhost ~]# cd /home
[root@localhost home]# cd ~
[root@localhost ~]# cd /home
[root@localhost home]# cd /root
[root@localhost ~]#

 

cd ../ 回退上一層目錄
cd ../../ 回退上2層目錄

[root@localhost ~]# cd /home/linux/
[root@localhost linux]# pwd
/home/linux
[root@localhost linux]# cd ../
[root@localhost home]# pwd
/home
[root@localhost home]# cd /home/linux
[root@localhost linux]# pwd
/home/linux
[root@localhost linux]# cd ../../
[root@localhost /]# pwd
/
[root@localhost /]# 

 

4.目錄 文件夾  路徑

  ·絕對路徑 /根目錄 以根目錄

  ·相對路徑 不以根目錄為開始,以當前光標所在的目錄為開始

 

5.clear  清空屏幕

 

6.ls查看當前光標所在的目錄下,文件和文件夾都有哪些

  其中ls 、ll的區別,其中ll 就是ls -l:

[root@localhost /]# ls
bin   dev  home  lost+found  misc  net  proc  sbin     srv  tftpboot  usr
boot  etc  lib   media       mnt   opt  root  selinux  sys  tmp       var
[root@localhost /]# ll
總計 154
drwxr-xr-x   2 root root  4096 10-16 07:21 bin
drwxr-xr-x   4 root root  1024 10-15 21:25 boot
drwxr-xr-x  13 root root  3980 11-10 21:50 dev
drwxr-xr-x 113 root root 12288 11-10 21:50 etc
drwxr-xr-x  12 root root  4096 10-25 20:11 home
drwxr-xr-x  13 root root 12288 10-16 07:21 lib
drwx------   2 root root 16384 10-15 21:23 lost+found
drwxr-xr-x   2 root root  4096 11-10 21:50 media
drwxr-xr-x   2 root root     0 11-10 21:50 misc
drwxr-xr-x   5 root root  4096 11-01 05:25 mnt
drwxr-xr-x   2 root root     0 11-10 21:50 net
drwxr-xr-x   2 root root  4096 2009-10-01 opt
dr-xr-xr-x 171 root root     0 11-10 21:49 proc
drwxr-x---   7 root root  4096 11-10 22:11 root
drwxr-xr-x   2 root root 12288 10-16 07:21 sbin
drwxr-xr-x   4 root root     0 11-10 21:49 selinux
drwxr-xr-x   2 root root  4096 2009-10-01 srv
drwxr-xr-x  12 root root     0 11-10 21:49 sys
drwxr-xr-x   3 root root  4096 10-15 21:26 tftpboot
drwxrwxrwt  25 root root  4096 11-10 21:50 tmp
drwxr-xr-x  14 root root  4096 10-15 21:24 usr
drwxr-xr-x  26 root root  4096 10-15 21:28 var
[root@localhost /]# 

 

 小結:

  ls -l ==> 等價於ll
  ls -l -a 查看當前的文件文件夾+ 隱藏文件文件夾   以.開頭
  ll -h 文件的大小

  ll -rt 按時間排序

ls
ls -l
ls -a
ls -l -a ==> ls -la

 

   實例:

[root@localhost /]# cd /home/linux/
[root@localhost linux]# ls
Desktop  file1.txt  file2.txt  ml
[root@localhost linux]# ls -l
總計 24
drwxr-xr-x 2 linux linux 4096 10-16 06:02 Desktop
-rw-rw-r-- 1 linux linux    0 10-16 07:04 file1.txt
-rw-rw-r-- 1 linux linux    0 10-16 07:07 file2.txt
drwxrwxr-x 2 linux linux 4096 10-16 07:10 ml
[root@localhost linux]# ls -a
.              .eggcups         .gstreamer-0.10      .redhat
..             .emacs           .gtkrc-1.2-gnome2    .scim
.bash_history  file1.txt        .ICEauthority        .ssh
.bash_logout   file2.txt        .kde                 .Trash
.bash_profile  .gconf           .metacity            .viminfo
.bashrc        .gconfd          ml                   .xsession-errors
.chewing       .gnome           .mozilla             .zshrc
Desktop        .gnome2          .nautilus
.dmrc          .gnome2_private  .recently-used.xbel
[root@localhost linux]# ls -l -a
總計 264
drwx------ 20 linux linux 4096 11-10 21:32 .
drwxr-xr-x 12 root  root  4096 10-25 20:11 ..
-rw-------  1 linux linux  754 11-10 21:48 .bash_history
-rw-r--r--  1 linux linux   33 2008-10-21 .bash_logout
-rw-r--r--  1 linux linux  176 2008-10-21 .bash_profile
-rw-r--r--  1 linux linux  124 2008-10-21 .bashrc
drwx------  2 linux linux 4096 10-15 21:34 .chewing
drwxr-xr-x  2 linux linux 4096 10-16 06:02 Desktop
-rw-------  1 linux linux   26 10-15 21:34 .dmrc
drwxr-x---  2 linux linux 4096 10-15 21:34 .eggcups
-rw-r--r--  1 linux linux  515 2007-12-11 .emacs
-rw-rw-r--  1 linux linux    0 10-16 07:04 file1.txt
-rw-rw-r--  1 linux linux    0 10-16 07:07 file2.txt
drwx------  4 linux linux 4096 11-10 21:32 .gconf
drwx------  2 linux linux 4096 11-10 21:48 .gconfd
drwxrwxr-x  3 linux linux 4096 10-15 21:34 .gnome
drwx------  7 linux linux 4096 10-16 06:05 .gnome2
drwx------  2 linux linux 4096 10-15 21:34 .gnome2_private
drwxrwxr-x  2 linux linux 4096 10-15 21:34 .gstreamer-0.10
-rw-r--r--  1 linux linux   87 10-15 21:34 .gtkrc-1.2-gnome2
-rw-------  1 linux linux 1512 11-10 21:32 .ICEauthority
drwxr-xr-x  3 linux linux 4096 10-15 21:27 .kde
drwx------  3 linux linux 4096 10-15 21:34 .metacity
drwxrwxr-x  2 linux linux 4096 10-16 07:10 ml
drwxr-xr-x  5 linux linux 4096 11-10 20:57 .mozilla
drwxr-xr-x  3 linux linux 4096 10-15 21:34 .nautilus
-rw-rw-r--  1 linux linux  848 10-16 06:06 .recently-used.xbel
drwxrwxr-x  3 linux linux 4096 10-15 21:34 .redhat
drwx------  4 linux linux 4096 11-01 09:32 .scim
drwx------  2 linux linux 4096 11-01 09:39 .ssh
drwx------  2 linux linux 4096 10-15 21:34 .Trash
-rw-------  1 linux linux  574 11-01 05:26 .viminfo
-rw-r--r--  1 linux linux 2097 11-10 21:34 .xsession-errors
-rw-r--r--  1 linux linux  658 2009-04-15 .zshrc
[root@localhost linux]# ls -la
總計 264
drwx------ 20 linux linux 4096 11-10 21:32 .
drwxr-xr-x 12 root  root  4096 10-25 20:11 ..
-rw-------  1 linux linux  754 11-10 21:48 .bash_history
-rw-r--r--  1 linux linux   33 2008-10-21 .bash_logout
-rw-r--r--  1 linux linux  176 2008-10-21 .bash_profile
-rw-r--r--  1 linux linux  124 2008-10-21 .bashrc
drwx------  2 linux linux 4096 10-15 21:34 .chewing
drwxr-xr-x  2 linux linux 4096 10-16 06:02 Desktop
-rw-------  1 linux linux   26 10-15 21:34 .dmrc
drwxr-x---  2 linux linux 4096 10-15 21:34 .eggcups
-rw-r--r--  1 linux linux  515 2007-12-11 .emacs
-rw-rw-r--  1 linux linux    0 10-16 07:04 file1.txt
-rw-rw-r--  1 linux linux    0 10-16 07:07 file2.txt
drwx------  4 linux linux 4096 11-10 21:32 .gconf
drwx------  2 linux linux 4096 11-10 21:48 .gconfd
drwxrwxr-x  3 linux linux 4096 10-15 21:34 .gnome
drwx------  7 linux linux 4096 10-16 06:05 .gnome2
drwx------  2 linux linux 4096 10-15 21:34 .gnome2_private
drwxrwxr-x  2 linux linux 4096 10-15 21:34 .gstreamer-0.10
-rw-r--r--  1 linux linux   87 10-15 21:34 .gtkrc-1.2-gnome2
-rw-------  1 linux linux 1512 11-10 21:32 .ICEauthority
drwxr-xr-x  3 linux linux 4096 10-15 21:27 .kde
drwx------  3 linux linux 4096 10-15 21:34 .metacity
drwxrwxr-x  2 linux linux 4096 10-16 07:10 ml
drwxr-xr-x  5 linux linux 4096 11-10 20:57 .mozilla
drwxr-xr-x  3 linux linux 4096 10-15 21:34 .nautilus
-rw-rw-r--  1 linux linux  848 10-16 06:06 .recently-used.xbel
drwxrwxr-x  3 linux linux 4096 10-15 21:34 .redhat
drwx------  4 linux linux 4096 11-01 09:32 .scim
drwx------  2 linux linux 4096 11-01 09:39 .ssh
drwx------  2 linux linux 4096 10-15 21:34 .Trash
-rw-------  1 linux linux  574 11-01 05:26 .viminfo
-rw-r--r--  1 linux linux 2097 11-10 21:34 .xsession-errors
-rw-r--r--  1 linux linux  658 2009-04-15 .zshrc
[root@localhost linux]# 

 

7.查詢命令幫助  ls  --help

[root@localhost linux]# ls  --help
用法:ls [選項]... [文件]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort.

長選項必須用的參數在使用短選項時也是必須的。
  -a, --all                  不隱藏任何以 . 字符開始的項目
  -A, --almost-all           列出除了 . 及 .. 以外的任何項目
      --author               和 -l 同時使用時列出每個文件的作者
  -b, --escape               以八進制溢出序列表示不可打印的字符
      --block-size=大小      塊以指定<大小>的字節為單位
  -B, --ignore-backups       不列出任何以 ~ 字符結束的項目
  -c                         配合 -lt:根據 ctime 排序及顯示 ctime (文件
                               狀態最后更改的時間)
                               配合 -l:顯示 ctime 但根據名稱排序
                               否則:根據 ctime 排序
  -C                         list entries by columns
      --color[=WHEN]         control whether color is used to distinguish file
                               types.  WHEN may be `never', `always', or `auto'
  -d, --directory            list directory entries instead of contents,
                               and do not dereference symbolic links
  -D, --dired                generate output designed for Emacs' dired mode
  -f                         do not sort, enable -aU, disable -lst
  -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
  -G, --no-group             like -l, but do not list group
  -h, --human-readable       with -l, print sizes in human readable format
                               (e.g., 1K 234M 2G)
      --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)
      --indicator-style=WORD append indicator with style WORD to entry names:
                               none (default), slash (-p),
                               file-type (--file-type), classify (-F)
  -i, --inode                with -l, print the index number of each file
  -I, --ignore=PATTERN       do not list implied entries matching shell PATTERN
  -k                         like --block-size=1K
  -l                         使用較長格式列出信息
  -L, --dereference          當顯示符號鏈接的文件信息時,顯示符號鏈接所指示
                               的對象而並非符號鏈接本身的信息
  -m                         所有項目以逗號分隔,並填滿整行行寬
  -n, --numeric-uid-gid      like -l, but list numeric user and group IDs
  -N, --literal              print raw entry names (don't treat e.g. control
                               characters specially)
  -o                         like -l, but do not list group information
  -p, --indicator-style=slash
                             append / indicator to directories
  -q, --hide-control-chars   以 ? 字符代替無法打印的字符
      --show-control-chars   直接顯示無法打印的字符 (這是默認方式,除非調用
                               的程序名稱是“ls”而且是在終端機畫面輸出結果)
  -Q, --quote-name           將項目名稱括上雙引號
      --quoting-style=方式   使用指定的 quoting <方式>顯示項目的名稱:
                               literal、locale、shell、shell-always、c、escape
  -r, --reverse              逆序排序
  -R, --recursive            遞歸列出所有子目錄
  -s, --size                 和 -l 同時使用時以塊為單位列出每個文件的大小
  -S                         根據文件大小排序
      --sort=WORD            以下是可選用的 WORD 和它們代表的相應選項:
                               extension -X       status   -c
                               none      -U       time     -t
                               size      -S       atime    -u
                               time      -t       access   -u
                               version   -v       use      -u
      --time=WORD            和 -l 同時使用時顯示 WORD 所代表的時間而非修改時
                             間:atime、access、use、ctime 或 status;加上
                             --sort=time 選項時會以指定時間作為排序關鍵字
      --time-style=STYLE     和 -l 同時使用時根據 STYLE 代表的格式顯示時間:
                               full-iso、iso、locale、posix-iso、+FORMAT。
                             FORMAT 即是“date”所用的時間格式;如果 FORMAT
                             是 FORMAT1<新行>FORMAT2,FORMAT1 適用於較舊
                             的文件而 FORMAT2 適用於較新的文件;如果 STYLE
                             以“posix-”開頭,則 STYLE 僅在 POSIX 語系之外
                             生效。
  -t                         根據修改時間排序
  -T, --tabsize=寬度         自行指定 tab 的<寬度>,而非 8 個字符
  -u                         with -lt: sort by, and show, access time
                               with -l: show access time and sort by name
                               otherwise: sort by access time
  -U                         do not sort; list entries in directory order.
                             In combination with one_per_line format `-1',
                             it will show files immediately and it has no
                             memory limitations.
  -v                         sort by version
  -w, --width=COLS           自行指定螢幕寬度而不使用目前的數值
  -x                         逐行列出項目而不是逐欄列出
  -X                         根據擴展名排序
  -1                         每行只列出一個文件

SELinux options:

      --lcontext             Display security context.   Enable -l. Lines
                               will probably be too wide for most displays.
      -Z, --context          Display security context so it fits on most
                               displays.  Displays only mode, user, group,
                               security context and file name.
      --scontext             Display only security context and file name.


      --help     顯示此幫助信息並退出
      --version  輸出版本信息並退出

[大小]可以是以下的單位(單位前可加上整數):
kB 1000,K 1024,MB 1000000,M 1048576,還有 G、T、P、E、Z、Y。

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

Exit status is 0 if OK, 1 if minor problems, 2 if serious trouble.

請向 <bug-coreutils@gnu.org> 報告錯誤。
[root@localhost linux]# 
ls --help

 

8.mkdir 創建文件夾

[root@localhost linux]# ll
總計 24
drwxr-xr-x 2 linux linux 4096 10-16 06:02 Desktop
-rw-rw-r-- 1 linux linux    0 10-16 07:04 file1.txt
-rw-rw-r-- 1 linux linux    0 10-16 07:07 file2.txt
drwxrwxr-x 2 linux linux 4096 10-16 07:10 ml
You have new mail in /var/spool/mail/root
[root@localhost linux]# mkdir  a
[root@localhost linux]# mkdir -p b/c/d
[root@localhost linux]# mkdir    1 2 3
[root@localhost linux]# ll
總計 64
drwxr-xr-x 2 root  root  4096 11-21 23:41 1
drwxr-xr-x 2 root  root  4096 11-21 23:41 2
drwxr-xr-x 2 root  root  4096 11-21 23:41 3
drwxr-xr-x 2 root  root  4096 11-21 23:41 a
drwxr-xr-x 3 root  root  4096 11-21 23:41 b
drwxr-xr-x 2 linux linux 4096 10-16 06:02 Desktop
-rw-rw-r-- 1 linux linux    0 10-16 07:04 file1.txt
-rw-rw-r-- 1 linux linux    0 10-16 07:07 file2.txt
drwxrwxr-x 2 linux linux 4096 10-16 07:10 ml
[root@localhost linux]#

 

 

9.mv移動

  始終只有1份  cp拷貝 原文件不動,新增一份

[root@localhost linux]# ll
總計 60
drwxr-xr-x 2 root  root  4096 11-21 23:49 1
drwxr-xr-x 2 root  root  4096 11-21 23:41 2
drwxr-xr-x 2 root  root  4096 11-21 23:41 3
drwxr-xr-x 2 root  root  4096 11-21 23:48 a
drwxr-xr-x 3 root  root  4096 11-21 23:41 b
drwxr-xr-x 2 linux linux 4096 10-16 06:02 Desktop
-rw-rw-r-- 1 linux linux    0 10-16 07:07 file2.txt
drwxrwxr-x 2 linux linux 4096 10-16 07:10 ml
[root@localhost linux]# mv file2.txt 2/
[root@localhost linux]# ll 2/
總計 4
-rw-rw-r-- 1 linux linux 0 10-16 07:07 file2.txt

 

 

 

10.如何創建一個空文件 或者把一個文件設置為空

  touch rz.log 如何創建一個空文件
  echo "" > rz.log1 慎用
  cat /dev/null > ruoze.log20191113 把一個文件設置為空

[root@localhost 3]# ll
總計 0
[root@localhost 3]# touch rz.log
[root@localhost 3]# echo "" > rz.log1
[root@localhost 3]# ll
總計 12
-rw-r--r-- 1 root root 0 11-21 23:53 rz.log
-rw-r--r-- 1 root root 1 11-21 23:53 rz.log1
[root@localhost 3]# cat /dev/null > ruoze.log20191113
[root@localhost 3]# ll
總計 16
-rw-r--r-- 1 root root 0 11-21 23:53 ruoze.log20191113
-rw-r--r-- 1 root root 0 11-21 23:53 rz.log
-rw-r--r-- 1 root root 1 11-21 23:53 rz.log1
[root@localhost 3]# 

 

 

11.查看文件內容 

 cat 文件內容一下子全部顯示
  more 文件內容一頁一頁的往下翻,按空格鍵往下,回退不了,按q退出
  less 文件內容 往下 往上 按上下箭頭的按鍵 按q鍵退出

 

12.實時 tail -f xxx.log 和 ail -F xxx.log 的查看日志的區別:

  配置文件 內容較少 cat more less
  log日志 內容較多   

  實時查看 :

    tail -f xxx.log
    tail -F xxx.log -f+ retry
    flume exec source 切記使用 -F
    xxx.log log4j代碼項目 配置輸出的日志
    

  規則: xxx.log 保留10份 100M

    aaa-->xxx.log 99m
    xxx.log 100m
    mv xxx.log xxx.log1
    touch xxx.log 空文件

 

13.當發生ERROR 如何快速定位  

  a.文件內容很小 幾十兆,上傳給window,用editplus工具打開

    上傳下載 yum install -y lrzsz

 

  b.文件內容很大 幾百兆 2G
    cat xxx.log | grep ERROR

 

14.命令輸出結果 | 命令輸入的 管道符

  grep過濾:

cat xxx.log | grep -A 10 ERROR 后10行
cat xxx.log | grep -B 10 ERROR 前10行
cat xxx.log | grep -C 30 ERROR 前后各30行 經常用 迅速定位ERROR上下文

tail -300f messages 實時查看倒數300行文件
tail -300F messages 不能這樣寫
tail: option used in invalid context -- 3

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM