Results 1 to 6 of 6

Thread: print a list of all file types in a folder?

  1. #1
    Join Date
    Oct 2008
    Location
    /usr/bin/
    Beans
    442
    Distro
    Ubuntu

    print a list of all file types in a folder?

    I want to print to the screen a list of all file types *.ext in a folder and its sub_folders

    so the list will be something like this

    avi
    txt
    jpg
    doc

  2. #2
    Join Date
    Jul 2006
    Beans
    607
    Distro
    Ubuntu 13.04 Raring Ringtail

    Re: print a list of all file types in a folder?

    What is wrong with good old
    Code:
    ~ $ ls
    You might also find the tree command useful.

    Code:
    ~ $ sudo apt-get install tree
    Code:
    ~ $ tree

  3. #3
    Join Date
    Oct 2008
    Location
    /usr/bin/
    Beans
    442
    Distro
    Ubuntu

    Re: print a list of all file types in a folder?

    Quote Originally Posted by foxmulder881 View Post
    What is wrong with good old
    Code:
    ~ $ ls
    You might also find the tree command useful.

    Code:
    ~ $ sudo apt-get install tree
    Code:
    ~ $ tree
    yes I know ls and tree but I only want to see the file types not a massive list of everything in the folder and sub_folders as there are 10000s of files

    I just want a list like this showing the different file types

    avi
    txt
    jpg
    doc

  4. #4
    Join Date
    Jul 2009
    Beans
    425
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: print a list of all file types in a folder?

    You can get a list of all extensions with the following
    Code:
    find . -type f | sed -e 's/^.*\.\([^\.]*$\)/\1/' -e '/^\//d' | sort -u
    First cd to the top directory, it'll then print every unique extension it finds. If a file doesn't have an extension it'll be excluded from the list.
    Mark your thread as [SOLVED], use Thread Tools on forum page.

  5. #5
    Join Date
    Oct 2008
    Location
    /usr/bin/
    Beans
    442
    Distro
    Ubuntu

    Re: print a list of all file types in a folder?

    Quote Originally Posted by btindie View Post
    You can get a list of all extensions with the following
    Code:
    find . -type f | sed -e 's/^.*\.\([^\.]*$\)/\1/' -e '/^\//d' | sort -u
    First cd to the top directory, it'll then print every unique extension it finds. If a file doesn't have an extension it'll be excluded from the list.
    thanks

  6. #6
    Join Date
    Jul 2006
    Beans
    607
    Distro
    Ubuntu 13.04 Raring Ringtail

    Re: print a list of all file types in a folder?

    Holy crap, even after 10 years Unix usage, I've never seen a command look like that. Well done.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •