php shell 无括号,【已解决】Linux shell中的空的(左右)大括号的含义

【背景】

折腾:

期间,虽然搞懂了find和xarg加上cp的用法,但是不知道其中:find . -name *.pdf | xargs -i cp {} ../docbook_pdf/

出现的空的大括号{}的含义。

【折腾过程】

1.去参考了:

知道了:

{a,b,c}

是以此展开每个item,但是空的大括号:{},是啥意思,还是不知道。

2.参考:

终于明白了:

空的(左右)大括号:{}

的含义是:

占位符

意思是:

对于(find等输出的一个列表的内容)依次循环每一个;

其给出了一些例子:find ~/ -name 'core*' -exec rm {} \;

# Removes all core dump files from user's home directory.find /home/bozo/projects -mtime -1

# ^ Note minus sign!

# Lists all files in /home/bozo/projects directory tree

#+ that were modified within the last day (current_day - 1).

#

find /home/bozo/projects -mtime 1

# Same as above, but modified *exactly* one day ago.

#

# mtime = last modification time of the target file

# ctime = last status change time (via 'chmod' or otherwise)

# atime = last access time

DIR=/home/bozo/junk_files

find "$DIR" -type f -atime +5 -exec rm {} \;

# ^ ^^

# Curly brackets are placeholder for the path name output by "find."

#

# Deletes all files in "/home/bozo/junk_files"

#+ that have not been accessed in *at least* 5 days (plus sign ... +5).

#

# "-type filetype", where

# f = regular file

# d = directory

# l = symbolic link, etc.

#

# (The 'find' manpage and info page have complete option listings.)find /etc -exec grep '[0-9][0-9]*[.][0-9][0-9]*[.][0-9][0-9]*[.][0-9][0-9]*' {} \;

# Finds all IP addresses (xxx.xxx.xxx.xxx) in /etc directory files.

# There a few extraneous hits. Can they be filtered out?

# Possibly by:

find /etc -type f -exec cat '{}' \; | tr -c '.[:digit:]' '\n' \

| grep '^[^.][^.]*\.[^.][^.]*\.[^.][^.]*\.[^.][^.]*$'

#

# [:digit:] is one of the character classes

#+ introduced with the POSIX 1003.2 standard.

# Thanks, Stéphane Chazelas.

注:

另外的,比如find的话,对于输出结果,也是可以通过-exec去执行的,所以可以有下面例子中的写法:#!/bin/bash

# badname.sh

# Delete filenames in current directory containing bad characters.

for filename in *

do

badname=`echo "$filename" | sed -n /[\+\{\;\"\\\=\?~\(\)\\&\*\|\$]/p`

# badname=`echo "$filename" | sed -n '/[+{;"\=?~()<>&*|$]/p'` also works.

# Deletes files containing these nasties: + { ; " \ = ? ~ ( ) < > & * | $

#

rm $badname 2>/dev/null

# ^^^^^^^^^^^ Error messages deep-sixed.

done

# Now, take care of files containing all manner of whitespace.

find . -name "* *" -exec rm -f {} \;

# The path name of the file that _find_ finds replaces the "{}".

# The '\' ensures that the ';' is interpreted literally, as end of command.

exit 0

#---------------------------------------------------------------------

# Commands below this line will not execute because of _exit_ command.

# An alternative to the above script:

find . -name '*[+{;"\\=?~()<>&*|$ ]*' -maxdepth 0 \

-exec rm -f '{}' \;

# The "-maxdepth 0" option ensures that _find_ will not search

#+ subdirectories below $PWD.

# (Thanks, S.C.)

即:find . -name "* *" -exec rm -f {} \;

其中,最后的反斜杠的含义是:

参考:

用于识别最后的参数

即,反斜杠后面,就是find的另外一个参数了。

举例:find euler/ -iname "*.c*" -exec echo {} \; -or -iname "*.py" -exec echo {} \;

【总结】

Linux中的(Bash的)shell中的空的大括号,是占位符的含义。

举例:find . -name *.pdf | xargs -i cp {} ../docbook_pdf/

此处空的大括号就是:

find出来的,每一个文件,的意思。

对于每一个文件,占座,等find出来后,放到对应的{}的位置。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值