美文网首页
shell笔记

shell笔记

作者: 酱油王0901 | 来源:发表于2020-11-22 20:09 被阅读0次
  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
  • 可以通过查看/etc/passwd文件去获取用户。
    list-users-linux
  • 可以通过getent命令进行获取,getent命令会从NSS(name service switch) database中检索相应的条目。

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
  • 每个user都有唯一的user ID,即UID。使用useradd命令创建user时如果没有指定UID,则将会从/etc/login.defs文件中自动选择合适的。
[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
.......
  • 另外,还可以通过compgen -u命令查看所有的users。
  • 可以通过查看/etc/group文件去获取用户组。
    etc-group-file
  • 同样地,也可以通过getent命令来获取
    getent <database> <key>
[root@dfs-bj71rkz2kt ~]# getent group
root:x:0:
bin:x:1:
daemon:x:2:
sys:x:3:
  • groups <username>

References

相关文章

  • linux shell脚本攻略笔记

    LINUX SHELL脚本攻略笔记[速查] linux shell脚本攻略笔记

  • Shell十三问 学习笔记

    文本处理 Shell脚本编程 Shell 十三问 学习笔记 shell and Carriage 关系 Shell...

  • Shell脚本

    shell脚本学习笔记 shell命令的组合运用 常用命令组合

  • Shell入门笔记

    本笔记参考 Linux探索之旅 1.什么是Shell 2.Shell种类 3.Shell脚本文件 4.Shell变...

  • Shell 学习笔记

    Shell 学习笔记 Shell 是一个用 C 语言编写的程序,它是用户使用 Linux 的桥梁。Shell 既是...

  • 1.1 开始

    《Linux Shell 脚本攻略(第 2 版)》读书笔记 Bash (Bourne Again Shell)是目...

  • SHELL 笔记

    shell笔记 判断语句 运算 选择语句 循环语句 将shell字句执行结果复制给变量 shell简单传参 编号变...

  • 1.11 调试脚本

    《Linux Shell 脚本攻略(第 2 版)》读书笔记 启用 shell 脚本的跟踪调试功能bash -x s...

  • Linux操作系统命令汇总

    SHELL脚本学习笔记 标签(空格分隔): linux shell脚本 1. 常用命令汇总 alias 设置别名u...

  • shell script学习笔记

    shell学习笔记 什么是shell? shell是运行在linux服务器上的用c语言编写的程序,即可以是服务器端...

网友评论

      本文标题:shell笔记

      本文链接:https://www.haomeiwen.com/subject/vtfpiktx.html