LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-01-2005, 02:08 AM   #1
bhar0761
Member
 
Registered: Jul 2005
Location: San Francisco
Distribution: Fedora Core 6
Posts: 64

Rep: Reputation: 15
Print a file if it exists and rename it at the same time.


I would like to write a script to print files in a directory if they exist and then rename them at the same time. This script will of course loop forever because new files are created all the time and i don't want to keep printing them.

One option i did look at would be to mv the files right after they print but if new files are created before they are printed, the move command will move them before they print.

B

Last edited by bhar0761; 08-01-2005 at 02:14 AM.
 
Old 08-01-2005, 03:36 AM   #2
ahh
Member
 
Registered: May 2004
Location: UK
Distribution: Gentoo
Posts: 293

Rep: Reputation: 31
Get the list of files first and store them in a variable, then no new files will be added when you rename then.
 
Old 08-01-2005, 10:34 AM   #3
bhar0761
Member
 
Registered: Jul 2005
Location: San Francisco
Distribution: Fedora Core 6
Posts: 64

Original Poster
Rep: Reputation: 15
Would I, set the variable like:
var1=$(ls -l)

B
 
Old 08-01-2005, 04:48 PM   #4
ahh
Member
 
Registered: May 2004
Location: UK
Distribution: Gentoo
Posts: 293

Rep: Reputation: 31
After some consideration, I think this is a better way to do what you want.
Code:
find ./ * -type f -maxdepth 0 -exec print_command '{}' \; -exec  mv '{}' '{}'.printed \;
You'll have to replace "print_command" with whatever command you're using to print the files.
This will rename "file" to "file.printed" after it's been printed. Adjust to what you want. ('{}' is replaced with the file name when this is run).
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Print-to-file print driver to print PDF Bill Fox Linux - General 3 05-02-2006 04:15 PM
Print a file if it exists and rename it at the same time. bhar0761 Linux - Enterprise 2 08-01-2005 11:51 PM
SIOCADDRT: File exists SIOCCADDRT: File Exists Failed to bring up eth0. opsraja Linux - Networking 0 01-10-2005 08:29 AM
Linker problem: can't find a file, but the file exists atlep Programming 5 08-16-2004 06:15 AM
auto file rename based on time wx_jason Linux - Newbie 10 07-10-2003 11:14 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:40 PM.

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
Open Source Consulting | Domain Registration