美文网首页
shell入门20-参数传递之xargs

shell入门20-参数传递之xargs

作者: 万州客 | 来源:发表于2023-01-03 08:03 被阅读0次

    xargs用得好,算是高手了。

    一,介绍

    image.png
    image.png

    二,练习

    [root@127 shell_demo]# cut -d: -f1 /etc/passwd
    root
    bin
    daemon
    adm
    lp
    sync
    shutdown
    halt
    mail
    operator
    games
    ftp
    nobody
    systemd-network
    dbus
    polkitd
    sshd
    postfix
    chengang
    tss
    redis
    mysql
    saslauth
    telegraf
    apache
    ntp
    sky
    nginx
    [root@127 shell_demo]# cut -d: -f1 /etc/passwd |echo
    
    [root@127 shell_demo]# find /etc -name *.conf -type f
    /etc/resolv.conf
    /etc/pki/ca-trust/ca-legacy.conf
    /etc/yum/pluginconf.d/fastestmirror.conf
    /etc/yum/pluginconf.d/langpacks.conf
    /etc/yum/protected.d/systemd.conf
    /etc/yum/version-groups.conf
    /etc/lvm/lvm.conf
    /etc/lvm/lvmlocal.conf
    /etc/asound.conf
    /etc/libuser.conf
    /etc/snmp/snmpd.conf
    /etc/snmp/snmptrapd.conf
    /etc/openldap/ldap.conf
    /etc/dracut.conf
    /etc/yum.conf
    /etc/depmod.d/dist.conf
    /etc/modprobe.d/tuned.conf
    /etc/modprobe.d/firewalld-sysctls.conf
    /etc/modprobe.d/dccp-blacklist.conf
    /etc/rsyslog.d/listen.conf
    /etc/host.conf
    /etc/systemd/bootchart.conf
    /etc/systemd/coredump.conf
    /etc/systemd/journald.conf
    /etc/systemd/logind.conf
    /etc/systemd/system/redis-sentinel.service.d/limit.conf
    /etc/systemd/system/redis.service.d/limit.conf
    /etc/systemd/system.conf
    /etc/systemd/user.conf
    /etc/dbus-1/system.d/org.freedesktop.hostname1.conf
    /etc/dbus-1/system.d/org.freedesktop.import1.conf
    /etc/dbus-1/system.d/org.freedesktop.locale1.conf
    /etc/dbus-1/system.d/org.freedesktop.login1.conf
    /etc/dbus-1/system.d/org.freedesktop.machine1.conf
    /etc/dbus-1/system.d/org.freedesktop.systemd1.conf
    /etc/dbus-1/system.d/org.freedesktop.timedate1.conf
    /etc/dbus-1/system.d/org.freedesktop.PolicyKit1.conf
    /etc/dbus-1/system.d/wpa_supplicant.conf
    /etc/dbus-1/system.d/nm-dispatcher.conf
    /etc/dbus-1/system.d/nm-ifcfg-rh.conf
    /etc/dbus-1/system.d/org.freedesktop.NetworkManager.conf
    /etc/dbus-1/system.d/teamd.conf
    /etc/dbus-1/system.d/com.redhat.tuned.conf
    /etc/dbus-1/system.d/FirewallD.conf
    /etc/dbus-1/system.d/org.selinux.conf
    /etc/dbus-1/session.conf
    /etc/dbus-1/system.conf
    /etc/udev/udev.conf
    /etc/NetworkManager/NetworkManager.conf
    /etc/X11/xorg.conf.d/00-keyboard.conf
    /etc/prelink.conf.d/nss-softokn-prelink.conf
    /etc/prelink.conf.d/fipscheck.conf
    /etc/prelink.conf.d/grub2.conf
    /etc/ld.so.conf
    /etc/ld.so.conf.d/bind-export-x86_64.conf
    /etc/ld.so.conf.d/kernel-3.10.0-1127.el7.x86_64.conf
    /etc/ld.so.conf.d/kernel-3.10.0-1160.59.1.el7.x86_64.conf
    /etc/ld.so.conf.d/dyninst-x86_64.conf
    /etc/ld.so.conf.d/tix-x86_64.conf
    /etc/ld.so.conf.d/mysql-x86_64.conf
    /etc/logrotate.conf
    /etc/nsswitch.conf
    /etc/sestatus.conf
    /etc/sysctl.conf
    /etc/wpa_supplicant/wpa_supplicant.conf
    /etc/libaudit.conf
    /etc/selinux/semanage.conf
    /etc/selinux/targeted/setrans.conf
    /etc/krb5.conf
    /etc/security/access.conf
    /etc/security/chroot.conf
    /etc/security/group.conf
    /etc/security/limits.conf
    /etc/security/limits.d/20-nproc.conf
    /etc/security/namespace.conf
    /etc/security/pam_env.conf
    /etc/security/sepermit.conf
    /etc/security/time.conf
    /etc/security/pwquality.conf
    /etc/sasl2/smtpd.conf
    /etc/plymouth/plymouthd.conf
    /etc/tuned/tuned-main.conf
    /etc/firewalld/firewalld.conf
    /etc/kdump.conf
    /etc/audisp/audispd.conf
    /etc/audisp/plugins.d/af_unix.conf
    /etc/audisp/plugins.d/syslog.conf
    /etc/audit/auditd.conf
    /etc/rsyslog.conf
    /etc/man_db.conf
    /etc/sudo-ldap.conf
    /etc/sudo.conf
    /etc/e2fsck.conf
    /etc/mke2fs.conf
    /etc/vconsole.conf
    /etc/locale.conf
    /etc/rsyncd.conf
    /etc/tcsd.conf
    /etc/fonts/conf.d/25-no-bitmap-fedora.conf
    /etc/fonts/fonts.conf
    /etc/redis-sentinel.conf
    /etc/redis.conf
    /etc/telegraf/telegraf.conf
    /etc/httpd/conf/httpd.conf
    /etc/httpd/conf.d/autoindex.conf
    /etc/httpd/conf.d/userdir.conf
    /etc/httpd/conf.d/welcome.conf
    /etc/httpd/conf.d/cacti.conf
    /etc/httpd/conf.modules.d/00-base.conf
    /etc/httpd/conf.modules.d/00-dav.conf
    /etc/httpd/conf.modules.d/00-lua.conf
    /etc/httpd/conf.modules.d/00-mpm.conf
    /etc/httpd/conf.modules.d/00-proxy.conf
    /etc/httpd/conf.modules.d/00-systemd.conf
    /etc/httpd/conf.modules.d/01-cgi.conf
    /etc/ntp.conf
    [root@127 shell_demo]# find /etc -name *.conf -type f |echo
    
    [root@127 shell_demo]# cat /var/run/crond.pid |kill
    kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]
    [root@127 shell_demo]# echo /tmp/
    11.conf     a.sh        b.sh        conf.log    etc/        .ICE-unix/  root/       usr/        
    22.conf     a.txt       b.txt       c.sh        filebak.sh  nounset.sh  sh.log      .X11-unix/  
    33.conf     A.txt       B.txt       errexit.sh  .font-unix/ passwd      .Test-unix/ .XIM-unix/  
    [root@127 shell_demo]# echo /tmp/b.sh |rm
    rm: missing operand
    Try 'rm --help' for more information.
    [root@127 shell_demo]# cat /etc/redhat-release |xargs
    CentOS Linux release 7.9.2009 (Core)
    [root@127 shell_demo]# cat /etc/redhat-release |xargs echo
    CentOS Linux release 7.9.2009 (Core)
    [root@127 shell_demo]# cut -d: -f1 /etc/passwd |xargs echo
    root bin daemon adm lp sync shutdown halt mail operator games ftp nobody systemd-network dbus polkitd sshd postfix chengang tss redis mysql saslauth telegraf apache ntp sky nginx
    [root@127 shell_demo]# cut -d: -f1 /etc/passwd |xargs 
    root bin daemon adm lp sync shutdown halt mail operator games ftp nobody systemd-network dbus polkitd sshd postfix chengang tss redis mysql saslauth telegraf apache ntp sky nginx
    [root@127 shell_demo]# find /etc -name *.conf -type d
    [root@127 shell_demo]# find /etc -name *.conf -type f |xargs echo
    /etc/resolv.conf /etc/pki/ca-trust/ca-legacy.conf /etc/yum/pluginconf.d/fastestmirror.conf /etc/yum/pluginconf.d/langpacks.conf /etc/yum/protected.d/systemd.conf /etc/yum/version-groups.conf /etc/lvm/lvm.conf /etc/lvm/lvmlocal.conf /etc/asound.conf /etc/libuser.conf /etc/snmp/snmpd.conf /etc/snmp/snmptrapd.conf /etc/openldap/ldap.conf /etc/dracut.conf /etc/yum.conf /etc/depmod.d/dist.conf /etc/modprobe.d/tuned.conf /etc/modprobe.d/firewalld-sysctls.conf /etc/modprobe.d/dccp-blacklist.conf /etc/rsyslog.d/listen.conf /etc/host.conf /etc/systemd/bootchart.conf /etc/systemd/coredump.conf /etc/systemd/journald.conf /etc/systemd/logind.conf /etc/systemd/system/redis-sentinel.service.d/limit.conf /etc/systemd/system/redis.service.d/limit.conf /etc/systemd/system.conf /etc/systemd/user.conf /etc/dbus-1/system.d/org.freedesktop.hostname1.conf /etc/dbus-1/system.d/org.freedesktop.import1.conf /etc/dbus-1/system.d/org.freedesktop.locale1.conf /etc/dbus-1/system.d/org.freedesktop.login1.conf /etc/dbus-1/system.d/org.freedesktop.machine1.conf /etc/dbus-1/system.d/org.freedesktop.systemd1.conf /etc/dbus-1/system.d/org.freedesktop.timedate1.conf /etc/dbus-1/system.d/org.freedesktop.PolicyKit1.conf /etc/dbus-1/system.d/wpa_supplicant.conf /etc/dbus-1/system.d/nm-dispatcher.conf /etc/dbus-1/system.d/nm-ifcfg-rh.conf /etc/dbus-1/system.d/org.freedesktop.NetworkManager.conf /etc/dbus-1/system.d/teamd.conf /etc/dbus-1/system.d/com.redhat.tuned.conf /etc/dbus-1/system.d/FirewallD.conf /etc/dbus-1/system.d/org.selinux.conf /etc/dbus-1/session.conf /etc/dbus-1/system.conf /etc/udev/udev.conf /etc/NetworkManager/NetworkManager.conf /etc/X11/xorg.conf.d/00-keyboard.conf /etc/prelink.conf.d/nss-softokn-prelink.conf /etc/prelink.conf.d/fipscheck.conf /etc/prelink.conf.d/grub2.conf /etc/ld.so.conf /etc/ld.so.conf.d/bind-export-x86_64.conf /etc/ld.so.conf.d/kernel-3.10.0-1127.el7.x86_64.conf /etc/ld.so.conf.d/kernel-3.10.0-1160.59.1.el7.x86_64.conf /etc/ld.so.conf.d/dyninst-x86_64.conf /etc/ld.so.conf.d/tix-x86_64.conf /etc/ld.so.conf.d/mysql-x86_64.conf /etc/logrotate.conf /etc/nsswitch.conf /etc/sestatus.conf /etc/sysctl.conf /etc/wpa_supplicant/wpa_supplicant.conf /etc/libaudit.conf /etc/selinux/semanage.conf /etc/selinux/targeted/setrans.conf /etc/krb5.conf /etc/security/access.conf /etc/security/chroot.conf /etc/security/group.conf /etc/security/limits.conf /etc/security/limits.d/20-nproc.conf /etc/security/namespace.conf /etc/security/pam_env.conf /etc/security/sepermit.conf /etc/security/time.conf /etc/security/pwquality.conf /etc/sasl2/smtpd.conf /etc/plymouth/plymouthd.conf /etc/tuned/tuned-main.conf /etc/firewalld/firewalld.conf /etc/kdump.conf /etc/audisp/audispd.conf /etc/audisp/plugins.d/af_unix.conf /etc/audisp/plugins.d/syslog.conf /etc/audit/auditd.conf /etc/rsyslog.conf /etc/man_db.conf /etc/sudo-ldap.conf /etc/sudo.conf /etc/e2fsck.conf /etc/mke2fs.conf /etc/vconsole.conf /etc/locale.conf /etc/rsyncd.conf /etc/tcsd.conf /etc/fonts/conf.d/25-no-bitmap-fedora.conf /etc/fonts/fonts.conf /etc/redis-sentinel.conf /etc/redis.conf /etc/telegraf/telegraf.conf /etc/httpd/conf/httpd.conf /etc/httpd/conf.d/autoindex.conf /etc/httpd/conf.d/userdir.conf /etc/httpd/conf.d/welcome.conf /etc/httpd/conf.d/cacti.conf /etc/httpd/conf.modules.d/00-base.conf /etc/httpd/conf.modules.d/00-dav.conf /etc/httpd/conf.modules.d/00-lua.conf /etc/httpd/conf.modules.d/00-mpm.conf /etc/httpd/conf.modules.d/00-proxy.conf /etc/httpd/conf.modules.d/00-systemd.conf /etc/httpd/conf.modules.d/01-cgi.conf /etc/ntp.conf
    [root@127 shell_demo]# find -name "*.txt" 
    ./test.txt
    [root@127 shell_demo]# find -name "*.txt" |xargs grep "abc"
    [root@127 shell_demo]# find -name "*.txt" |xargs grep "e"
    hello
    [root@127 shell_demo]# find /etc -name *.conf -type f |xargs ls -l
    -rw-r--r--. 1 root  root     55 Aug  8  2019 /etc/asound.conf
    -rw-r-----. 1 root  root    246 Aug  8  2019 /etc/audisp/audispd.conf
    -rw-r-----. 1 root  root    358 Aug  8  2019 /etc/audisp/plugins.d/af_unix.conf
    -rw-r-----. 1 root  root    517 Aug  8  2019 /etc/audisp/plugins.d/syslog.conf
    -rw-r-----. 1 root  root    805 Aug  8  2019 /etc/audit/auditd.conf
    -rw-r--r--. 1 root  root    838 Sep 30  2020 /etc/dbus-1/session.conf
    -rw-r--r--. 1 root  root    833 Sep 30  2020 /etc/dbus-1/system.conf
    -rw-r--r--. 1 root  root    587 Mar 22  2019 /etc/dbus-1/system.d/com.redhat.tuned.conf
    -rw-r--r--. 1 root  root   1084 Apr 28  2021 /etc/dbus-1/system.d/FirewallD.conf
    -rw-r--r--. 1 root  root    465 Nov 17  2020 /etc/dbus-1/system.d/nm-dispatcher.conf
    -rw-r--r--. 1 root  root    387 Nov 17  2020 /etc/dbus-1/system.d/nm-ifcfg-rh.conf
    -rw-r--r--. 1 root  root    947 Jan 14  2022 /etc/dbus-1/system.d/org.freedesktop.hostname1.conf
    -rw-r--r--. 1 root  root   2527 Jan 14  2022 /etc/dbus-1/system.d/org.freedesktop.import1.conf
    -rw-r--r--. 1 root  root    937 Jan 14  2022 /etc/dbus-1/system.d/org.freedesktop.locale1.conf
    -rw-r--r--. 1 root  root   8534 Jan 14  2022 /etc/dbus-1/system.d/org.freedesktop.login1.conf
    -rw-r--r--. 1 root  root   3726 Jan 14  2022 /etc/dbus-1/system.d/org.freedesktop.machine1.conf
    -rw-r--r--. 1 root  root   9740 Nov 17  2020 /etc/dbus-1/system.d/org.freedesktop.NetworkManager.conf
    -rw-r--r--. 1 root  root    638 Jan 26  2022 /etc/dbus-1/system.d/org.freedesktop.PolicyKit1.conf
    -rw-r--r--. 1 root  root  10118 Jan 14  2022 /etc/dbus-1/system.d/org.freedesktop.systemd1.conf
    -rw-r--r--. 1 root  root    947 Jan 14  2022 /etc/dbus-1/system.d/org.freedesktop.timedate1.conf
    -rw-r--r--. 1 root  root    535 Apr  1  2020 /etc/dbus-1/system.d/org.selinux.conf
    -rw-r--r--. 1 root  root    409 Dec  9  2018 /etc/dbus-1/system.d/teamd.conf
    -rw-r--r--. 1 root  root   1096 Mar 16  2021 /etc/dbus-1/system.d/wpa_supplicant.conf
    -rw-r--r--. 1 root  root    116 Apr  1  2020 /etc/depmod.d/dist.conf
    -rw-r--r--. 1 root  root   1285 Sep 30  2020 /etc/dracut.conf
    -rw-r--r--. 1 root  root    112 Sep 30  2020 /etc/e2fsck.conf
    -rw-r--r--. 1 root  root   2706 Apr 28  2021 /etc/firewalld/firewalld.conf
    -rw-r--r--. 1 root  root   1160 Oct 30  2018 /etc/fonts/conf.d/25-no-bitmap-fedora.conf
    -rw-r--r--. 1 root  root   2416 Oct 31  2018 /etc/fonts/fonts.conf
    -rw-r--r--. 1 root  root      9 Jun  7  2013 /etc/host.conf
    -rw-r--r--  1 root  root   2926 Mar 24  2022 /etc/httpd/conf.d/autoindex.conf
    -rw-r--r--  1 root  root   1505 Nov  2  2021 /etc/httpd/conf.d/cacti.conf
    -rw-r--r--  1 root  root   1252 Jan  8  2022 /etc/httpd/conf.d/userdir.conf
    -rw-r--r--  1 root  root    824 Jan 14  2022 /etc/httpd/conf.d/welcome.conf
    -rw-r--r--  1 root  root  11753 Jan 14  2022 /etc/httpd/conf/httpd.conf
    -rw-r--r--  1 root  root   3739 Jan 14  2022 /etc/httpd/conf.modules.d/00-base.conf
    -rw-r--r--  1 root  root    139 Jan  8  2022 /etc/httpd/conf.modules.d/00-dav.conf
    -rw-r--r--  1 root  root     41 Jan  8  2022 /etc/httpd/conf.modules.d/00-lua.conf
    -rw-r--r--  1 root  root    742 Jan 14  2022 /etc/httpd/conf.modules.d/00-mpm.conf
    -rw-r--r--  1 root  root    957 Jan 14  2022 /etc/httpd/conf.modules.d/00-proxy.conf
    -rw-r--r--  1 root  root     88 Jan  8  2022 /etc/httpd/conf.modules.d/00-systemd.conf
    -rw-r--r--  1 root  root    451 Jan  8  2022 /etc/httpd/conf.modules.d/01-cgi.conf
    -rw-r--r--. 1 root  root   7274 Mar 19  2022 /etc/kdump.conf
    -rw-r--r--. 1 root  root    646 Sep 30  2020 /etc/krb5.conf
    -rw-r--r--. 1 root  root     28 Feb 28  2013 /etc/ld.so.conf
    -rw-r--r--. 1 root  root     26 Feb 24  2022 /etc/ld.so.conf.d/bind-export-x86_64.conf
    -rw-r--r--. 1 root  root     19 Aug  9  2019 /etc/ld.so.conf.d/dyninst-x86_64.conf
    -r--r--r--. 1 root  root     63 Apr  1  2020 /etc/ld.so.conf.d/kernel-3.10.0-1127.el7.x86_64.conf
    -r--r--r--. 1 root  root     63 Feb 24  2022 /etc/ld.so.conf.d/kernel-3.10.0-1160.59.1.el7.x86_64.conf
    -rw-r--r--  1 root  root     17 Jan  5  2021 /etc/ld.so.conf.d/mysql-x86_64.conf
    -rw-r--r--. 1 root  root     18 Jun 10  2014 /etc/ld.so.conf.d/tix-x86_64.conf
    -rw-r-----. 1 root  root    191 Mar  2  2019 /etc/libaudit.conf
    -rw-r--r--. 1 root  root   2391 Oct 13  2013 /etc/libuser.conf
    -rw-r--r--. 1 root  root     19 Mar 19  2022 /etc/locale.conf
    -rw-r--r--. 1 root  root    662 Jul 31  2013 /etc/logrotate.conf
    -rw-r--r--. 1 root  root  95859 Apr 28  2021 /etc/lvm/lvm.conf
    -rw-r--r--. 1 root  root   2301 Apr 28  2021 /etc/lvm/lvmlocal.conf
    -rw-r--r--. 1 root  root   5171 Oct 31  2018 /etc/man_db.conf
    -rw-r--r--. 1 root  root   1106 Sep 30  2020 /etc/mke2fs.conf
    -rw-r--r--. 1 root  root    215 Feb 24  2022 /etc/modprobe.d/dccp-blacklist.conf
    -rw-r--r--. 1 root  root    166 Apr 28  2021 /etc/modprobe.d/firewalld-sysctls.conf
    -rw-r--r--. 1 root  root    674 Mar 22  2019 /etc/modprobe.d/tuned.conf
    -rw-r--r--. 1 root  root   2145 Nov 17  2020 /etc/NetworkManager/NetworkManager.conf
    -rw-r--r--. 1 root  root   1949 Mar 19  2022 /etc/nsswitch.conf
    -rw-r--r--  1 root  root   2000 Nov 28  2019 /etc/ntp.conf
    -rw-r--r--. 1 root  root    363 Feb 24  2022 /etc/openldap/ldap.conf
    -rw-r--r--. 1 root  root    980 Sep 23  2021 /etc/pki/ca-trust/ca-legacy.conf
    -rw-r--r--. 1 root  root     72 Oct  2  2020 /etc/plymouth/plymouthd.conf
    -rw-r--r--. 1 root  root     57 Aug  2  2017 /etc/prelink.conf.d/fipscheck.conf
    -rw-r--r--. 1 root  root    220 Oct 14  2021 /etc/prelink.conf.d/grub2.conf
    -rw-r--r--. 1 root  root    184 Oct 14  2021 /etc/prelink.conf.d/nss-softokn-prelink.conf
    -rw-r-----  1 redis root  46729 Oct 26  2018 /etc/redis.conf
    -rw-r-----  1 redis root   7642 Oct 26  2018 /etc/redis-sentinel.conf
    -rw-r--r--  1 root  root    130 Jan  1 09:45 /etc/resolv.conf
    -rw-r--r--. 1 root  root    458 Apr  1  2020 /etc/rsyncd.conf
    -rw-r--r--. 1 root  root   3232 Sep 30  2020 /etc/rsyslog.conf
    -rw-r--r--. 1 root  root     49 Jan 14  2022 /etc/rsyslog.d/listen.conf
    -rw-r--r--. 1 root  root     49 Apr  1  2020 /etc/sasl2/smtpd.conf
    -rw-r--r--. 1 root  root   4564 Apr  1  2020 /etc/security/access.conf
    -rw-r--r--. 1 root  root     82 Apr  1  2020 /etc/security/chroot.conf
    -rw-r--r--. 1 root  root   3635 Apr  1  2020 /etc/security/group.conf
    -rw-r--r--. 1 root  root   2422 Apr  1  2020 /etc/security/limits.conf
    -rw-r--r--. 1 root  root    191 Apr  1  2020 /etc/security/limits.d/20-nproc.conf
    -rw-r--r--. 1 root  root   1440 Apr  1  2020 /etc/security/namespace.conf
    -rw-r--r--. 1 root  root   2972 Apr  1  2020 /etc/security/pam_env.conf
    -rw-r--r--. 1 root  root   1718 Dec  7  2011 /etc/security/pwquality.conf
    -rw-r--r--. 1 root  root    419 Apr  1  2020 /etc/security/sepermit.conf
    -rw-r--r--. 1 root  root   2179 Apr  1  2020 /etc/security/time.conf
    -rw-r--r--. 1 root  root   2321 Oct 31  2018 /etc/selinux/semanage.conf
    -rw-r--r--. 1 root  root    607 Nov 17  2020 /etc/selinux/targeted/setrans.conf
    -rw-r--r--. 1 root  root    216 Apr  1  2020 /etc/sestatus.conf
    -rw-------  1 root  root  18861 Apr  6  2022 /etc/snmp/snmpd.conf
    -rw-------  1 root  root    220 Apr  6  2022 /etc/snmp/snmptrapd.conf
    -rw-r-----. 1 root  root   1786 Sep 30  2020 /etc/sudo.conf
    -rw-r-----. 1 root  root   3181 Sep 30  2020 /etc/sudo-ldap.conf
    -rw-r--r--. 1 root  root    449 Nov 17  2020 /etc/sysctl.conf
    -rw-r--r--. 1 root  root    720 Jan 14  2022 /etc/systemd/bootchart.conf
    -rw-r--r--. 1 root  root    615 Jan 14  2022 /etc/systemd/coredump.conf
    -rw-r--r--. 1 root  root    983 Jan 14  2022 /etc/systemd/journald.conf
    -rw-r--r--. 1 root  root    957 Jan 14  2022 /etc/systemd/logind.conf
    -rw-r--r--. 1 root  root   1552 Jan 14  2022 /etc/systemd/system.conf
    -rw-r--r--  1 root  root    217 Oct 26  2018 /etc/systemd/system/redis-sentinel.service.d/limit.conf
    -rw-r--r--  1 root  root    217 Oct 26  2018 /etc/systemd/system/redis.service.d/limit.conf
    -rw-r--r--. 1 root  root   1127 Jan 14  2022 /etc/systemd/user.conf
    -rw-------. 1 tss   tss    7046 Aug  4  2017 /etc/tcsd.conf
    -rw-r--r--  1 root  root 211844 Apr  7  2022 /etc/telegraf/telegraf.conf
    -rw-r--r--. 1 root  root   1305 Feb  3  2021 /etc/tuned/tuned-main.conf
    -rw-r--r--. 1 root  root     49 Jan 14  2022 /etc/udev/udev.conf
    -rw-r--r--. 1 root  root     37 Mar 19  2022 /etc/vconsole.conf
    -rw-------. 1 root  root     67 Mar 16  2021 /etc/wpa_supplicant/wpa_supplicant.conf
    -rw-r--r--. 1 root  root    232 Mar 19  2022 /etc/X11/xorg.conf.d/00-keyboard.conf
    -rw-r--r--. 1 root  root    970 Oct  2  2020 /etc/yum.conf
    -rw-r--r--. 1 root  root    279 May 13  2020 /etc/yum/pluginconf.d/fastestmirror.conf
    -rw-r--r--. 1 root  root    372 Mar 19  2022 /etc/yum/pluginconf.d/langpacks.conf
    -rw-r--r--. 1 root  root      8 Jan 14  2022 /etc/yum/protected.d/systemd.conf
    -rw-r--r--. 1 root  root    444 Oct  2  2020 /etc/yum/version-groups.conf
    [root@127 shell_demo]# find /etc -name *.conf -type f |xargs wc -l
         5 /etc/resolv.conf
        24 /etc/pki/ca-trust/ca-legacy.conf
        12 /etc/yum/pluginconf.d/fastestmirror.conf
        12 /etc/yum/pluginconf.d/langpacks.conf
         1 /etc/yum/protected.d/systemd.conf
        12 /etc/yum/version-groups.conf
      2152 /etc/lvm/lvm.conf
        57 /etc/lvm/lvmlocal.conf
         3 /etc/asound.conf
        89 /etc/libuser.conf
       462 /etc/snmp/snmpd.conf
         6 /etc/snmp/snmptrapd.conf
        18 /etc/openldap/ldap.conf
        51 /etc/dracut.conf
        26 /etc/yum.conf
         6 /etc/depmod.d/dist.conf
        25 /etc/modprobe.d/tuned.conf
         1 /etc/modprobe.d/firewalld-sysctls.conf
         7 /etc/modprobe.d/dccp-blacklist.conf
         1 /etc/rsyslog.d/listen.conf
         1 /etc/host.conf
        26 /etc/systemd/bootchart.conf
        21 /etc/systemd/coredump.conf
        40 /etc/systemd/journald.conf
        34 /etc/systemd/logind.conf
         7 /etc/systemd/system/redis-sentinel.service.d/limit.conf
         7 /etc/systemd/system/redis.service.d/limit.conf
        60 /etc/systemd/system.conf
        44 /etc/systemd/user.conf
        27 /etc/dbus-1/system.d/org.freedesktop.hostname1.conf
        62 /etc/dbus-1/system.d/org.freedesktop.import1.conf
        27 /etc/dbus-1/system.d/org.freedesktop.locale1.conf
       190 /etc/dbus-1/system.d/org.freedesktop.login1.conf
        86 /etc/dbus-1/system.d/org.freedesktop.machine1.conf
       220 /etc/dbus-1/system.d/org.freedesktop.systemd1.conf
        27 /etc/dbus-1/system.d/org.freedesktop.timedate1.conf
        20 /etc/dbus-1/system.d/org.freedesktop.PolicyKit1.conf
        25 /etc/dbus-1/system.d/wpa_supplicant.conf
        14 /etc/dbus-1/system.d/nm-dispatcher.conf
        12 /etc/dbus-1/system.d/nm-ifcfg-rh.conf
       151 /etc/dbus-1/system.d/org.freedesktop.NetworkManager.conf
        12 /etc/dbus-1/system.d/teamd.conf
        16 /etc/dbus-1/system.d/com.redhat.tuned.conf
        27 /etc/dbus-1/system.d/FirewallD.conf
        19 /etc/dbus-1/system.d/org.selinux.conf
        19 /etc/dbus-1/session.conf
        19 /etc/dbus-1/system.conf
         3 /etc/udev/udev.conf
        50 /etc/NetworkManager/NetworkManager.conf
         7 /etc/X11/xorg.conf.d/00-keyboard.conf
         6 /etc/prelink.conf.d/nss-softokn-prelink.conf
         2 /etc/prelink.conf.d/fipscheck.conf
         7 /etc/prelink.conf.d/grub2.conf
         1 /etc/ld.so.conf
         1 /etc/ld.so.conf.d/bind-export-x86_64.conf
         1 /etc/ld.so.conf.d/kernel-3.10.0-1127.el7.x86_64.conf
         1 /etc/ld.so.conf.d/kernel-3.10.0-1160.59.1.el7.x86_64.conf
         1 /etc/ld.so.conf.d/dyninst-x86_64.conf
         1 /etc/ld.so.conf.d/tix-x86_64.conf
         1 /etc/ld.so.conf.d/mysql-x86_64.conf
        35 /etc/logrotate.conf
        67 /etc/nsswitch.conf
        18 /etc/sestatus.conf
        10 /etc/sysctl.conf
         3 /etc/wpa_supplicant/wpa_supplicant.conf
         7 /etc/libaudit.conf
        51 /etc/selinux/semanage.conf
        19 /etc/selinux/targeted/setrans.conf
        27 /etc/krb5.conf
       122 /etc/security/access.conf
         4 /etc/security/chroot.conf
       106 /etc/security/group.conf
        61 /etc/security/limits.conf
         6 /etc/security/limits.d/20-nproc.conf
        28 /etc/security/namespace.conf
        73 /etc/security/pam_env.conf
        11 /etc/security/sepermit.conf
        65 /etc/security/time.conf
        50 /etc/security/pwquality.conf
         2 /etc/sasl2/smtpd.conf
         3 /etc/plymouth/plymouthd.conf
        41 /etc/tuned/tuned-main.conf
        69 /etc/firewalld/firewalld.conf
       163 /etc/kdump.conf
        12 /etc/audisp/audispd.conf
        14 /etc/audisp/plugins.d/af_unix.conf
        14 /etc/audisp/plugins.d/syslog.conf
        37 /etc/audit/auditd.conf
        91 /etc/rsyslog.conf
       131 /etc/man_db.conf
        86 /etc/sudo-ldap.conf
        57 /etc/sudo.conf
         3 /etc/e2fsck.conf
        58 /etc/mke2fs.conf
         2 /etc/vconsole.conf
         1 /etc/locale.conf
        20 /etc/rsyncd.conf
       191 /etc/tcsd.conf
        44 /etc/fonts/conf.d/25-no-bitmap-fedora.conf
        88 /etc/fonts/fonts.conf
       197 /etc/redis-sentinel.conf
      1052 /etc/redis.conf
      5980 /etc/telegraf/telegraf.conf
       353 /etc/httpd/conf/httpd.conf
        94 /etc/httpd/conf.d/autoindex.conf
        36 /etc/httpd/conf.d/userdir.conf
        22 /etc/httpd/conf.d/welcome.conf
        57 /etc/httpd/conf.d/cacti.conf
        77 /etc/httpd/conf.modules.d/00-base.conf
         3 /etc/httpd/conf.modules.d/00-dav.conf
         1 /etc/httpd/conf.modules.d/00-lua.conf
        19 /etc/httpd/conf.modules.d/00-mpm.conf
        16 /etc/httpd/conf.modules.d/00-proxy.conf
         2 /etc/httpd/conf.modules.d/00-systemd.conf
        14 /etc/httpd/conf.modules.d/01-cgi.conf
        58 /etc/ntp.conf
     14136 total
    [root@127 shell_demo]# echo "test" > /tmp/test.txt
    [root@127 shell_demo]# echo /tmp/test.txt |xargs rm
    [root@127 shell_demo]# ls /tmp/test.txt
    ls: cannot access /tmp/test.txt: No such file or directory
    [root@127 shell_demo]# touch "hello world.txt"
    [root@127 shell_demo]# touch "ni hao.txt"
    [root@127 shell_demo]# find ./ -name "*txt"
    ./hello world.txt
    ./ni hao.txt
    ./test.txt
    [root@127 shell_demo]# find ./ -name "*.txt" |xargs rm
    rm: cannot remove ‘./hello’: No such file or directory
    rm: cannot remove ‘world.txt’: No such file or directory
    rm: cannot remove ‘./ni’: No such file or directory
    rm: cannot remove ‘hao.txt’: No such file or directory
    [root@127 shell_demo]# find ./ -name "*.txt" -print0|xargs -0 rm
    [root@127 shell_demo]# find ./ -name "*txt"
    [root@127 shell_demo]# xargs -a
    xargs: option requires an argument -- 'a'
    Usage: xargs [OPTION]... COMMAND INITIAL-ARGS...
    Run COMMAND with arguments INITIAL-ARGS and more arguments read from input.
    
    Mandatory arguments to long options are mandatory for short options too.
    Non-mandatory arguments are indicated by [square brackets]
      -0, --null                   Items are separated by a null, not whitespace.
                                   Disables quote and backslash processing
      -a, --arg-file=FILE          Read arguments from FILE, not standard input
      -d, --delimiter=CHARACTER    Input items are separated by CHARACTER, not by
                                   blank space. Disables quote and backslash
                                   processing
      -E END                       If END occurs as a line of input, the rest of
                                   the input is ignored.
      -e [END], --eof[=END]        Equivalent to -E END if END is specified.
                                   Otherwise, there is no end-of-file string
      --help                       Print a summary of the options to xargs.
      -I R                         same as --replace=R (R must be specified)
      -i,--replace=[R]             Replace R in initial arguments with names
                                   read from standard input. If R is
                                   unspecified, assume {}
      -L,-l, --max-lines=MAX-LINES Use at most MAX-LINES nonblank input lines per
                                   command line
      -l                           Use at most one nonblank input line per
                                   command line
      -n, --max-args=MAX-ARGS      Use at most MAX-ARGS arguments per command
                                   line
      -P, --max-procs=MAX-PROCS    Run up to max-procs processes at a time
      -p, --interactive            Prompt before running commands
      --process-slot-var=VAR       Set environment variable VAR in child
                                   processes
      -r, --no-run-if-empty        If there are no arguments, run no command.
                                   If this option is not given, COMMAND will be
                                   run at least once.
      -s, --max-chars=MAX-CHARS    Limit commands to MAX-CHARS at most
      --show-limits                Show limits on command-line length.
      -t, --verbose                Print commands before executing them
      --version                    Print the version number
      -x, --exit                   Exit if the size (see -s) is exceeded
    
    Report bugs to <bug-findutils@gnu.org>.
    [root@127 shell_demo]# xargs -a /etc/redhat-release echo
    CentOS Linux release 7.9.2009 (Core)
    [root@127 shell_demo]# xargs -a /etc/hostname 
    127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.1.111 localhost 192.168.1.111 sky
    [root@127 shell_demo]# 
    [root@127 shell_demo]# 
    [root@127 shell_demo]# 
    [root@127 shell_demo]# seq 5 |xargs
    1 2 3 4 5
    [root@127 shell_demo]# seq 5 |xargs -n 2
    1 2
    3 4
    5
    [root@127 shell_demo]# seq 5 |xargs -n 3
    1 2 3
    4 5
    [root@127 shell_demo]# echo "helloatheworld" | xargs
    helloatheworld
    [root@127 shell_demo]# echo "helloatheworld" | xargs -da
    hello theworld
    
    [root@127 shell_demo]# touch {a,b,c}.txt
    [root@127 shell_demo]# ls *.txt|xargs -I{} cp {} /tmp/
    [root@127 shell_demo]# rm -rf /tmp/{a,b,c}.txt
    [root@127 shell_demo]# ls *.txt |xargs -I[] cp [] /tmp/
    [root@127 shell_demo]# rm -rf /tmp/{a,b,c}.txt
    [root@127 shell_demo]# ls *.txt |xargs -I% cp % /tmp/
    [root@127 shell_demo]# ls /tmp/
    11.conf  33.conf  a.txt  b.sh   B.txt     c.sh   errexit.sh  filebak.sh  passwd  sh.log
    22.conf  a.sh     A.txt  b.txt  conf.log  c.txt  etc         nounset.sh  root    usr
    [root@127 shell_demo]# rm -rf /tmp/{a,b,c}.txt
    [root@127 shell_demo]# rm -rf /tmp/{a,b,c}.txt
    [root@127 shell_demo]# rm -rf /tmp/{a,b,c}.txt
    

    相关文章

      网友评论

          本文标题:shell入门20-参数传递之xargs

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