Uses of % in bash

Posted on 2011-10-08
Last Modified: 2012-05-12
Hello, I am trying to interpret one command and I am not able to get the get what does % symbolizes here..

find /path/to/diretory -type f -print0 | xargs -0 -i% cp -v % /path/to/new/directory

Open in new window

Please let me know how cp is taking % as the argument supplied via find using pipe. I know it works but how it works I am failed to get it. Does bash shell playing any role here or it is magic of xargs command? Thanks!
Question by:beer9
    LVL 2

    Accepted Solution

    The -i argument to xargs is the "replace string". Instances of this string in the initial argument are replaced by input From std-in.

    So cp % ... Is replaced by each file from the find command.

    Not how I would have done it. I'd have used -exec argument to find.
    LVL 48

    Assisted Solution

    By default, the -i flag to xargs uses {} as a placeholder for arguments.  It is the equivalent of -I{}

    So you can specify any character you like as the placeholder, eg: %

    The find statement is better written as:
    find /path/to/diretory -type f  | xargs -i cp -v /path/to/new/directory

    Open in new window


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
    How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now