Linux OPS Engineer Essentials (command)

Source: Internet
Author: User
Tags epoll system log egrep

    1. How to filter out all the first level directories in the following directory

[email protected] ~]# LL

Total 16

-rw-r--r--1 root root 0 Jul 5 11:43 111

-rw-r--r--1 root root 0 Jul 5 11:43 222

-rw-r--r--1 root root 0 Jul 5 11:43 333

Drwxr-xr-x 2 root root 4096 Jul 5 11:43 AAA

Drwxr-xr-x 2 root root 4096 Jul 5 11:43 BBB

Drwxr-xr-x 2 root root 4096 Jul 5 11:43 CCC

Drwxr-xr-x 2 root root 4096 Jul 5 11:43 DDD


Method 1:ls-l The result is a directory that begins with D

D[[email protected] ~]# ls-l |grep ^d drwxr-xr-x 2 root root 4096 Jul 5 11:43 aaadrwxr-xr-x 2 R by filtering the start file with long format output  oot root 4096 Jul 5 11:43 bbbdrwxr-xr-x 2 root root 4096 Jul 5 11:43 cccdrwxr-xr-x 2 root root 4096 Jul 5 11:43 ddd Hint: ^ : To ... Beginning

Method 2: Filter out the directory by labeling the directory and filtering the identity

[[email protected] ~]# ls-f #把目录结尾加上 "/", easy to distinguish and filter out, ls-p can also let the directory with a slash 111 222 333 Aaa/bbb/ccc/ddd/[[email protected ] ~]# ls-f|grep/$ #把包含斜线 "/" filtered out is the catalogue aaa/bbb/ccc/ddd/

Application of 3:find method

[[email protected] ~]# find. -type D #. Represents the current directory./aaa./ccc./bbb./ddd

Method 4:tree

[Email protected] ~]# tree-dl.| --aaa|--bbb|--CCC '--DDD

Filter lines that start with a blank line and #

[Email protected] ~]# Grep-ev "^#|^$"/etc/init.d/sshd [[email protected] ~]# egrep-v "^#|^$"/etc/init.d/sshd Comment:-E # Egrep-v #过滤 ^# #井号开头 ^$ #空行

Method 5:sed

[[email protected] ~]# Ls-l|sed-n/^d/pdrwxr-xr-x 2 root root 4096 Jul 5 11:43 aaadrwxr-xr-x 2 root root 4096 Jul 5 11 : bbbdrwxr-xr-x 2 root root 4096 Jul 5 11:43 cccdrwxr-xr-x 2 root root 4096 Jul 5 11:43 ddd Note:-N #拒绝默认输出p #打印

Method 6:awk

[[Email protected] ~] #ls-l|awk '/^d/{print $} ' drwxr-xr-x 2 root root 4096 Jul 5 11:43 aaadrwxr-xr-x 2 root root 4096 J UL 5 11:43 bbbdrwxr-xr-x 2 root root 4096 Jul 5 11:43 cccdrwxr-xr-x 2 root root 4096 Jul 5 11:43 DDD


2. If the current directory is

[Email protected] ~]# pwd #这是打印当前目录/root

Now because you need to enter the/TMP directory to operate, the following commands are executed:

[[email protected] ~]# pwd/root[[email protected] ~]# Cd/tmp/[[email protected] tmp]# CD-/root[[email protected] ~]#

Principle:

[Email protected] ~]# env|grep-i oldpwd #是这个变量记录着上一次的目录OLDPWD =/tmp


3. There are a lot of files in a directory (LS viewing a lot of screen), want to see the fastest speed to the most recent files. If you look?

Answer:

[[email protected] etc]# LS-LRT #执行这个命令后最新的文件会在最下面 # Reverse the modified time file and directory in long format so that the recently created or modified file or directory-T #按修改时间-R #翻转


