数据仓库001 - 复习Linux shell命令 - 01




1.  [[email protected] ~]#  的含义 ?

   【登录的用户  机器的名称 家目录】

2. 查看当前光标所在的目录   pwd

[[email protected] ~]# pwd
/root

3. 切换目录 cd

[[email protected] ~]# cd /home
[[email protected] home]# pwd
/home

  root用户 家目录 /root 规定
  xxx用户 家目录 /home/xxx 默认

回退家目录 的三种方法:

[[email protected] home]# cd -
/root
[[email protected] ~]# cd /home
[[email protected] home]# cd ~
[[email protected] ~]# cd /home
[[email protected] home]# cd /root
[[email protected] ~]#

cd ../ 回退上一层目录
cd ../../ 回退上2层目录

[[email protected] ~]# cd /home/linux/
[[email protected] linux]# pwd
/home/linux
[[email protected] linux]# cd ../
[[email protected] home]# pwd
/home
[[email protected] home]# cd /home/linux
[[email protected] linux]# pwd
/home/linux
[[email protected] linux]# cd ../../
[[email protected] /]# pwd
/
[[email protected] /]# 

4.目录 文件夹  路径

  ·绝对路径 /根目录 以根目录

  ·相对路径 不以根目录为开始,以当前光标所在的目录为开始

5.clear  清空屏幕

6.ls查看当前光标所在的目录下,文件和文件夹都有哪些

其中ls 、ll的区别,其中ll 就是ls -l:

[[email protected] /]# ls
bin   dev  home  lost+found  misc  net  proc  sbin     srv  tftpboot  usr
boot  etc  lib   media       mnt   opt  root  selinux  sys  tmp       var
[[email protected] /]# 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
[[email protected] /]# 

 小结:

  ls -l ==> 等价于ll
  ls -l -a 查看当前的文件文件夹+ 隐藏文件文件夹   以.开头
  ll -h 文件的大小

  ll -rt 按时间排序

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

实例:

[[email protected] /]# cd /home/linux/
[[email protected] linux]# ls
Desktop  file1.txt  file2.txt  ml
[[email protected] 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
[[email protected] 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
[[email protected] 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
[[email protected] 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
[[email protected] linux]# 

7.查询命令帮助  ls  --help

[[email protected] 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.

请向 <[email protected]> 报告错误。
[[email protected] linux]# 

ls --help

8.mkdir 创建文件夹

[[email protected] 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
[[email protected] linux]# mkdir  a
[[email protected] linux]# mkdir -p b/c/d
[[email protected] linux]# mkdir    1 2 3
[[email protected] 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
[[email protected] linux]#

9.mv移动 始终只有1份  cp拷贝 原文件不动,新增一份

[[email protected] 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
[[email protected] linux]# mv file2.txt 2/
[[email protected] 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 把一个文件设置为空

[[email protected] 3]# ll
总计 0
[[email protected] 3]# touch rz.log
[[email protected] 3]# echo "" > rz.log1
[[email protected] 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
[[email protected] 3]# cat /dev/null > ruoze.log20191113
[[email protected] 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
[[email protected] 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

原文地址:https://www.cnblogs.com/Raodi/p/11909311.html

时间: 2024-08-29 16:09:22

数据仓库001 - 复习Linux shell命令 - 01的相关文章

37条常用Linux Shell命令组合

序号 任务 命令组合 1 删除0字节文件 find . -type f -size 0 -exec rm -rf {} \; find . type f -size 0 -delete 2 查看进程,按内存从大到小排列 ps -e -o “%C : %p : %z : %a”|sort -k5 -nr 3 按cpu利用率从大到小排列 ps -e -o “%C : %p : %z : %a”|sort -nr 4 打印说cache里的URL grep -r -a jpg /data/cache/*

常用Linux Shell命令组合

序号 任务 命令组合 1 删除0字节文件 find . -type f -size 0 -exec rm -rf {} \;find . type f -size 0 -delete 2 查看进程,按内存从大到小排列 ps -e -o “%C : %p : %z : %a”|sort -k5 -nr 3 按cpu利用率从大到小排列 ps -e -o “%C : %p : %z : %a”|sort -nr 4 打印说cache里的URL grep -r -a jpg /data/cache/*

linux shell 命令学习(5) xxd- make a hexdump or do the reverse.

对于标准输入或者给定的文件,显示其16进制的内容.也可以反过来进行转换. ? 1 2 3 xxd -h[elp] xxd [options] [infile [outfile]] xxd -r[evert] [options] [infile [outfile]] 如果没有指定输入文件, 则采用标准输入. -b: 以2进制格式进行输出 ? 1 2 3 4 [[email protected] src]$ xxd -b train.ini 0000000: 01011011 01110100 01

[Python] 利用commands模块执行Linux shell命令

用Python写运维脚本时,经常需要执行linux shell的命令,Python中的commands模块专门用于调用Linux shell命令,并返回状态和结果,下面是commands模块的3个主要函数: 1. commands.getoutput('shell command') 执行shell命令,返回结果(string类型) >>> commands.getoutput('pwd') '/home/oracle' 2. commands.getstatus('file') 该函数

linux shell 命令

linux shell 命令 什么是Shell? Shell 是连接操作系统内核 与 用户 的接口. 终端是shell的表现形式. 什么是Shell编程? Shell 脚本语言加上linux 命令语句就构成了shell程序.优点在于批量处理.不用用户每次手动输入. bash是shell程序解释器的一种. 常用命令 pwd:print working directory,打印工作目录. cd:chang directory,改变工作目录. 可使用绝对命令或相对命令. ls:list,查看目录内容.

[Shell&amp;Mac&amp;Environment variables]自己常用的Mac(或者说Linux)Shell命令小结,含Mac使用zsh shell的环境变量的有关配置方法

今天在使用tomcat的配置的时候,我用的mac,要是用到一些命令去配置tomcat. 问题来了: 我每次要去启动tomcat服务特别麻烦,因为我要先进入tomcat所在的文件目录,或者不进入使用~/,但是因为我把tomcat放到了一个比较“深“的文件夹里,所以命令显得又丑又长. 问题解决方案: 1.使用环境变量(修改.bashrc的方法) a.先查看自己的Mac目前正在用的是什么shell echo $SHELL 返回结果类似如下图 这里我是zsh,,也许你是bash,不过没关系,配置环境变量

java执行linux shell命令,并拿到返回值

1 package com.suning.spc.util; 2 3 import java.io.IOException; 4 import java.io.InputStream; 5 import java.nio.charset.Charset; 6 7 import org.slf4j.Logger; 8 import org.slf4j.LoggerFactory; 9 10 import ch.ethz.ssh2.ChannelCondition; 11 import ch.eth

使用Runtime.exec()运行windwos dos或linux shell命令

使用Runtime.exec()运行windwos dos或linux shell命令,按实际情况具体测试 实例代码: package com.bookoo.test.command; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter

Linux shell命令 cp 加上-f还是提示是否覆盖

这是因为环境变量中有 allias cp='cp -i' 为了去掉这个系统自带的别名,可以使用grep -r --include="*" "alias cp"  /查找设置这个环境变量的脚本文件: 我的ubuntu机器上是: ./.bash_aliases:alias cp='cp -i' 于是我将./.bash_aliases文件中的这句话去掉即可 然后使用 source ./.bash_aliases 使其立即生效 2014年7月5日11:49:54 www.u