Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have many files in my external harddrive, so I want to automatically tell the computer to sort all my files into folders, by their size, extension, name and other variables. Is there any program that will allow me to perform these tasks. Please teach me how to install it too.

share|improve this question
    
How can you use the script to perform such tasks. –  owl Nov 8 '12 at 10:44
add comment

2 Answers 2

up vote 8 down vote accepted

If you're OK to use bash commands, you should look the man page for the find command Manpage icon.

find . -name \*.txt -size +599k -exec mv {} bigTextFolder \;

With this line, you can move all .txt files bigger or equal than 600KB into the bigTextFolder folder. You can find a lot of documentation about find on the net (Beginner Linux Guide) and the list of all tests available in the man page (first link).

To understand the command, look arguments:

  • . is the directory where find will look for file. You can replace that by the path of your HDD.
  • -name \*.txt is the name filter. It can use wildcards(*) if you escape them with . You can read this like "Find all the file with a name ended by .txt". Replace that by the pattern you're looking for:
    • All file beginning by a: find . -name a\*
    • The file aba.txt: find . -name aba.txt
  • -size +599k is the size filter. Here you say "Find all the file with a size strictly superior too 599KB". Change 599 to the size you want, and k is just the unit.
  • -exec allows to execute another command once a file is found. So here, for each file found, we do mv fileFounded targetFolder. The {} will be replace by your result. This part has to end with \;.

Keep in mind that you have a lot of other filters: type, date, owner, permissions,...

share|improve this answer
    
I need something more specific, I don't quite understand the commands, sorry for the trouble. I am new to linux. –  owl Nov 8 '12 at 11:29
    
Did that work ? Please let us know if you've got any problem. –  NorTicUs Nov 9 '12 at 9:44
    
Yeah, I think it should. However, I don't quite understand it, so I might need a video demonstration, to get it clear. –  owl Nov 9 '12 at 12:48
add comment

I am not aware of some readily available program for it, but you can write a shell script by combining commands like

du -a | sort -nr

will display files in reverse order of size.

and you can use it in combination with NorTicUs's script mentioned in post above

find . -name \*.txt -size +599k -exec mv {} bigTextFolder \;

to specify dynamic size by replacing 599K with variable holding output of 1st command.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.