CLI
From AdminWiki
(Difference between revisions)
| Line 7: | Line 7: | ||
if you have /path/sub/over/unter/filename.txt and you want to get the filename.txt basename does the trick: | if you have /path/sub/over/unter/filename.txt and you want to get the filename.txt basename does the trick: | ||
echo /path/sub/over/unter/filename.txt | basename | echo /path/sub/over/unter/filename.txt | basename | ||
| + | |||
| + | === Find files matching a certain pattern - weird filename safe & multicore capable === | ||
| + | |||
| + | WHATEVER is the pattern you are looking for, 4 is the number of cpus you have available for the job. | ||
| + | find . -type f -print0 | xargs -P 4 -0 echo grep -H WHATEVER | ||
Revision as of 11:50, 10 April 2009
Common solutions to common problems when working with CLI tools.
Problems and Solutions
Get the last element from a path
if you have /path/sub/over/unter/filename.txt and you want to get the filename.txt basename does the trick:
echo /path/sub/over/unter/filename.txt | basename
Find files matching a certain pattern - weird filename safe & multicore capable
WHATEVER is the pattern you are looking for, 4 is the number of cpus you have available for the job.
find . -type f -print0 | xargs -P 4 -0 echo grep -H WHATEVER