Actual case operation

Source: Internet
Author: User
Tags egrep

Outline

    1. Basic Disk Management operations

    2. grep and regular expression

    3. Find basic operations

    4. Special permissions


Environmental statement:Operating system:centos.7.0


1.1) Create a 10G file system, type EXT4, requires the boot can be automatically mounted to a separate data/data directory;

You can first use the fdisk command to view the disk information on the current system, where we only view information about the /dev/sdb disk device, ensuring that there is enough space to partition the operation

#fdisk-L/dev/sdbdisk/dev/sdb:53.7 GB, 53687091200 bytes, 104857600 sectorsunits = sectors of 1 * = Bytessector Size (logical/physical): bytes/512 bytesi/o size (minimum/optimal): bytes/512 bytes

As can be seen from the above information, the/dev/sdb device has a size of about 50GB and is divided into any partition. Now to partition a 10GB size EXT4 file system type for the /dev/sdb disk device, and the boot automatically mounts in the/data directory

Disk Management using the fdisk command

#fdisk/dev/sdb

After entering the mode, you can use the p command to view the partition on the current device (the current device has no partitions)

Command (M for help): P disk/dev/sdb:53.7 GB, 53687091200 bytes, 104857600 sectorsunits = sectors of 1 * MB = bytes Sector size (logical/physical): bytes/512 bytesi/o size (minimum/optimal): bytes/512 bytesdisk label Type:dos Disk identifier:0xdda9498c Device Boot Start End Blocks Id systemcommand (M for help):

Then let's create a new partition using the n option;

Here, let's Select a partition type, default to primary partition, select Main partition

Input sector start bit, we use default, enter can

Input sector size, you can use +{k,m,g}, using +10g

Prompt for partition settings of size 10GB to complete

Command (M for help): Npartition Type:p Primary (0 primary, 0 extended, 4 free) e extendedselect (default p): PPa Rtition number (1-4, default 1): 1First sector (2048-104857599, default 2048): Using default value 2048Last sector, +secto RS or +size{k,m,g} (2048-104857599, default 104857599): +10gpartition 1 of type Linux and of size ten GiB is set

Use the P command again to view and confirm the error after using the w command to save the exit

command  (M FOR HELP): p disk /dev/sdb: 53.7 gb, 53687091200  bytes, 104857600 sectorsunits = sectors of 1 * 512 = 512  bytesSector size  (logical/physical): 512 bytes / 512 bytesi/o  size  (Minimum/optimal): 512 bytes / 512 bytesdisk label type:  dosdisk identifier: 0xdda9498c    device boot       start         end      blocks    Id  System/dev/sdb1             2048    20973567    10485760   83   Linux Command  (m for help):  wthe partition table has been  altered! calling&Nbsp;ioctl ()  to re-read partition table. 

Exit fdisk-l View

#fdisk-L/dev/sdb disk/dev/sdb:53.7 GB, 53687091200 bytes, 104857600 sectorsunits = sectors of 1 * = Bytessecto R Size (logical/physical): bytes/512 bytesi/o size (minimum/optimal): bytes/512 bytesdisk label Type:dosdisk     identifier:0xdda9498c Device Boot Start End Blocks Id system/dev/sdb1 2048 20973567 10485760 Linux

You can see that the partition has been successfully created, and after the creation is complete, format the partition

You can use mkfs.{ EXT2,3,4,XFS...},MKE2FS and other commands to create a partition of the EXT series

Use the mkfs.ext4 and mke2fs commands to create EXT4-type partitions, respectively

#mkfs. ext4/dev/sdb1

#mke2fs-T Ext4

View the partitioning situation,

#fdisk-L/dev/sdb disk/dev/sdb:53.7 GB, 53687091200 bytes, 104857600 sectorsunits = sectors of 1 * = Bytessecto R Size (logical/physical): bytes/512 bytesi/o size (minimum/optimal): bytes/512 bytesdisk label Type:dosdisk     identifier:0xdda9498c Device Boot Start End Blocks Id system/dev/sdb1 2048 20973567 10485760 Linux

View partition UUID and type

#blkid/dev/sdb1/dev/sdb1:uuid= "f5749efa-ca95-44dd-ae6e-8b04cbc23920" type= "Ext4"

Create automatic mount directories and set automatic mounts (use default Mount selection, no backup not self-test)

#mkdir/data#echo "Uuid=f5749efa-ca95-44dd-ae6e-8b04cbc23920/data ext4 defaults 0 0" >>/etc/fstab

After the setup is complete, use the mount-a command to update the Mount information and view the Mount condition, confirm that the system can be mounted and reboot, and the/dev/sdb1 partition will automatically mount to the /data directory when it is started again.

# mount-a # Mount | TAIL-1/DEV/SDB1 on/data type EXT4 (rw,relatime,seclabel,data=ordered)


2.1) Filter netstat-ant results to listen a line followed by 0 or more white-space characters

#netstat-ant | Egrep "$LISTEN [[: space:]]*$]


2.2) Create Nginx, Zabbix, Tomcat, Nologin, and hadoop,nologin user default shell for /sbin/nologin, find out /etc/passwd File whose user name is the same as the shell

#useradd nginx ... #useradd nologin-s/sbin/nologin#egrep "^ ([[: alnum:]]+\b). *\1$"/etc/passwd

2.3) Find a word in the /etc/rc.d/init.d/functions file (the middle of the word can be underlined) followed by a set of parentheses on the line

#egrep "[_[:alpha:]]+\ (\)" Functions

2.4) Use echo to output a path, and then egrep to find its path base name, and further use Egrep to remove its directory name (note that the directory name, not the directory path)

#echo "/hello/world" |egrep-o "[^/]+/?$" |cut-d "/"-f1#

3.1) Find all files that are not root, bin, or Hadoop under the/ usr directory

#find/usr-! \ (-user root-o-user bin-o-user hadoop \)

3.2) Find all files on the current system that are not owned by the master or group and have been visited in the last week;

In addition, it is necessary to find all files of more than 20k and type ordinary files in/ etc directory;

#find/-type f \ (-nouser-o-nogroup \)-a-atime-7#find/-type f/etc-size +20k

4.1) Create a directory /test/data, let a group of ordinary users have write permissions to it, and all the files created by the group is the directory belongs to the group, in addition, each user can only delete their own files.

#grep   "Usgroup"  /etc/groupusgroup::1006:usert,userf#mkdir /test/data && chown  :usgroup /test/data && chmod g+ws o+t /test/data#ls -ld  /test/datadrwxrwsr-t. 2 root usgroup 4096 dec 21 17:56 /test/data#  su -l usert$ touch /test/data/tfile && mkdir /test/data/tdir$  exit logout# su -l userf$ touch /test/data/ffile &&  mkdir /test/data/fdir$ ll  /test/data/total 8drwxrwsr-x. 2 userf  Usgroup 4096 dec 21 18:08 fdir-rw-rw-r--.  1 userf usgroup     0 Dec 21 18:08 ffiledrwxrwsr-x. 2 usert usgroup 4096  Dec 21 18:07 tdir-rw-rw-r--.  1 usert usgroup    0 dec  21 18:07 tFile$ rm /test/data/ffile $ rm /test/data/tfile rm: cannot remove   '/test/data/tfile ': operation not permitted$ ll  /test/data/total  8drwxrwsr-x. 2 userf usgroup 4096 dec 21 18:08 fdirdrwxrwsr-x. 2  usert usgroup 4096 dec 21 18:07 tdir-rw-rw-r--.  1 usert  Usgroup    0 dec 21 18:07 tfile


This article from "Whang" blog, reproduced please contact the author!

Actual case operation

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.