List filename of files only inside a directory (non-recurrsive) on AIX

I wish to list only files along with the absolute path in a given directory on my AiX 6.1 system.

Below is the best I could do.

ls -p "/app/scripts"/*

This gives a a list of all filename along with folder names with absolute path non-recurrsive (without listing files in sub-directories)

I notice that each directory is listed with a colon ':' at the end which I wish to eleminate as shown below.

Can we grep for the listing with a colon at the end as I m not expecting my filenames to have a colon at the end ? if yes how can i do that. Below is how I tried to grep each entry ending with a colon in ksh shell but none of them worked.

echo "/app/scripts/myfolder:" | grep *: 
echo "/app/scripts/myfolder:" | grep "*:"
echo "/app/scripts/myfolder:" | grep *':'
echo "/app/scripts/myfolder:" | grep *":"

This approach is pretty fast and hence I like it.

I tried find command but it is searching recurrsively inside sub-directories.

Can you please suggest ?

grep for items ending with a :

grep ':$'

The $ indicates the line end.
But doesn't the -p option let the ls command add a / to the end of directory names?
Then grep -v '/$' or grep '[^/]$' can eliminate them.

1 Like
Moderator comments were removed during original forum migration.