1834150 Members
2098 Online
110064 Solutions
New Discussion

list file name

 
SOLVED
Go to solution
hangyu
Regular Advisor

list file name

I want to list the file name in the directory /tmp , if I use "ls -1 /tmp" ,it will list all file name and direcotoy in /tmp , if I want to list file only , want can I do ? thx
6 REPLIES 6
Devender Khatana
Honored Contributor
Solution

Re: list file name

Hi,

Your question is not clear. What do you want to list from /tmp ?

Regards,
Devender
Impossible itself mentions "I m possible"
David de Beer
Valued Contributor

Re: list file name


Perhaps you are thinking of something like

ls -la /tmp/myfile

?

or "'ll /tmp/myfile". ls -la, same as "ll". Still old school, so i use "ls -la" :)

or if you're looking for everything in /tmp that starts with slang in /tmp - then -:

ls -la /tmp/slang*

Regards,
David de Beer.
V. Nyga
Honored Contributor

Re: list file name

Hi,

interesting question - I never used 'ls -1'.
But simple:

ls -F -1| grep -v /

Option -F will give you a '/' after a directory. With 'grep -v /' you only see lines without/'

HTH
Volkmar
*** Say 'Thanks' with Kudos ***
Suraj Singh_1
Trusted Contributor

Re: list file name

Hi,

try

for I in /tmp/*
do
if [ ! -d ${I} ]
then
ll ${I}
fi
done

HTH,
Suraj
What we cannot speak about we must pass over in silence.
Vibhor Kumar Agarwal
Esteemed Contributor

Re: list file name

Assuming that you only want to see the files in your directory and not the sub-directories.

ls -l | grep "^-" | awk '{ print $NF }'

I have used l for long-listing.
Vibhor Kumar Agarwal
Vibhor Kumar Agarwal
Esteemed Contributor

Re: list file name

Well hangyu,

This is a public help forum, but there is a point system to let people know that you have gained something from other people's help.

You haven't yet assigned a single point.

Don't take it the other way, you are new so might not be knowing it.
Vibhor Kumar Agarwal