Sponsored Content
Homework and Emergencies Homework & Coursework Questions Sorting files by size in another directory Post 302900085 by TedFTW on Sunday 4th of May 2014 01:36:46 AM
Old 05-04-2014
Wrench 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:
Code:
system("ls -al | sort -k5n >> tempfile.txt");

This command enters the sorted data into a temporary directory named tempfile.txt. Tempfile.txt is later deleted. But the command:
system("ls -al | sort -k5n");
sorts only the data in the current directory. I would like to be able to sort data in any directory entered into my program.



3. The attempts at a solution (include all code and scripts):
i've tried:
Code:
       sprintf(cmd, "cd %s", argv[PATH]);
       system(cmd);

to change directories before using the sort command. But this doesn't work. I do not know very much about the Unix language to create a command that changes directories and sorts the files it finds there.


4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

University at Albany, Albany NY, United States, S.S. Ravi, CSI 402


Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

Last edited by vbe; 05-04-2014 at 05:30 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to check if 3 files have same size in directory

I need to determine if any three files have the same file size in a specified directly? I have got as far as listing the file sizes but where to go from here? ls -al |sort -n -r +4 | awq '{print $5}' Thanks in anticipation (5 Replies)
Discussion started by: oggle
5 Replies

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

3. UNIX for Dummies Questions & Answers

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... (3 Replies)
Discussion started by: olimiles
3 Replies

4. Shell Programming and Scripting

files of size 0 need to be deleted inside a directory

Hiiii, I have written a script which takes backup of some log files. let say the backuplocation is --- /abc/backuplocation -rw-r--r-- 1 webmut2 spgroup 0 Jan 27 02:41 ansrpt23994.log -rw-r--r-- 1 webmut2 spgroup 0 Jan 27 02:41 ansrpt3601.log -rw-r--r-- 1... (2 Replies)
Discussion started by: namishtiwari
2 Replies

5. UNIX for Dummies Questions & Answers

listing files in a directory in bases of size

Hi , I want to list all files in the order of size . Just want to know which files occupies more size and which occupies less size . Is it possible with ls command ? :) Thanks, Arun. (1 Reply)
Discussion started by: arunkumar_mca
1 Replies

6. UNIX for Dummies Questions & Answers

Cp files (>5 Mb size) from one directory to another

Hi All, I have a requirement like below, I want to transfer few file of size > 5 Mb from one directory to anotehr directory. Please let me know the command how can i do that Sorry if it looks silly Senthil (6 Replies)
Discussion started by: skcontact
6 Replies

7. Shell Programming and Scripting

Getting the total file size for certain files per directory

Hi, I am trying to get the total file size for certain files per directory. I am using find /DirectoryPath -name '*.dta' -exec ls -l {} \; | awk '{ print $NF ": " $5 }' > /users/cergun/My\ Documents/dtafiles.txt but this lists all the files in the directories. I need the total... (9 Replies)
Discussion started by: cergun
9 Replies

8. Shell Programming and Scripting

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... (3 Replies)
Discussion started by: BobbyTee
3 Replies

9. UNIX for Dummies Questions & Answers

How to get the set of files size as a sum in a directory.

Hi, Can someone help me to get the complete files size (sum) over a perod time (1 day,2days)in a directory. eg: Directory :ABC I have a1,a2,a3 files are created in last 24 hours so I need to get the some of all these files. I am using the below find command but its giving me the... (1 Reply)
Discussion started by: gaddamja
1 Replies

10. Shell Programming and Scripting

How to delete some of the files in the directory, if the directory size limits the specified size

To find the whole size of a particular directory i use "du -sk /dirname".. but after finding the direcory's size how do i make conditions like if the size of the dir is more than 1 GB i hav to delete some of the files inside the dir (0 Replies)
Discussion started by: shaal89
0 Replies
WRAP-AND-SORT(1)					      General Commands Manual						  WRAP-AND-SORT(1)

NAME
wrap-and-sort - wrap long lines and sort items in Debian packaging files SYNOPSIS
wrap-and-sort [options] DESCRIPTION
wrap-and-sort wraps the package lists in Debian control files. By default the lists will only split into multiple lines if the entries are longer than 80 characters. wrap-and-sort sorts the package lists in Debian control files and all .install files. Beside that wrap-and-sort removes trailing spaces in these files. This script should be run in the root of a Debian package tree. It searches for control, control.in, copyright, copyright.in, install, and *.install in the debian directory. OPTIONS
-h, --help Show this help message and exit. -a, --wrap-always Wrap all package lists in the Debian control file even if the entries are shorter than 80 characters and could fit in one line line. -s, --short-indent Only indent wrapped lines by one space (default is in-line with the field name). -b, --sort-binary-packages Sort binary package paragraphs by name. -k, --keep-first When sorting binary package paragraphs, leave the first one at the top. Unqualified debhelper(7) configuration files are applied to the first package. -n, --no-cleanup Do not remove trailing whitespaces. -d path, --debian-directory=path Location of the debian directory (default: ./debian). -f file, --file=file Wrap and sort only the specified file. You can specify this parameter multiple times. All supported files will be processed if no files are specified. -v, --verbose Print all files that are touched. AUTHORS
wrap-and-sort and this manpage have been written by Benjamin Drung <bdrung@debian.org>. Both are released under the ISC license. DEBIAN
Debian Utilities WRAP-AND-SORT(1)
All times are GMT -4. The time now is 02:20 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy