LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Command syntax to modify multiple files (https://www.linuxquestions.org/questions/linux-newbie-8/command-syntax-to-modify-multiple-files-758016/)

sg_sonic 09-26-2009 11:14 PM

Command syntax to modify multiple files
 
I have a program I use, rrdtool. I need to modify a ds value on every file at the same time. However, using a wildcard (*) to try this operation of all files does not work and instead only updates one file.

Here is the command syntax:

rrdtool tune <file> --maximum traffic_in:100000000000 && rrdtool tune <file> --maximum traffic_out:100000000000

So, how can I do this on every file in the directory?

lutusp 09-27-2009 01:14 AM

Quote:

Originally Posted by sg_sonic (Post 3698202)
I have a program I use, rrdtool. I need to modify a ds value on every file at the same time. However, using a wildcard (*) to try this operation of all files does not work and instead only updates one file.

Here is the command syntax:

rrdtool tune <file> --maximum traffic_in:100000000000 && rrdtool tune <file> --maximum traffic_out:100000000000

So, how can I do this on every file in the directory?

You don't say why your present method didn't work or how you tried to do it. Here is a reliable way to scan a directory and all subdirectories and apply any command top each file:

Code:

path="/path/of/interest"

find $path -type f | while read filepath
do
  # put your command here
done


sg_sonic 09-27-2009 02:26 AM

As I stated:

"However, using a wildcard (*) to try this operation of all files does not work and instead only updates one file."

Buuut, how would I formulate said command?

Thanks for your help.

lutusp 09-27-2009 02:35 AM

Quote:

Originally Posted by sg_sonic (Post 3698283)
As I stated:

"However, using a wildcard (*) to try this operation of all files does not work and instead only updates one file."

Buuut, how would I formulate said command?

Thanks for your help.

Shall I post again, or will you kindly read what I have already posted? I solved your problem, all you have to do is read and apply the solution.

sg_sonic 09-27-2009 03:32 AM

Yes, I still don't understand.

path="/path/of/interest"

find $path -type f | while read filepath
do
#your command here
done

Apply what solution? You didn't answer me completely. How do I specify the file name in the command?

rrdtool tune ??? <-- what do I put here ...

I hope I have been clear this time around. :)

CroMagnon 09-27-2009 02:28 PM

The name of the file would be stored in the variable $filepath, so you would write your command with $filepath wherever the filename argument should go.

Note that lutusp's solution will apply to all files in the specified directory and all its subdirectories, which may or may not be what you want. You can use:
Code:

find $path -maxdepth 1 -type f | while read filepath
...

to restrict it to files in the given directory only.


All times are GMT -5. The time now is 09:39 PM.