Day 14 10 min
xargs
1 / 11 · ≈ 7 min left
The problem
The disk of a build server is at 97%. find and grep give you lists of file names, one per line, but rm, gzip and cp want the names as arguments. xargs reads the list on standard input and builds those command lines for you.
The reps use one folder. logs/ holds api.log (3 lines, one of them FATAL db down), web.log (2 lines), old report.log, stale.tmp and cache 1.tmp; 2 of those names contain a space. files.txt lists logs/api.log and logs/web.log, one per line. paths.txt lists 3 full paths: /var/log/nginx/access.log, /var/log/nginx/error.log and /var/log/syslog. hosts.txt lists web1, web2 and db1.