find . -type f | grep -v '/\.' lists out all non-hidden files in the current dir recursively.
Example of this command given the following file tree
.
├── css
│ ├── base.css
│ └── main.css
├── img
├── index.html
└── js
└── app.js
$ find . -type f | grep -v '/\.'
./index.html
./css/main.css
./css/base.css
./js/app.js
But how do I print all these listed files using lpr?
I tried find . -type f | grep -v '/\.'|lpr but this only prints this list instead of printing each file.
Answer
lpr prints out, what is sent to it via STDIN. So you need to invoke lpr for each file found by find:
find . -type f ! -name ".*" -print0 | xargs -0 lpr
-type fsearches for files!is a logical not, hence! -name ".*"will omit hidden files (with some help from https://superuser.com/a/101012/195224)-print0separates the individual filesnames with\0so that this will also work with file names with white spaces in it.xargsfinally executeslprwith the list of filesnames it receives (-0again tells that\0is used as a delimiter).
This command will list only non-dotfiles, but also those in dotdirs.
If you also want to exclude dotdirs, extend the find command to
find . -type f ! -regex ".*/\..*" ! -name ".*"
And finally, as some versions of lpr have obviously a problem with empty files, omit these also:
find . -type f ! -regex ".*/\..*" ! -name ".*" ! -empty
As a sidenote: To get a nicer layout of your printout (includes file name) you should consider to replace lpr by a2ps.
No comments:
Post a Comment