unix - echoing specific files, excluding some characters -


i have folder few files, these 3:

vmware-diskmanager vmware-disklib.tar.gz vmware-disklib-distrib 

if want echo both files without .tar.gz extension, can use

# echo v* 

but let's have file

vmware-disklib 

then use

# echo [vv]* 

to 4 files, can complete command line says "don't show files dot in it"?

 with bash

if use bash, see man bash, expansion > pathname expansion > pattern matching:

if extglob shell option enabled using shopt builtin, several extended pattern matching operators recognized.

(this option seems default.) in particular can use:

!(pattern-list):
matches except 1 of given patterns

so in case work:

echo [vv]!(*.*) 

with find

i use zsh instead of bash , not work. have not checked wether there equivalent syntax zsh, go solution find:

find . -maxdepth 1 -iregex './v[^.]*' -exec echo -n "{} " \; 

where:

  • . directory search
  • -maxdepth 1 limits search current directory (no recursion)
  • -iregex './v[^.]*' applies case-insensitive regex whole path of files in current directory
  • -exec echo -n "{}" indicates echo file name (the name replace {} placeholder) without linebreak
  • \; needed end -exec command.

it should print name of files ./ @ beginning , without linebreak @ end. on plus side, can use regex.


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -