Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have a script that I use to aide in data recovery when the host OS will not boot. Booting with a linux liveCD I execute a script with commands similar to:
I'd like to add a little "prettiness" to it and allow for a verbose output, but only for the file being copied (not the entire command as '-v' offers) and also to show this only on one line (i.e. show the file being copied on one line, when the copy is complete remove the output from the first find/copy and show the next file being copied on the same line (replace the verbose output with each successive file)).
Is this possible?
Thanks in advance for any assistance
Last edited by dick.swift; 01-10-2006 at 11:35 AM.
(getting the quotes right in all of that is going to be fun...) As for displaying them on the same line, I think (though I might be wrong, never really having looked into it) you need a library like ncurses for that. The standard UNIX console tools simply write to standard out, which AFAIK doesn't have any absolute positioning.
Of course, if I am wrong, I'll be very happy to hear about it and learn how to do it!
I find that I get the same printed output with or without the sed portion.
So it seems very close to what I'm looking to accomplish, but need it to show only the file that is being copied - I don't want to see the path as that will be documented in the output from due to the --parents switch.
Thanks for your help - again this is getting me closer.
Last edited by dick.swift; 01-11-2006 at 11:01 AM.
Distribution: Debian Etch (w/ dual-boot XP for gaming)
Posts: 282
Rep:
Ah, for only getting the file I believe there's a very handy tool called basename that will do exactly what you want. Unfortunately, it won't take output through a pipe so we can't just stick it on the end as you'd expect. We can either pass basically the entire script into it as an argument (which works) or use some scripting tool to cut off all characters up to and including the last non-escaped forward slash. I'm going to go with the former, since although it doesn't look quite as nice it works fine and doesn't require extra thinking
As for the sed not doing anything, does your cp -v surround the file names in ticks/quotes? Mine did, which is why I sed-ed them away, but if yours doesn't that's fine too.
I'm afraid I've still had no luck on the creative positioning of strings on a console window, it's beyond my current knowledge. Hopefully someone else can step in and educate us both.
by substituting $1 with $3, I am at least getting a paired down path/$filename (with the single quotes removed by SED). This may suffice while I investigate baseline or similar alternate methods.
Thanks again for your help!
Last edited by dick.swift; 01-11-2006 at 02:05 PM.
Distribution: Debian Etch (w/ dual-boot XP for gaming)
Posts: 282
Rep:
I don't know if you missed it - but there was a subtle change in the code that means basename is being called. By using the shell's "execute expression" brackets around basically the whole of the exec command, you can tell the shell to evaluate that part first then pass it in to basename. Note the part immediately after the -exec: basename $(cp... and then the extra bracket to close it all off at the end.
It's very easy to overlook when you have to scroll the little window too.
Distribution: Debian Etch (w/ dual-boot XP for gaming)
Posts: 282
Rep:
OK, I knew there was some way of controlling the display of characters to a console, and the answer is via tput.
There are (by the looks of it) many fancy things you can do with tput - but the following four should be enough for your application:
Code:
tput lines # Returns the number of lines on the current console
tput cols # Returns the number of columns (i.e. characters per line) on the current console
tput cup $row $col # Places the cursor at line $row, column $col (the top line is 0, and the bottom is $(tput lines) - 1).
tput el # Deletes from cursor to end of line
These are really funky commands, and reflect the current window, not just the underlying terminal program - try issuing 'tput cols', resizing your window and issuing it again... now that's impressive. Anyway, you can read in the row and columns at the start of your script, and then before issuing the echo command, use 'tput cup x y' dollowed by 'tput el' to clear your old text, then write the new text on the same line. For sanity checks in case someone resizes the window, you may want to update your rows and columns count periodically, depending on how important it is to have them up-to-date.
At this point I'd like to say that while I think these commands will work fine, I've only just come across the command and haven't looked into the weird and wacky errors that may arise from strange configurations and unexpected use. I'd definitely recommend you have a look around for tput HOWTOs and learn its abilities and limitations for yourself.
It's pretty tasty, though.
Edit: oh, and while man tput isn't that information, man 5 terminfo gives you a long list of capabilities that you can get/set/otherwise exploit with tput. Some of these are more device-dependent than others, YMMV.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.