Use unix find to find files




















Collectives on Stack Overflow. Learn more. Ask Question. Asked 12 years, 8 months ago. Active 12 years, 8 months ago. Viewed times. I tried this: find. What's the right syntax? Improve this question. Frank Frank Add a comment. Active Oldest Votes. All of the filenames were tagged onto the end of the tar command as a very long command line. You can choose to have the final command run on all the file names at once or invoked once per filename.

We can see the difference quite easily by piping the output from xargs to the line and character counting utility wc. This command pipes all the filenames into wc at once. Effectively, xargs constructs a long command line for wc with each of the filenames in it. This means wc is called repeatedly, once for each file. Each invocation of wc operates on a single file so wc has nothing to line the output up with. Each line of output is an independent line of text.

The find command has a built-in method of calling external programs to perform further processing on the filenames that it returns. The -exec execute option has a syntax similar to but different from the xargs command.

When we run that command we see the output of wc. The -c byte count limits its output to the number of bytes in each file. As you can see there is no total. The wc command is executed once per filename.

We get the summary total and neatly tabulated results that tell us all files were passed to wc as one long command line. This computer has a shell function defined called words-only. This counts just the words in a file. We can test what it does like this:. That works just fine with a normal command-line invocation.

To overcome this we can have find launch a Bash shell, and pass the rest of the command line to it as arguments to the shell.

We need to wrap the command line in double quotation marks. Before we can run the find command, we need to export our shell function with the -f as a function option:. The filename and path are passed to our words-only function just as before. Whatever method your situation requires, no one should be surprised that Linux provides enough options that you can find the one that suits your particular needs.

Skip to: content search login. Knowledge Base Toggle local menu Menus About the team. Knowledge Base Search. Log in. Options Help Chat with a consultant. Include archived documents. I've been using the command below which works well for finding the largest files in a certain folder. I can do this with du and get similar results but I am looking for a way to do this by tweaking the command above.

Execute a du for each regular file and give the desired option like -m for megabyte. Sign up to join this community. The best answers are voted up and rise to the top. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams?



0コメント

  • 1000 / 1000