Operating System - HP-UX
1849594 Members
6547 Online
104044 Solutions
New Discussion

How to list only files on HP-UX B.11.11 U 9000/800

 
SOLVED
Go to solution
diwa
Frequent Advisor

How to list only files on HP-UX B.11.11 U 9000/800

Hi,

One dir is having files and dirs. I want to list only files. Can any one suggest how to do this?

Thanks
9 REPLIES 9
Ivan Krastev
Honored Contributor

Re: How to list only files on HP-UX B.11.11 U 9000/800

use:

find . -type f

regards,
ivan
Steven E. Protter
Exalted Contributor

Re: How to list only files on HP-UX B.11.11 U 9000/800

Shalom,

find -type f

This will show only files, not directories.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
diwa
Frequent Advisor

Re: How to list only files on HP-UX B.11.11 U 9000/800

Hi,

Soory but i want something like that:

Suppose i am under dir1:
under this i am having files f1.txt,f2.txt,f3.txt and subdir subdir1,subdir2.

Now if i use ls -lrt it will list all the files as well as dir.

If i use ls -lrt | grep "^d" it will list only dir.

Similarly i want some command which will display f1.txt,f2.txt.f3.txt and nothing else menas no files under subdir1 and so on.

Thanks.
V. Nyga
Honored Contributor

Re: How to list only files on HP-UX B.11.11 U 9000/800

Hi,

add option '-p' to your ls command, then pipe it to grep: '| grep -v /'

This exludes directories listed with '/' at the end (option -p of ls command)

HTH
Volkmar
*** Say 'Thanks' with Kudos ***
V. Nyga
Honored Contributor

Re: How to list only files on HP-UX B.11.11 U 9000/800

ls -lrt | grep -v "^d" will work too

V.
*** Say 'Thanks' with Kudos ***
Sandman!
Honored Contributor

Re: How to list only files on HP-UX B.11.11 U 9000/800

# ls -ltr | grep ^-
Peter Nikitka
Honored Contributor
Solution

Re: How to list only files on HP-UX B.11.11 U 9000/800

Hi,

first I want to remember, that there is more than (plain) files and directories:
sockets, named pipes, symbolic links, block and character devices, ... (*)
Excluding directories is one point, listing only plain files another.

Second: It seems necessary for me to get just filenames without additional stat information.

I want to highlight some aspects of the two solutions of Volker and Sandman (dropped options 'rt' which are meaningless here):
1) ls -p | grep -v /
- prints no additional status information
- prints anything but directories (including (*))
This is the best solution if you do not want to get plain files only.

2) ls -l | grep -v "^d"
- prints additional status information
- like 1)

3) ls -l | grep ^-
- prints additional status information
- list just plain files, which are not symlinks

Though you could use the option 'ls -F' and filter its additional markers out, this won't seperate the block+character devices.
My favourite (the 'sub' has six spaces in it):

ls -go | awk '/^-/ {for(i=1;i<7;i++) $i="";sub("^ ","");print}'

This will lead to correct results even when files containing whitespace are found.

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
diwa
Frequent Advisor

Re: How to list only files on HP-UX B.11.11 U 9000/800

Hi,

Thanks a lot for your sloutions.

Special thanks to Peter.


diwa
Frequent Advisor

Re: How to list only files on HP-UX B.11.11 U 9000/800

Thanks a lot,

I got satisfactory answers for my query.