4. When configuring Apache, execute the./confiure--prefix=/application/apache2.2.17 to compile Apache after make Installl is finished, you want the user's access path to be simpler, need to give/ The application/apache2.2.17 directory makes a soft link/application/apache that allows internal developers or managers to access the/apache installation directory via/application/apache application/apache2.2.17 the content, please give the implementation of the command (hint: Apache for an HTTP Web service)

[[email protected] ~]# ln-s/application/apache2.2.17/application/apache #-s parameter is represented as creating a soft link


5. The access logs for Apache services are known to be logged by day in the server local directory/data/logs, and because of the tight disk space, it is now required to keep only the last 7 days of access logs! How can I resolve this? Please provide a workaround or configure or process the command.

-rw-r--r-- 1 root root   0 jun 28 00:00 2017-06-29_00-00. backstage_access.log-rw-r--r-- 1 root root   0 jun 28 00:00  2017-06-29_00-00.backstage_error.log-rw-r--r-- 1 root root   0 jun 29  00:00 2017-06-30_00-00.backstage_access.log-rw-r--r-- 1 root root   0  jun 29 00:00 2017-06-30_00-00.backstage_error.log-rw-r--r-- 1 root root    0 jun 30 00:00 2017-07-01_00-00.backstage_access.log-rw-r--r-- 1  root root   0 jun 30 00:00 2017-07-01_00-00.backstage_ error.log-rw-r--r-- 1 root root   0 jul  1 00:00  2017-07-02_00-00.backstage_access.log-rw-r--r-- 1 root root   0 jul   1 00:00 2017-07-02_00-00.backstage_error.log-rw-r--r-- 1 root root   0 jul  2  00:00 2017-07-03_00-00.backstage_access.log-rw-r--r-- 1 root root   0  Jul  2 00:00 2017-07-03_00-00.backstage_error.log-rw-r--r-- 1 root root    0 jul  3 00:00 2017-07-04_00-00.backstage_access.log-rw-r--r--  1 root root   0 jul  3 00:00 2017-07-04_00-00. backstage_error.log-rw-r--r-- 1 root root   0 jul  4 00:00  2017-07-05_00-00.backstage_access.log-rw-r--r-- 1 root root   0 jul   4 00:00 2017-07-05_00-00.backstage_error.log-rw-r--r-- 1 root root    0 jul  5 00:00 2017-07-06_00-00.backstage_access.log-rw-r--r-- 1  root root   0&nbsp jul  5 00:00 2017-07-06_00-00.backstage_error.log[[email protected] ~]#  find ./ -type f -name  "*.log"  -mtime +7|xarge rm -f      #删除7天

Find finds time-related parameters:

-atime n #n为数字, meaning the file that was accessed by access in "one day" prior to n days;

-ctime n #n为数字, meaning a file that has a change in "one day" prior to n days

-mtime N #n is a number, meaning a file that was modification in "one day" before N days

-newer file #file As an existing file, meaning that as long as the file is newer than file, it will be listed.

Find./Type F-name "*.log"-mtime +7|xargs rm-f


6. When debugging the system service, want to be able to view the system log/var/log/messages update in real time, how to do?

Law One:

[[email protected] ~]# tail -f /var/log/messages    jul   6 14:51:40 localhost yum[29341]: installed: gnome-vfs2-devel-2.24.2-8.el6.x86_ 64jul  6 14:51:41 localhost yum[29341]: installed:  dmz-cursor-themes-0.4-4.el6.noarchjul  6 14:51:41 localhost yum[29341]:  installed: system-gnome-theme-60.0.2-1.el6.noarchjul  6 14:51:41 localhost yum[ 29341]: installed: libgnome-2.28.0-11.el6.x86_64jul  6 14:51:41 localhost  yum[29341]: installed: libgnome-devel-2.28.0-11.el6.x86_64jul  6 14:51:41  Localhost yum[29341]: installed: libbonoboui-2.24.2-3.el6.x86_64jul  6 14:51:42  localhost yum[29341]: installed: libbonoboui-devel-2.24.2-3.el6.x86_64jul  6  14:51:42 localhost yum[29341]: installed: libgnomeui-2.24.1-4.el6.x86_64jul  6 14:51:42 localhost yum[29341]:  installed: libgnomeui-devel-2.24.1-4.el6.x86_64jul  6 14:51:43 localhost yum[ 29341]: updated: glib2-2.28.8-9.el6.i686

