Find the answer to your Linux question:
Results 1 to 5 of 5
Hi All, I am currently using Ubuntu 9.10, and very much liked it. However, I had used Windows earlier, which used to crash very frequently. So I had to many ...
  1. #1
    Just Joined!
    Join Date
    Dec 2007
    Posts
    32

    Question Sort Out Files based on File Type.

    Hi All,

    I am currently using Ubuntu 9.10, and very much liked it.
    However, I had used Windows earlier, which used to crash very frequently. So I had to many files over and over again. These has now accumulated to more than 30 GB.

    Now I want to sort files according to their file types. Like all *.doc file in "Word Files" Folder, and *.xls to "Excel Files" etc. I need the Command line for this, is it possible to do like this..

    "for i in *.doc;cp "$i" "/word/$i";done"

    Open to any other suggestions.

    Also I need to compare files and if they are the same files (to be Checked with Content not Name), delete the older version, for this any utility/Tools/Programs availble


    Thanks,
    Harish.A

  2. #2
    Just Joined!
    Join Date
    Aug 2005
    Posts
    65
    to search in the directory and the subdirectories
    Code:
    find . -name "*.doc" -exec mv {} /path/to/doc/files
    this will move the files in a location u choose but it will override the files according to names without comparing the content .
    u can add to mv , mv -i , to make it interactive

    for comparing , after moving the files in its folder u can use this
    Code:
    for i in * 
    do
    for j in *
    do 
     diff $i $j && [ $i != $j ] && rm $i
    done
    done
    it looks working , try it with caution

  3. #3
    Just Joined! mehorter's Avatar
    Join Date
    May 2006
    Posts
    20
    Quote Originally Posted by deepinlife View Post
    to search in the directory and the subdirectories
    Code:
    find . -name "*.doc" -exec mv {} /path/to/doc/files

    remember when using caution it is very easy to just add an 'echo' to your commands to see what would happen. Then if you like the out put remove the echo and run again.


    it looks working , try it with caution
    Code:
    echo rm  *files_I_think_would_match*
    good? then run

    Code:
    rm  *files_I_think_would_match*

  4. #4
    drl
    drl is online now
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,117
    Hi.

    You might find this useful:
    Code:
    fdupes - finds duplicate files in a given set of directories
    see man fdupes for details, and write a few test scripts to see how it works.

    I think I would use fdupes before copying the files by content. In Windows the suffix (.doc, .xls, etc) determines the file content. Not so in *nix where the suffix may mean something to other programs (e.g. file.c means something to the c compiler), but not to every utility in general. There is:
    Code:
    file - determine file type
    to help you with identification of content; see man file, and again I suggest getting comfortable by writing a few test scripts.

    The advice from mehorter is very good to avoid calamities, and a good backup is the final guard against human error, as well as against equipment failure.

    Best wishes ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  5. #5
    Just Joined!
    Join Date
    Dec 2007
    Posts
    32
    Hi,

    Thanks for the suggestions, I will try it out.

Posting Permissions

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