Sorting files by size. No ls.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sorting files by size. No ls.
# 1  
Old 09-28-2010
Sorting files by size. No ls.

I've got an assignment where I've made a script that searched and found files that meet certain requirement. (Files that are a size that is from "x" to "y" in size and has a certain name).

The script sends the output to a file that gathers the info.

The problem is I'd like to sort what's displayed in that file by size (and I need info on how large the files are, filename and directory).

I've read on the forums and found cases that are ALMOST right on, 'cept I can't use any "ls" commands because that would list and sort all the files in a directory, not the results that I get from my script.

This is the script:

Code:
#!/bin/bash
find . -name 'test*' -size +32c | sort > findtest_info.txt

It returns:

./test2.sh
./test53.sh
./test.sh
./test.txt

Is there any way to sort it via filesize and display the size of the files. In ascending order?

Complete noob here, just started with bash - Cheers, BobbyTee.

Last edited by BobbyTee; 09-28-2010 at 12:02 PM.. Reason: [Edit: Spelling errors, LOTS of them...]
# 2  
Old 09-28-2010
Try this

Quote:
#!/bin/bash
find . -name 'test*' -size +32c -exec du -sk {} \; | sort -n
This will get the size of the files in KBs and will sort in ascending order of size with filename printed, example

8 ./vishu2
80 ./vishal
112 ./vishal_log_bak
# 3  
Old 09-28-2010
For me this returns the correct files, but it says that they're all 4kb.. :S
4 ./test2.sh
4 ./test53.sh
4 ./test.sh
4 ./test.txt

The files range from 34bytes to 1.7kb.
Cheers, BobbyTee
# 4  
Old 09-28-2010
God dag til Norge.

Homework and coursework questions can only be posted in this forum under special homework rules.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Sorting files by size in another directory

1. The problem statement, all variables and given/known data: I'm trying to use a directory path to enter a new directory and sort the files there. I'm using the language C with a system call in Unix to sort the files from smallest to largest. 2. Relevant commands, code, scripts, algorithms:... (1 Reply)
Discussion started by: TedFTW
1 Replies

2. Shell Programming and Scripting

Sorting riles by size with -nr

Hello everyone, I am working on this bash script and I can't seem to get this last part right. It's really trivial but I must not be doing something right. I want to sort files by their size in reverse order (largest to smallest). My script right now sort of tdoes this but there is one file that... (3 Replies)
Discussion started by: tastybrownies
3 Replies

3. Shell Programming and Scripting

Complex data sorting in excel files or text files

Dear all, I have a complex data file shown below,,,,, A_ABCD_13208 0 0 4.16735 141044 902449 1293900 168919 C_ABCD_13208 0 0 4.16735 141044 902449 1293900 168919 A_ABCDEF715 52410.9 18598.2 10611 10754.7 122535 252426 36631.4 C_DBCDI_1353 0... (19 Replies)
Discussion started by: AAWT
19 Replies

4. Shell Programming and Scripting

Sorting files

I have the following set of files and I want to order them according to the ascending values of the run: For example, doing ls -lrt *drw*.log gives n02-z30-sr65-rgdt0p25-dc0p08-4x3drw.log n02-z30-sr65-rgdt0p25-dc0p03-8x6drw.log n02-z30-sr65-rgdt0p25-dc0p01-8x6drw.log ... (18 Replies)
Discussion started by: kristinu
18 Replies

5. Red Hat

Sorting folder size not working

I am using du -h --max-depth=2 to get list of folders by size upto 2 levels down. Problem is I am not able to sort them in max folder size. Normally this can be achieved by using du -k | sort -nr * but I can't use it here since it conflicts (the -s argument) with the --max-depth=2 argument. ... (1 Reply)
Discussion started by: rockf1bull
1 Replies

6. Shell Programming and Scripting

i need help in sorting two files

i have file a 123 234 456 567 678 and file b 123|xxx|hhh|ppp or zzz 234|rrr|ttt|xxx 432|ttt|mmm|nnn 678|cft|byt|mop i want to compare file a to file b such that when each of the lines in file a can be found in file b column1 and also xxx or hhh or ppp or zzz can be... (12 Replies)
Discussion started by: blackzinga80
12 Replies

7. Shell Programming and Scripting

sorting files

hi i have file like below: col1,col2,col3,col4 val1,val2,val3,val4 abc1,abc2,abc3,abc4 this is a 4 column file with 3 rows. i want to sort the file like.. first on col1, then on col2 and so ..on.. i want the sort order to be descending. Pls help.. Thnks Sumit (2 Replies)
Discussion started by: sumit207
2 Replies

8. UNIX for Dummies Questions & Answers

Need some help for sorting files

I am new to shell scripting can u guys please provide a small script for the following senario step1:need to find some files in a directory for ex having 020908 step2:sort them and redirecting to new file (ex:sort abc > abc.sort) i am trying this but giveing flag error ls -l... (4 Replies)
Discussion started by: cgreddy2020
4 Replies

9. Shell Programming and Scripting

bash script working for small size files but not for big size files.

Hi, I have one file stat. Stat file contents are as follows: for example. H50768020040913,00260100,507680,13,0000000643,0000000643,00000,0000 H50769520040808,00260100,507695,13,0000000000,0000000000,00000,0000 H50770620040611,00260100,507706,13,0000000000,0000000000,00000,0000 Now i... (1 Reply)
Discussion started by: davidpreml
1 Replies

10. Shell Programming and Scripting

Sorting files

Hi, What is the command for sorting files according to their size Thanx in advance (4 Replies)
Discussion started by: sendhil
4 Replies
Login or Register to Ask a Question