LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 09-27-2009, 12:14 AM   #1
sg_sonic
LQ Newbie
 
Registered: Sep 2009
Posts: 3

Rep: Reputation: 0
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?
 
Old 09-27-2009, 02:14 AM   #2
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 101Reputation: 101
Quote:
Originally Posted by sg_sonic View Post
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
 
Old 09-27-2009, 03:26 AM   #3
sg_sonic
LQ Newbie
 
Registered: Sep 2009
Posts: 3

Original Poster
Rep: Reputation: 0
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.

Last edited by sg_sonic; 09-27-2009 at 03:31 AM.
 
Old 09-27-2009, 03:35 AM   #4
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 101Reputation: 101
Quote:
Originally Posted by sg_sonic View Post
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.
 
Old 09-27-2009, 04:32 AM   #5
sg_sonic
LQ Newbie
 
Registered: Sep 2009
Posts: 3

Original Poster
Rep: Reputation: 0
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.
 
Old 09-27-2009, 03:28 PM   #6
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sed Command - - -How to change part of the name of multiple files sahil.jammu Linux - Newbie 6 04-02-2009 11:57 PM
Syntax error for multiple if conditions predatorz Programming 2 01-29-2009 02:44 PM
Write to multiple files...one command tekmann33 Linux - Newbie 3 06-04-2008 02:02 PM
Root cannot modify files in any way. Copied files from slackware. CrAzY G Fedora 1 01-08-2007 10:18 AM
How to perform an action (a command) on multiple files with the FOR loop? chun-mee Programming 4 08-23-2005 04:11 AM


All times are GMT -5. The time now is 08:08 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration