Sorting files in a directory


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Sorting files in a directory
# 1  
Old 09-02-2006
Sorting files in a directory

Hi guys,

Probably an easy one, but how do you sort a directory so that the files come first, then subdirectories?

ie ./dir1 has

file 1
subdir 1
file 2

i need it to become

file 1
file 2
subdir 1

as i'm using it in a script to pass each one through a for loop, and would like all the files done before going into the subdir.

Many thanks in advance

Oliver
# 2  
Old 09-02-2006
Please don't bump up your questions, you have posted same question in other forum also, wait until someone answers your query.
# 3  
Old 09-02-2006
Apologies, just wasen't sure which forum was appropriate, and also which one receives more attention.

Again, apologies

Oliver
# 4  
Old 09-06-2006
MySQL

May be there could be some more simpler way to get it done, but as of now all i could think of is something like

Code:
ls -l | sort -rd | awk '{ print $9 }'

Rishi
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Directory containing files,Print names of the files in the directory that are exactly same content.

Given a directory containing say a few thousand files, please output a list of all the names of the files in the directory that are exactly the same, i.e. have the same contents. func(a_directory_name) output -> {“matches”: , ... ]} e.g. func(“/home/my/files”) where the directory... (7 Replies)
Discussion started by: anuragpgtgerman
7 Replies

2. 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

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. UNIX for Dummies Questions & Answers

help with sorting files

find / -type f 2> /dev/null | find -inum +1 2> /dev/null | find -mtime -30 2> /dev/null what i am trying to do i search all regular files in root directory with one or more inodes modified within last 30 days. the /dev/null is to suppress the permission denied outputs. i am now trying to... (5 Replies)
Discussion started by: iluvsushi
5 Replies

5. Shell Programming and Scripting

Sorting issue with directory and file name

Hi All, My folder contains the files as: $ ls -lrt total 50 lms_prap_rf_20100422_99.xml lms_prap_rf_20100422_9.xml lms_prap_rf_20100422_100.xml lms_prap_rf_20100422_10.xml lms_prap_rf_20100426_1.xml I need to get the sorting of the above file based on numbers. I need first file in... (5 Replies)
Discussion started by: sreejitnair123
5 Replies

6. Shell Programming and Scripting

Sorting by Full directory path

I have a text file with full list of files with their full path. I wanted to sort it by directory then files then subdirectory by alphabetically. When I used the sort command it doesn't give like what I want. Could somebody help me on this. Here is the ex: This is what I'm getting... (2 Replies)
Discussion started by: javidraaj
2 Replies

7. 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

8. UNIX for Dummies Questions & Answers

Sorting Directory Listing

If I do an ls -l on a directory I get this: -rw-r--r-- 1 root other 5248094 Jun 24 03:56 monitor.log.7 -rw-r--r-- 1 root other 5248303 Jul 11 11:19 ct.log.1 -rw-r--r-- 1 root other 5248907 Jun 29 06:01 ct_monitor.log.5 -rw-r--r-- 1 root other 5249042 Jun 19... (1 Reply)
Discussion started by: Sepia
1 Replies

9. Shell Programming and Scripting

Sorting files in a directory

Hi guys, Probably an easy one, but how do you sort a directory so that the files come first, then subdirectories? ie ./dir1 contains file 1 subdir 1 file 2 i need it to become file 1 file 2 subdir 1 as i'm using it in a script to pass each one through a for loop, and would... (2 Replies)
Discussion started by: olimiles
2 Replies

10. Shell Programming and Scripting

Sorting Files

How to sort such files which contains records of varying length and varying lines? (With respect to Bash shell) Eg: Each record begins with a sting of 1/0(binary) which may or may not be followed by properties like AB,BS etc. I have to sort such records on the basis of 1/0 string and keep the... (2 Replies)
Discussion started by: sandeep_hi
2 Replies
Login or Register to Ask a Question