CLI

From AdminWiki

(Difference between revisions)
Jump to: navigation, search
(command line interface examples)
 
(7 intermediate revisions not shown)
Line 1: Line 1:
-
= CLI =
+
Common solutions to common problems when working with CLI tools.
-
The Command Line Interface is the powerway to talk to your system
+
== Problems and Solutions ==
 +
=== Get the last element from a path ===
-
== Problems and Solutions ==
+
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 ===
-
=== Get the last element from a cut situation ===
+
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
-
if you have /path/sub/over/unter/filename.txt and you want to get the filename.txt then do this:
+
=== Some light relief with Roulette ===
-
  echo /path/sub/over/unter/filename.txt | awk -F/ '{ printf("%s\n", $NF)}'
+
-
and it will return just filename.txt
+
-
--[[User:Gullevek|gullevek]] 03:08, 24 May 2006 (CEST)
+
# [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "You live"

Latest revision as of 11:51, 10 April 2009

Common solutions to common problems when working with CLI tools.

Contents

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

Some light relief with Roulette

# [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "You live"
Personal tools