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:
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:
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).
Each call to system() creates a separate shell execution environment. Once the commands given to a call to system() complete, that environment is gone.
So, if you call system two times:
the first call will not affect the directory in which the second call is run. But, if you perform the cd and the ls and sort pipeline in the same call to system() as in:
then the cd command will affect the directory where the pipeline executes.
Do you want the primary sort key of your output to be the file size and the secondary sort key to be the file type? Would you prefer to sort the output with the primary sort key being the file size and the secondary sort key being the file name? Have you looked at all of the options that the ls utility accepts on your system? Do you need both ls and sort? Is there an option to ls that will sort the output by file size and file name instead of having the primary sort key be the file name? If that output is backwards, is there an option to reverse the order of the output produced by ls?
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)