LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-30-2012, 06:12 PM   #1
rajhans
LQ Newbie
 
Registered: Mar 2012
Location: India
Distribution: i'm a beginner
Posts: 10

Rep: Reputation: Disabled
Question print all the number of extension in system


is it possible to print the names of file extension present in a linux system using shell script?
if yes.
how?
need help.

Last edited by rajhans; 03-30-2012 at 10:52 PM. Reason: it lacks some points..
 
Old 03-30-2012, 07:32 PM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
You will have to explain what you mean by 'extension'. That isn't a standard term in Linux. Do you mean filename extensions; the last part following a dot in a filename?
--- rod.
 
1 members found this post helpful.
Old 03-30-2012, 10:51 PM   #3
rajhans
LQ Newbie
 
Registered: Mar 2012
Location: India
Distribution: i'm a beginner
Posts: 10

Original Poster
Rep: Reputation: Disabled
yes
i mean file extension.
for example
hello.mp3
then mp3 is the file extension...
 
Old 03-31-2012, 12:48 PM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
What have you tried so far? You can find all the file names having an extension by means of the find command using a proper pattern, then fetch the output to sed to extract the extension and finally sort the result removing duplicates. Looking for files all over the system might take a long time, anyway. May I ask what is the purpose of this?
 
1 members found this post helpful.
Old 03-31-2012, 09:44 PM   #5
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
There is a fair bit of ambiguity in your request. For instance, how would you deal with the likes of the following?
Code:
libungif.so.4 -> libgif.so.4.1.6
libungif.so.4.1 -> libgif.so.4.1.6
libungif.so.4.1.6 -> libgif.so.4.1.6
At any rate, I think the approach has to start with find, since you intend to traverse the entire filesystem. The result would then have to be piped to either a file for subsequent processing, or directly to some script that finds and counts filename extensions. The latter would probably best be done with some language that understands associative arrays, since you are going to keep track and count of lists of things that are non-numeric. The script will have to use some of your own definition of what constitutes a filename extension. My own would look something like this (untested):
Code:
#! /usr/bin/perl -w
use strict;

#
#  LQrajhans.pl  ---   find filename extensions, count and list them.
#
my %extensions;

    while(<>){ 
        if( $_ =~ m/.+(\..+)$/ ){ 
            # print $1,"\n"; 
            $extensions{$1}++; 
        } 
    } 
    print "Extensions found: ", int keys %extensions,"\n"; 
    foreach my $ext ( sort keys %extensions ){ 
        print $ext,"\n";
    }
The find command might then look something like:

Code:
find / -type f | LQrajhans.pl
--- rod.

Last edited by theNbomr; 03-31-2012 at 09:46 PM.
 
1 members found this post helpful.
Old 04-02-2012, 11:28 AM   #6
rajhans
LQ Newbie
 
Registered: Mar 2012
Location: India
Distribution: i'm a beginner
Posts: 10

Original Poster
Rep: Reputation: Disabled
i tried dis

find . -type f -maxdepth 1 -iname *.* | sed -e s/^.*\.// | sort -u

not working
 
Old 04-02-2012, 11:30 AM   #7
rajhans
LQ Newbie
 
Registered: Mar 2012
Location: India
Distribution: i'm a beginner
Posts: 10

Original Poster
Rep: Reputation: Disabled
i tried dis
find . -type f -maxdepth 1 -iname *.* | sed -e s/^.*\.// | sort -u

not working
 
Old 04-02-2012, 01:27 PM   #8
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
There are at least a couple of different classes of 'not working', so it behooves you to spell out for us what you mean by 'not working'.
One case is where the tools you try to use complain about the syntax or values of the arguments you supply. That might occur in a bash shell command when you, for instance, fail to provide proper quoting by using either the wrong characters, or use unbalanced quoting. Another type of error might be that you've provided a commandline argument to which the tool you intend to use it makes no sense. Usually, this will result in an error message that you would find helpful in fixing the error. Finally, there are errors in programming logic, where the algorithm you implement does not perform the task you intended. In such cases, it is helpful to describe how the result differs form the intended result.
In all cases, when posting programming code, it is imperative that you use [/CODE]your code here[/CODE] tags to distinguish the characters you type as fully literal, and not to be interpreted as smilies, or have quote marks transformed into other formats.
--- rod.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] OpenSSL PHP extension have to be enabled to use extension repository system. jsaravana87 Linux - Server 2 09-09-2011 01:00 AM
Please chech my statement - delete all except file with largest number extension laki47 Linux - Newbie 3 02-20-2009 07:02 AM
to print the files that ends with .sh extension naveensankineni Programming 4 03-15-2008 09:19 PM
Print from a line number hammertime1983 Linux - Newbie 3 08-20-2007 08:06 AM
how to print system identity on print page livetoday Red Hat 7 06-15-2006 07:59 AM


All times are GMT -5. The time now is 07:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration