LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 06-12-2016, 07:30 AM   #1
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
find -exec: path-less {}


I'm trying to compose a one-line command that recursively searches a directory for all files ending in <digit>.in, and then runs the man command on each file found, piping the output from each man command into a separate file on my Desktop.

Here's my attempt so far:

Code:
find ./ -name '*.[[:digit:]].in' -execdir "man {} > ~/Desktop/{}" \;
The result should be a series of files on my Desktop e.g. "ext2ed", "e2fsck" etc.

The problem I'm encountering is that the files are not generated because {} expands to the complete filename, including path, thus producing the following errors:

Code:
find: ‘man ./ext2ed.8.in > ~/Desktop/./ext2ed.8.in’: No such file or directory
find: ‘man ./e2fsck.8.in > ~/Desktop/./e2fsck.8.in’: No such file or directory
Is there any way I can have my second {} expansion produce the path-less filename, or will I have to write and run a script to achieve my goal?
 
Old 06-12-2016, 07:55 AM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Try adding `basename {}` intead of just {}

This by itself will not be enough as it will still have the extensions (man pages are USUALLY something like "zsh.1.gz", and doing "man zsh.1.gz" won't work, but "man zsh" will work.

Also note that some man pages (like "stat") have multiple entries, one in any relavent section, thus "man stat" will get you the page for the stat command, but "man 2 stat" will get you the information on the system call. The file name is different too: "stat.2.gz".

The files are "subject"."section"."compression" usually... Sometimes you will find man pages without the compression, but instead the "man" extension.

And that variation requires the filename to be processed in more than the simple approach. I think you will have to parse the file name to handle the section numbers as well.

BTW, the problem has been addressed before:
http://linux.die.net/man/1/bookman
UNFORTUNATELY, my google fu didn't find where the source to the utility was.

If you find it, please post where it is... I (and others) would find it useful as well. It is rather hard to refer to a man page for configuration information... when the computer won't work well enough to access man pages.

Last edited by jpollard; 06-12-2016 at 08:15 AM.
 
1 members found this post helpful.
Old 06-12-2016, 07:57 AM   #3
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
I think you need a small script to parse found files names, I don't think "man ext2ed.8.in" would return something usefull on your system, rather it would be "man 8 ext2ed", no?
 
1 members found this post helpful.
Old 06-12-2016, 08:01 AM   #4
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048

Original Poster
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
Quote:
Originally Posted by jpollard View Post
Try adding `basename {}` intead of just {}
Code:
find ./ -name '*.[[:digit:]].in' -execdir "man {} > ~/Desktop/`basename {}`" \;
produces the same errors.
 
Old 06-12-2016, 08:58 AM   #5
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Try
Code:
find ./ -name '*.[[:digit:]].in' -printf "%f" -execdir "man {} > ~/Desktop/ {}" \;
But I still think this is not going to work as expected
 
Old 06-12-2016, 08:59 AM   #6
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Quote:
Originally Posted by hydrurga View Post
Code:
find ./ -name '*.[[:digit:]].in' -execdir "man {} > ~/Desktop/`basename {}`" \;
produces the same errors.
That is why I said you need more to handle the file names.

Last edited by jpollard; 06-12-2016 at 09:01 AM.
 
Old 06-12-2016, 09:05 AM   #7
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048

Original Poster
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
Quote:
Originally Posted by keefaz View Post
Try
Code:
find ./ -name '*.[[:digit:]].in' -printf "%f" -execdir "man {} > ~/Desktop/ {}" \;
But I still think this is not going to work as expected
You were right.

Code:
ext2ed.8.infind: ‘man ./ext2ed.8.in > ~/Desktop/ ./ext2ed.8.in’: No such file or directory
e2fsck.8.infind: ‘man ./e2fsck.8.in > ~/Desktop/ ./e2fsck.8.in’: No such file or directory
 
Old 06-12-2016, 09:09 AM   #8
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048

Original Poster
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
Quote:
Originally Posted by jpollard View Post
Try adding `basename {}` intead of just {}

This by itself will not be enough as it will still have the extensions (man pages are USUALLY something like "zsh.1.gz", and doing "man zsh.1.gz" won't work, but "man zsh" will work.

Also note that some man pages (like "stat") have multiple entries, one in any relavent section, thus "man stat" will get you the page for the stat command, but "man 2 stat" will get you the information on the system call. The file name is different too: "stat.2.gz".

The files are "subject"."section"."compression" usually... Sometimes you will find man pages without the compression, but instead the "man" extension.

And that variation requires the filename to be processed in more than the simple approach. I think you will have to parse the file name to handle the section numbers as well.

BTW, the problem has been addressed before:
http://linux.die.net/man/1/bookman
UNFORTUNATELY, my google fu didn't find where the source to the utility was.

If you find it, please post where it is... I (and others) would find it useful as well. It is rather hard to refer to a man page for configuration information... when the computer won't work well enough to access man pages.
I have no problems with the filenames or man structure.

Code:
man ./e2undo.8.in
displays the relevant man page, and

Code:
man ./e2undo.8.in > ~/Desktop/e2undo
pipes it to a folder.
 
Old 06-12-2016, 09:14 AM   #9
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048

Original Poster
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
Quote:
Originally Posted by keefaz View Post
I think you need a small script to parse found files names, I don't think "man ext2ed.8.in" would return something usefull on your system, rather it would be "man 8 ext2ed", no?
The files are all in a directory structure containing the source code of e2fsprogs. The ".in" section reflects the fact that the files are pre-processed to insert some e2fsprogs-specific values (version number etc.) but I don't care about those.

Running

Code:
man ./ext2ed.8.in
produces a good man page. The only problem is that I need the second {} in my one-liner to return the file basename, not the whole path.

I think that jpollard is on to it with his suggestion of using the basename command, it's just a question of finding the right way to incorporate it in the one-liner.
 
Old 06-12-2016, 09:49 AM   #10
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
You don't have the complete man page.

One of the things done to the .in file is to modify configuration pathnames, library references, header references. There can even be differences depending on architecture the resulting software is installed on.

So you are missing a lot more than just the version number.
 
Old 06-12-2016, 10:21 AM   #11
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048

Original Poster
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
Quote:
Originally Posted by jpollard View Post
You don't have the complete man page.

One of the things done to the .in file is to modify configuration pathnames, library references, header references. There can even be differences depending on architecture the resulting software is installed on.

So you are missing a lot more than just the version number.
I appreciate that, thanks, but really it is not important to me.
 
Old 06-12-2016, 10:21 AM   #12
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048

Original Poster
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
Got it:

Code:
find ./ -name '*.[[:digit:]].in' -execdir sh -c 'man {} > ~/Desktop/$(echo $(basename {}) | sed 's/.[0-9].in//')' \;
Thanks for helping me get there.
 
1 members found this post helpful.
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find with -exec argument - not giving proper output..how to find... hinetvenkat Linux - Server 4 01-25-2010 06:19 AM
Find a file path and directory path ak.lokesh Linux - Newbie 3 02-19-2009 12:37 PM
find -exec syntax: bug in find? mfcarroll Programming 5 06-21-2007 07:13 PM
find -exec help dc144 Linux - Newbie 3 10-12-2006 02:14 AM
find -exec cricbk Linux - Newbie 4 01-05-2004 07:03 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:11 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