list any random first 5 files with 'ls'


 
Thread Tools Search this Thread
Operating Systems Solaris list any random first 5 files with 'ls'
# 1  
Old 11-29-2011
list any random first 5 files with 'ls'

I just need to see any number of random files to see the owner, group and permissions information since all the files in the directory have the same permissions and ownership information. Is it possible just to list any 5 files without going thru the series of commands such as "ls -ltu | head -5" since they all have to be processed in a sequential order and take more time than just getting the output of the 'ls'. For me the 'list' command itself takes a while to display due to the high number of files.
# 2  
Old 11-29-2011
I just checked Solaris 10.. It's not working there.
This User Gave Thanks to bartus11 For This Post:
# 3  
Old 11-29-2011
First of all, thank you so much for your reply.
Well, running your command in the directory returned a warning as below. BTW, it doesn't have to five. One will do it as well.
Code:
find . -type f -ls -quit
find: bad option -quit
find: [-H | -L] path-list predicate-list

# 4  
Old 11-29-2011
Well.. you could use some dirty hack solution: In one session run
Code:
find . -type f -ls

In another kill it with
Code:
pkill find

or something similar.
This User Gave Thanks to bartus11 For This Post:
# 5  
Old 11-29-2011
That is a good trick. Thanks a lot for your thoughts.
# 6  
Old 11-29-2011
You can also cancel the execution with "CTRL-C". The "pkill" version is for the case when that wouldn't work (like too much output going to the screen, etc).
# 7  
Old 11-29-2011
FWIW - rebuild the directories. When one directory has a large number of files it becomes progressively slower when you issue an ls command. To the point where it becomes usable.

The short answer to the question is to write C (or perl), use dirent (opendir(), readdir(), closedir() ) read just five files.

Does the ownership of the directory tell you nothing that will let you make a smart guess on something like this:
Code:
ls -l [I already know this filename]

This is lots faster to begin with. Directory entries are hashed in ZFS. ufs does that as well.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to generate a file with random data. /dev/[u]random doesn't exist.

Need to use dd to generate a large file from a sample file of random data. This is because I don't have /dev/urandom. I create a named pipe then: dd if=mynamed.fifo do=myfile.fifo bs=1024 count=1024 but when I cat a file to the fifo that's 1024 random bytes: cat randomfile.txt >... (7 Replies)
Discussion started by: Devyn
7 Replies

2. Shell Programming and Scripting

Copy list of files from a keyword list to another directory

Hello, I have a folder with a massive amount of files, and I want to copy out a specific subset of the files to a new directory. I would like to use a text file with the filenames listed, but can't get it to work. The thing I'm hung up on is that the folder names in the path can and do have... (5 Replies)
Discussion started by: twjolson
5 Replies

3. Shell Programming and Scripting

copying random Jpg files to different folder

Hi, I have 200 pictures in a folder and I would like move 10 random pictures every week to given folder automatically. I have this server on 1and1.com. So I tried the following using Bash script for manual copy and paste for testing #!/bin/bash mapfile -t -n 3 files < <(find... (13 Replies)
Discussion started by: raamkum
13 Replies

4. Shell Programming and Scripting

Take a list if strings from a file and search them in a list of files and report them

I have a file 1.txt with the below contents. -----cat 1.txt----- 1234 5678 1256 1234 1247 ------------------- I have 3 more files in a folder -----ls -lrt------- A1.txt A2.txt A3.txt ------------------- The contents of those three files are similar format with different data values... (8 Replies)
Discussion started by: realspirituals
8 Replies

5. Ubuntu

expect script for random password and random commands

Hi I am new to expect. Please if any one can help on my issue its really appreciable. here is my issue: I want expect script for random passwords and random commands generation. please can anyone help me? Many Thanks in advance (0 Replies)
Discussion started by: vanid
0 Replies

6. Shell Programming and Scripting

shell script to auto process ten random files and generate logs

Hello member's I'm learning to script in the ksh environment on a Solaris Box. I have 10 files in a directory that I need to pass, as input to a batch job one by one. lets say, the files are named as follows: abcd.txt ; efgh.bat ; wxyz.temp etc. (random filenames with varied extensions ).... (1 Reply)
Discussion started by: novice82
1 Replies

7. UNIX for Dummies Questions & Answers

counting a list of string in a list of txt files

Hi there! I have 150 txt files named chunk1, chunk2, ........., chunk150. I have a second file called string.txt with more than 1000 unique strings, house, dog, cat ... I want to know which command I should use to count how many times each string appears in the 150 files. I have tried... (4 Replies)
Discussion started by: Pep Puigvert
4 Replies

8. Shell Programming and Scripting

FTP random files

Hello everyone, What I'm trying to do is figure out how to ftp a set of random files each day about 50 or so maybe more or less. I have a folder on my server that gets about 1000 or so new files each day, each with today's date in the file name. We just want to take a sample each day for... (3 Replies)
Discussion started by: whegra
3 Replies

9. Shell Programming and Scripting

Random files do not FTP in the shell script

The following script is used to loop through files in the /tmp directory and transfer those files onto another server. However, some of the files do not transfer. It is very random when the transferring is done (i.e. one of the files won't transfer then next time, that one will transfer and... (1 Reply)
Discussion started by: RLatham20
1 Replies

10. Shell Programming and Scripting

how to generate a random list from a given list

Dear Masters, Is there an easy way to generate a random list from a give list of names? Let's say, I have a file containing 15000 city name of world(spreadsheet, names in the first column), I would like to randomly pick up 50 cities each time for total 1000 picks. Or doesn't anyone know a... (3 Replies)
Discussion started by: mskcc
3 Replies
Login or Register to Ask a Question