shell笔记

2020-11-22  本文已影响0人  酱油王0901
  1. print0xargs -0参数
    The find command prints results to standard output by default, so the -print option is normally not needed, but -print0 separates the filenames with a 0 (NULL) byte so that names containing spaces or newlines can be interpreted correctly.
    The xargs command reads space- or newline-separated strings (typically from the find command, but they could come from anywhere) and executes some command for each string.
    If xargs is run with a -0 option, it'll expect NULL-separatedstrings as output by find ... -print0
(ENV) [root@ceph-2 mount]# find /root -type f -size +1G -print0 | xargs -0 ls -l
-rw-r--r-- 1 root root 3342567446 Nov 17 19:45 /root/jenkins/installe.tar.gz
-rw-r--r-- 1 root root 3285436362 Nov 17 11:31 /root/jenkins/release
  1. /lib/modules/*/kernel/目录底下有很多 *.ko 内核模块。 这些 kernel modules 有点类型 windows 底下的驱动程序, 负责和不同的硬件沟通。 其中 fs/子目录底下的驱动程序负责认出并使用各种不同格式 (ext2/3/4、 fat、 ntfs、 isofs、 ...) 的文件系統。 它们的功能是将一长条没有组织的阵列(就是磁盘的一个分区,从第0磁道到第xxxx磁道),翻译成我们习惯的树状结构(就是文件系统或shell底下看到的层层目录)。
(ENV) [root@ceph-2 ~]# ll /lib/modules/`uname -r`/kernel/fs
total 20
-rw-r--r--. 1 root root 5916 Aug 23  2017 binfmt_misc.ko.xz
drwxr-xr-x. 2 root root   25 Aug  9  2018 btrfs
drwxr-xr-x. 2 root root   30 Aug  9  2018 cachefiles
drwxr-xr-x. 2 root root   24 Aug  9  2018 ceph
drwxr-xr-x. 2 root root   24 Aug  9  2018 cifs
drwxr-xr-x. 2 root root   26 Aug  9  2018 cramfs
drwxr-xr-x. 2 root root   23 Aug  9  2018 dlm
drwxr-xr-x. 2 root root   26 Aug  9  2018 exofs
drwxr-xr-x. 2 root root   24 Aug  9  2018 ext4
drwxr-xr-x. 2 root root   60 Aug  9  2018 fat
drwxr-xr-x. 2 root root   27 Aug  9  2018 fscache
drwxr-xr-x. 2 root root   42 Aug  9  2018 fuse
drwxr-xr-x. 2 root root   24 Aug  9  2018 gfs2
drwxr-xr-x. 2 root root   25 Aug  9  2018 isofs
drwxr-xr-x. 2 root root   24 Aug  9  2018 jbd2
drwxr-xr-x. 2 root root   25 Aug  9  2018 lockd
-rw-r--r--. 1 root root 5208 Aug 23  2017 mbcache.ko.xz
drwxr-xr-x. 6 root root  137 Aug  9  2018 nfs
drwxr-xr-x. 2 root root   46 Aug  9  2018 nfs_common
drwxr-xr-x. 2 root root   24 Aug  9  2018 nfsd
drwxr-xr-x. 2 root root 4096 Aug  9  2018 nls
drwxr-xr-x. 2 root root   27 Aug  9  2018 overlayfs
drwxr-xr-x. 2 root root   27 Aug  9  2018 pstore
drwxr-xr-x. 2 root root   28 Aug  9  2018 squashfs
drwxr-xr-x. 2 root root   23 Aug  9  2018 udf
drwxr-xr-x. 2 root root   23 Aug  9  2018 xfs

loopback file system, 意思是將一个镜像文件当成是一片实体的光碟或磁片一样挂载进来: mount -o loop slackware.iso /mnt/test_cdmount -o loop floppy.img /mnt/test_floppy

挂载 挂载镜像文件
  1. 修改文件属性chattr,lsattr
chattr changes the file attributes on a Linux file system.

       The format of a symbolic mode is +-=[aAcCdDeijsStTu].

       The  operator  '+'  causes  the selected attributes to be added to the existing attributes of the files; '-' causes them to be removed; and '=' causes them to be the only attributes that the files
       have.

       The letters 'aAcCdDeijsStTu' select the new attributes for the files: append only (a), no atime updates (A), compressed (c), no copy on write (C), no dump (d), synchronous directory  updates  (D),
       extent format (e), immutable (i), data journalling (j), secure deletion (s), synchronous updates (S), no tail-merging (t), top of directory hierarchy (T), and undeletable (u).

       The  following  attributes  are  read-only, and may be listed by lsattr(1) but not modified by chattr: compression error (E), huge file (h), indexed directory (I), inline data (N), compression raw
       access (X), and compressed dirty file (Z).

例如设置文件不可修改和删除

(ENV) [root@ceph-2 ~]# lsattr iptables.save
---------------- iptables.save
(ENV) [root@ceph-2 ~]# chattr +i iptables.save
(ENV) [root@ceph-2 ~]# lsattr iptables.save
----i----------- iptables.save
(ENV) [root@ceph-2 ~]# rm -rf iptables.save
rm: cannot remove ‘iptables.save’: Operation not permitted
  1. rm's -- argument to tell it that everything that follows is a filename and not an option(i.e., rm -- -f).
(ENV) [root@ceph-2 delete]# ll
total 4
-rw-r--r-- 1 root root 9 Nov 22 22:00 -f
(ENV) [root@ceph-2 delete]# rm -i -f
(ENV) [root@ceph-2 delete]# ll
total 4
-rw-r--r-- 1 root root 9 Nov 22 22:00 -f
(ENV) [root@ceph-2 delete]# rm -i -- -f
rm: remove regular file ‘-f’? y
(ENV) [root@ceph-2 delete]# ll
total 0
(ENV) [root@ceph-2 delete]#
  1. users and groups

The Name Service Switch is a Unix utility that retrieves entries from a set of different datasources such as files, LDAP, a DNS server or a Network Information Service.
The list of all the datasources available can be read from the nsswitch.conf file located at /etc.

getent passwd <optional_user>

[root@dfs-bj71rkz2kt ~]# getent passwd | grep 100100
user100:x:100100:100::/home/user100:/bin/bash
[root@dfs-bj71rkz2kt ~]# grep -E '^UID_MIN|^UID_MAX' /etc/login.defs
UID_MIN                  1000
UID_MAX                 60000

可以通过如下命令获取regular(normal) users。

[root@dfs-bj71rkz2kt ~]#  getent passwd {1000..60000}
.......
[root@dfs-bj71rkz2kt ~]# eval getent passwd {$(awk '/^UID_MIN/ {print $2}' /etc/login.defs)..$(awk '/^UID_MAX/ {print $2}' /etc/login.defs)}
centos:x:1000:1000:Cloud User:/home/centos:/bin/bash
.......
[root@dfs-bj71rkz2kt ~]# getent group
root:x:0:
bin:x:1:
daemon:x:2:
sys:x:3:

References

上一篇 下一篇

猜你喜欢

热点阅读