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 /]# lsbin dev home lost+found misc net proc sbin srv tftpboot usrboot etc lib media mnt opt root selinux sys tmp var[root@localhost /]# ll总计 154drwxr-xr-x 2 root root 4096 10-16 07:21 bindrwxr-xr-x 4 root root 1024 10-15 21:25 bootdrwxr-xr-x 13 root root 3980 11-10 21:50 devdrwxr-xr-x 113 root root 12288 11-10 21:50 etcdrwxr-xr-x 12 root root 4096 10-25 20:11 homedrwxr-xr-x 13 root root 12288 10-16 07:21 libdrwx------ 2 root root 16384 10-15 21:23 lost+founddrwxr-xr-x 2 root root 4096 11-10 21:50 mediadrwxr-xr-x 2 root root 0 11-10 21:50 miscdrwxr-xr-x 5 root root 4096 11-01 05:25 mntdrwxr-xr-x 2 root root 0 11-10 21:50 netdrwxr-xr-x 2 root root 4096 2009-10-01 optdr-xr-xr-x 171 root root 0 11-10 21:49 procdrwxr-x--- 7 root root 4096 11-10 22:11 rootdrwxr-xr-x 2 root root 12288 10-16 07:21 sbindrwxr-xr-x 4 root root 0 11-10 21:49 selinuxdrwxr-xr-x 2 root root 4096 2009-10-01 srvdrwxr-xr-x 12 root root 0 11-10 21:49 sysdrwxr-xr-x 3 root root 4096 10-15 21:26 tftpbootdrwxrwxrwt 25 root root 4096 11-10 21:50 tmpdrwxr-xr-x 14 root root 4096 10-15 21:24 usrdrwxr-xr-x 26 root root 4096 10-15 21:28 var[root@localhost /]#
小结:
ls -l ==> 等价于ll
ls -l -a 查看当前的文件文件夹+ 隐藏文件文件夹 以.开头
ll -h 文件的大小
ll -rt 按时间排序
lsls -lls -als -l -a ==> ls -la
实例:
[root@localhost /]# cd /home/linux/[root@localhost linux]# lsDesktop file1.txt file2.txt ml[root@localhost linux]# ls -l总计 24drwxr-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.txtdrwxrwxr-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 .zshrcDesktop .gnome2 .nautilus.dmrc .gnome2_private .recently-used.xbel[root@localhost linux]# ls -l -a总计 264drwx------ 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 .bashrcdrwx------ 2 linux linux 4096 10-15 21:34 .chewingdrwxr-xr-x 2 linux linux 4096 10-16 06:02 Desktop-rw------- 1 linux linux 26 10-15 21:34 .dmrcdrwxr-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.txtdrwx------ 4 linux linux 4096 11-10 21:32 .gconfdrwx------ 2 linux linux 4096 11-10 21:48 .gconfddrwxrwxr-x 3 linux linux 4096 10-15 21:34 .gnomedrwx------ 7 linux linux 4096 10-16 06:05 .gnome2drwx------ 2 linux linux 4096 10-15 21:34 .gnome2_privatedrwxrwxr-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 .ICEauthoritydrwxr-xr-x 3 linux linux 4096 10-15 21:27 .kdedrwx------ 3 linux linux 4096 10-15 21:34 .metacitydrwxrwxr-x 2 linux linux 4096 10-16 07:10 mldrwxr-xr-x 5 linux linux 4096 11-10 20:57 .mozilladrwxr-xr-x 3 linux linux 4096 10-15 21:34 .nautilus-rw-rw-r-- 1 linux linux 848 10-16 06:06 .recently-used.xbeldrwxrwxr-x 3 linux linux 4096 10-15 21:34 .redhatdrwx------ 4 linux linux 4096 11-01 09:32 .scimdrwx------ 2 linux linux 4096 11-01 09:39 .sshdrwx------ 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总计 264drwx------ 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 .bashrcdrwx------ 2 linux linux 4096 10-15 21:34 .chewingdrwxr-xr-x 2 linux linux 4096 10-16 06:02 Desktop-rw------- 1 linux linux 26 10-15 21:34 .dmrcdrwxr-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.txtdrwx------ 4 linux linux 4096 11-10 21:32 .gconfdrwx------ 2 linux linux 4096 11-10 21:48 .gconfddrwxrwxr-x 3 linux linux 4096 10-15 21:34 .gnomedrwx------ 7 linux linux 4096 10-16 06:05 .gnome2drwx------ 2 linux linux 4096 10-15 21:34 .gnome2_privatedrwxrwxr-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 .ICEauthoritydrwxr-xr-x 3 linux linux 4096 10-15 21:27 .kdedrwx------ 3 linux linux 4096 10-15 21:34 .metacitydrwxrwxr-x 2 linux linux 4096 10-16 07:10 mldrwxr-xr-x 5 linux linux 4096 11-10 20:57 .mozilladrwxr-xr-x 3 linux linux 4096 10-15 21:34 .nautilus-rw-rw-r-- 1 linux linux 848 10-16 06:06 .recently-used.xbeldrwxrwxr-x 3 linux linux 4096 10-15 21:34 .redhatdrwx------ 4 linux linux 4096 11-01 09:32 .scimdrwx------ 2 linux linux 4096 11-01 09:39 .sshdrwx------ 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 isequivalent to using --color=none. Using the --color option without theoptional WHEN argument is equivalent to using --color=always. With--color=auto, color codes are output only if standard output is connectedto a terminal (tty). The environment variable LS_COLORS can influence thecolors, 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总计 24drwxr-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.txtdrwxrwxr-x 2 linux linux 4096 10-16 07:10 mlYou 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总计 64drwxr-xr-x 2 root root 4096 11-21 23:41 1drwxr-xr-x 2 root root 4096 11-21 23:41 2drwxr-xr-x 2 root root 4096 11-21 23:41 3drwxr-xr-x 2 root root 4096 11-21 23:41 adrwxr-xr-x 3 root root 4096 11-21 23:41 bdrwxr-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.txtdrwxrwxr-x 2 linux linux 4096 10-16 07:10 ml[root@localhost linux]#
9.mv移动
始终只有1份 cp拷贝 原文件不动,新增一份
[root@localhost linux]# ll总计 60drwxr-xr-x 2 root root 4096 11-21 23:49 1drwxr-xr-x 2 root root 4096 11-21 23:41 2drwxr-xr-x 2 root root 4096 11-21 23:41 3drwxr-xr-x 2 root root 4096 11-21 23:48 adrwxr-xr-x 3 root root 4096 11-21 23:41 bdrwxr-xr-x 2 linux linux 4096 10-16 06:02 Desktop-rw-rw-r-- 1 linux linux 0 10-16 07:07 file2.txtdrwxrwxr-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
评论前必须登录!
立即登录