Law two:

[[email protected] ~]# tail -f /var/log/messages  jul  6  14:51:40 localhost yum[29341]: installed: gnome-vfs2-devel-2.24.2-8.el6.x86_64jul   6 14:51:41 localhost yum[29341]: Installed:  dmz-cursor-themes-0.4-4.el6.noarchjul  6 14:51:41 localhost yum[29341]:  installed: system-gnome-theme-60.0.2-1.el6.noarchjul  6 14:51:41 localhost yum[ 29341]: installed: libgnome-2.28.0-11.el6.x86_64jul  6 14:51:41 localhost  yum[29341]: installed: libgnome-devel-2.28.0-11.el6.x86_64jul  6 14:51:41  Localhost yum[29341]: installed: libbonoboui-2.24.2-3.el6.x86_64jul  6 14:51:42  localhost yum[29341]: installed: libbonoboui-devel-2.24.2-3.el6.x86_64jul  6  14:51:42 localhost yum[29341]: installed: libGnomeui-2.24.1-4.el6.x86_64jul  6 14:51:42 localhost yum[29341]: installed:  libgnomeui-devel-2.24.1-4.el6.x86_64Jul  6 14:51:43 localhost yum[29341]:  updated: glib2-2.28.8-9.el6.i68

Law Three:

[[email protected] ~]# tailf /var/log/messages jul  6 14:51:40  localhost yum[29341]: installed: gnome-vfs2-devel-2.24.2-8.el6.x86_64jul  6  14:51:41 localhost yum[29341]: installed: dmz-cursor-themes-0.4-4.el6.noarchjul   6 14:51:41 localhost yum[29341]: Installed:  system-gnome-theme-60.0.2-1.el6.noarchjul  6 14:51:41 localhost yum[29341]:  INSTALLED: LIBGNOME-2.28.0-11.EL6.X86_64JUL  6 14:51:41 LOCALHOST YUM[29341]:  Installed: libgnome-devel-2.28.0-11.el6.x86_64Jul  6 14:51:41 localhost  Yum[29341]: installed: libbonoboui-2.24.2-3.el6.x86_64jul  6 14:51:42 localhost  yum[29341]: installed: libbonoboui-devel-2.24.2-3.el6.x86_64jul  6 14:51:42  localhost yum[29341]: installed: libgnomeui-2.24.1-4.el6.x86_64jul  6 14:51:42 localhost yum[29341]: installed:  libgnomeui-devel-2.24.1-4.el6.x86_64jul  6 14:51:43 localhost yum[29341]:  updated: glib2-2.28.8-9.el6.i686


7. How do I print the line number and content of the nginx.conf content of the configuration file?

Act 1:

[Email protected] conf]# NL nginx.conf 1 user nginx;     2 worker_processes 4;     3 4 #pid/var/run/nginx.pid;     5 6 Events {7 Worker_connections 5000;     8 #use Epoll; 9} ........ .......


Act 2:

[Email protected] conf]# cat-n nginx.conf 1 user nginx;     2 worker_processes 4;     3 4 #pid/var/run/nginx.pid;     5 6 Events {7 Worker_connections 5000;     8 #use Epoll; 9} 10 ..... .............


Act 3:

[[Email protected] conf]# less -n nginx.conf      1  user  nginx;      2 worker_processes 4;       3       4  #pid  /var/run/nginx.pid;       5       6 events {       7     worker_connections  5000;       8      #use  epoll;      9 }      10      11 http {      12     include       mime.types;      13     default_type  application/octet-stream;      14

The 4:vi file is then executed: Set NU,: Set Nonu to cancel line number









This article is from the "Little Rookie" blog, please be sure to keep this source http://baishuchao.blog.51cto.com/12918589/1945114

Linux OPS Engineer Essentials (command)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.