linux实战案例-1

1、创建一个10G的文件系统,类型为ext4,要求开机可自动挂载至单独数据/data目录;

[root@localhost ~]# dd if=/dev/zero of=/root/test bs=10M count=1000

记录了1000+0 的读入

记录了1000+0 的写出

10485760000字节(10 GB)已复制,13.7358 秒,763 MB/秒

[root@localhost ~]# losetup /dev/loop0 /root/test 

[root@localhost ~]# mkfs.ext4 -L MyData /dev/loop0 

mke2fs 1.42.9 (28-Dec-2013)

Discarding device blocks: 完成                            

文件系统标签=MyData

OS type: Linux

块大小=4096 (log=2)

分块大小=4096 (log=2)

Stride=0 blocks, Stripe width=0 blocks

640848 inodes, 2560000 blocks

128000 blocks (5.00%) reserved for the super user

第一个数据块=0

Maximum filesystem blocks=2151677952

79 block groups

32768 blocks per group, 32768 fragments per group

8112 inodes per group

Superblock backups stored on blocks: 

32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632


Allocating group tables: 完成                            

正在写入inode表: 完成                            

Creating journal (32768 blocks): 完成

Writing superblocks and filesystem accounting information: 完成 


[root@localhost ~]# vim /etc/fstab 

-bash: vim: 未找到命令

[root@localhost ~]# vi /etc/fstab 


#

# /etc/fstab

# Created by anaconda on Sat Dec 12 16:40:22 2015

#

# Accessible filesystems, by reference, are maintained under '/dev/disk'

# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info

#

/dev/mapper/centos-root /                       xfs     defaults        0 0

UUID=a75083b6-f119-487d-a023-3f98dcfd438a /boot                   xfs     defaults        0 0

/dev/mapper/centos-swap swap                    swap    defaults        0 0

LABEL='MyData' /data ext4 defaults 0 0



2、显示`netstat -tan`命令结果中以‘LISTEN’后跟0个、1个或者多个空白字符结尾的行;

    centos7需要安装net-tools才可使用netstat工具

    yum install net-tools

[root@localhost ~]# netstat -tan | grep "LISTEN *$"

tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     

tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN     

tcp6       0      0 :::22                   :::*                    LISTEN     

tcp6       0      0 ::1:25                  :::*                    LISTEN     

[root@localhost ~]# 


3、添加用户nginx、zabbix、tomcat、nologin以及hadoop用户(nologin用户的shell为/sbin/nologin);而后找出/etc/passwd文件中用户名与其shell名相同的行;


[root@localhost ~]# 

[root@localhost ~]# useradd nginx

[root@localhost ~]# useradd zabbix

[root@localhost ~]# useradd tomcat

[root@localhost ~]# useradd hadoop

[root@localhost ~]# useradd nologin -s /sbin/nologin

[root@localhost ~]# cat /etc/passwd | grep "^\(.*\):.*/\1$"

sync:x:5:0:sync:/sbin:/bin/sync

shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown

halt:x:7:0:halt:/sbin:/sbin/halt

nologin:x:1005:1005::/home/nologin:/sbin/nologin

[root@localhost ~]# 


4、找出/etc/rc.d/init.d/functions文件中某单词(单词中间可以存在下划线)后面跟着一组小括号的行;

[root@localhost ~]# cat /etc/rc.d/init.d/functions | grep "[a-z | _]()"

systemctl_redirect () {

checkpid() {

__pids_var_run() {

__pids_pidof() {

daemon() {

killproc() {

pidfileofproc() {

pidofproc() {

status() {

echo_success() {

echo_failure() {

echo_passed() {

echo_warning() {

update_boot_stage() {

success() {

failure() {

passed() {

warning() {

action() {

strstr() {

is_ignored_file() {

is_true() {

is_false() {

apply_sysctl() {

[root@localhost ~]# 



5、使用echo输出一个路径,而后egrep找出其路径基名;进一步的使用egrep取出其目录名(注意是目录名,而非目录路径);


[root@localhost ~]# echo "/etc/text" | egrep -o "[^/]*$"

text

[root@localhost ~]# echo "/etc/text" | egrep -o ".*/" | egrep -o ".*[^/]"

/etc

[root@localhost ~]# 


6、查找/usr目录下不属于root、bin或hadoop的所有文件;


[root@localhost ~]# 

[root@localhost ~]#  find /usr -not \( -user root -o -user bin -o -user hadoop \) -ls

210602    0 drwx------   2 polkitd  root            6 6月 10  2014 /usr/share/polkit-1/rules.d

[root@localhost ~]# 


7、某天系统被入侵了,黑客在你系统下留下木马文件:

现需要查找当前系统上没有属主或属组,且最近一周内曾被访问过的所有文件;

另外,需要查找/etc目录下大于20k且类型为普通文件的所有文件;


[root@localhost ~]# clear

[root@localhost ~]# find / -atime -7 -nouser -o -nogroup

find: ‘/proc/2590/task/2590/fd/6’: 没有那个文件或目录

find: ‘/proc/2590/task/2590/fdinfo/6’: 没有那个文件或目录

find: ‘/proc/2590/fd/6’: 没有那个文件或目录

find: ‘/proc/2590/fdinfo/6’: 没有那个文件或目录

[root@localhost ~]# find /etc -type f -size +20K

find: 无效的 -size 类型“K”

[root@localhost ~]# find /etc -type f -size +20k

/etc/pki/ca-trust/extracted/java/cacerts

/etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt

/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem

/etc/pki/ca-trust/extracted/pem/email-ca-bundle.pem

/etc/pki/ca-trust/extracted/pem/objsign-ca-bundle.pem

/etc/pki/nssdb/cert8.db

/etc/udev/hwdb.bin

/etc/services

/etc/sysconfig/network-scripts/network-functions-ipv6

/etc/ssh/moduli

/etc/dnsmasq.conf

/etc/lvm/lvm.conf

/etc/selinux/targeted/contexts/files/file_contexts

/etc/selinux/targeted/modules/active/base.pp

/etc/selinux/targeted/modules/active/file_contexts

/etc/selinux/targeted/modules/active/file_contexts.template

/etc/selinux/targeted/modules/active/modules/apache.pp

/etc/selinux/targeted/modules/active/modules/init.pp

/etc/selinux/targeted/modules/active/modules/staff.pp

/etc/selinux/targeted/modules/active/modules/sysadm.pp

/etc/selinux/targeted/modules/active/modules/unprivuser.pp

/etc/selinux/targeted/modules/active/modules/virt.pp

/etc/selinux/targeted/modules/active/modules/xguest.pp

/etc/selinux/targeted/modules/active/modules/xserver.pp

/etc/selinux/targeted/policy/policy.29

/etc/openldap/certs/cert8.db

/etc/postfix/access

/etc/postfix/header_checks

/etc/postfix/main.cf

[root@localhost ~]# 

8、创建目录/test/data,让某组内普通用户对其有写权限,且创建的所有文件的属组为目录所属的组;此外,每个用户仅能删除自己的文件。


mkdir -p /test/data

chmod -R 1774 /test/data


本文出自 “机智少年普朗克” 博客,谢绝转载!

你可能感兴趣的:(linux,实战案例)