2

I want to define a new ls command to do something like this

The first when i use ordinary ls command:

$ls
undergrade.AI              undergrade.KDD
undergrade.AI2             undergrade.micro
undergrade.ANN             undergrade.OOT
undergrade.autoMata        undergrade.OS
undergrade.bulletin        undergrade.parallelAndDistributedProgramming
undergrade.CG              undergrade.pop
undergrade.CLP             undergrade.PPL
undergrade.comNet          undergrade.researchingMethod
undergrade.comOr           undergrade.SA
undergrade.comSec          undergrade.SE
undergrade.DBMS            undergrade.softwareTesting
undergrade.discrete        undergrade.webApps
code.ajax  code.cc  code.erl  code.html    code.js    code.pl     code.py   
code.sage  code.x3d code.c    code.cl      code.go    code.jquery code.lisp  
code.pro   code.roo code.sh   code.xml

And for a new ls that i want:

$ls_new
undergrade  code

I want it to show only the first word when i type ls_new.

Why do i want this command?

Because i named my folders in pattern of category.subj that so too much output when i use ordinary ls. then i need some command that can filter, group and show them but only the category name.

2
  • You should make undergrade and code directories with subdirectories called AI, ajax, etc... Directories nest for a reason! Nov 1, 2013 at 23:31
  • … and they make beautiful tree outputs ;)
    – Runium
    Nov 2, 2013 at 12:24

2 Answers 2

3

This should do what you want:

ls|sed 's/\..*//'|sort -u|column

If your shell has the width of your terminal in $COLUMNS, then this is better:

ls|sed 's/\..*//'|sort -u|column -c $COLUMNS
3

Another way with awk:

ls | awk -F. '$1 != p { p=$1; print $1}'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .