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


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章