Visit Our UNIX and Linux User Community


list the files but exclude the files in subdirectories


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers list the files but exclude the files in subdirectories
# 1  
Old 05-16-2008
Question list the files but exclude the files in subdirectories

If I execute the command "ls -l /export/home/abcde/dev/proj/code/* | awk -F' ' '{print $9}' | cut -d'/' -f6-8" it will list all the files in /export/home/abcde/dev/proj/code/ directory as well as the files in subdirectories also
proj/code/test.sh
proj/code/test1.c
proj/code/unix
proj/code/xml_db


CPP: SUBDIRECTORY
a.out
constr.cpp
fn_ptr.cpp
samp.cpp


MYSCRIPTS: SUBDIRECTORY
autoTest.sh
file2.txt
filenames.txt
filenames.txt


Is there any way to list only the files mentioned in path /export/home/abcde/dev/proj/code/ and should exclude all the files in subdirectories CPP and MYSCRIPTS
proj/code/test.sh
proj/code/test1.c
proj/code/unix
proj/code/xml_db

Thanks in advance...
# 2  
Old 05-16-2008
i) ls -ld
ii) find -maxdepth 1 -type f
# 3  
Old 05-16-2008
Thanks fabtagon
ls -ld worked for me...
# 4  
Old 10-15-2008
ls -l d do not work for me

Hi i want to list only the files within a directory and not the sub directories if any. i tried ls -ld but that is not working for me.
this is the result if I use it in usr/bin
$ pwd
/usr/bin
$ ls -ld
drwxr-xr-x 4 bin bin 40960 Mar 17 2008 .
$
# 5  
Old 10-15-2008
What shell you are using (exact version, if possible)?
# 6  
Old 10-15-2008
I am using K shell but how do I know the version??

$ echo $0
-ksh

Last edited by tosattam; 10-15-2008 at 08:26 AM..
# 7  
Old 10-15-2008
OK,
you may try:

Code:
print $KSH_VERSION

It will return the release of the mksh and pdksh (if I recall correctly).

Otherwise you may try:

Code:
print ${.sh.version}

and it works with ksh93 (that's the most powerful implementation).

If none of the above works, you probably have ksh88 (^V to display its version).

Anyway, I suppose fpmurphy will offer a more succinct solution with ksh93, meanwhile you may try:

Code:
find /usr/bin/* ! -name . -prune -type f -ls

 

Previous Thread | Next Thread
Test Your Knowledge in Computers #689
Difficulty: Medium
The HP-35, the world's first handheld scientific calculator, introduced the classical two-level RPN in 1972.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Append string to all the files inside a directory excluding subdirectories and .zip files

Hii, Could someone help me to append string to the starting of all the filenames inside a directory but it should exclude .zip files and subdirectories. Eg. file1: test1.log file2: test2.log file3 test.zip After running the script file1: string_test1.log file2: string_test2.log file3:... (4 Replies)
Discussion started by: Ravi Kishore
4 Replies

2. UNIX for Dummies Questions & Answers

How to list the names of the files from all the subdirectories?

Hi, I'm currently trying to print the names of all the .txt files in the subdirectories that contain the string I'm searching. I tried with this code, but it seems that it searches for the names that matches the string instead of searching for the string in the individual files and printing the... (2 Replies)
Discussion started by: nuclearpenguin
2 Replies

3. Shell Programming and Scripting

Bash script deleting my files, and editing files in subdirectories question

#!/bin/bash # name=$1 type=$2 number=1 for file in ./** do if then filenumber=00$number elif then filenumber=0$number fi tempname="$name""$filenumber"."$type" if (4 Replies)
Discussion started by: TheGreatGizmo
4 Replies

4. UNIX for Advanced & Expert Users

List all files in subdirectories which are modifiled recently.

Hello, I wanted to list all files in subdirectories which are modifiled recently. need to display all files with full details like hpw it display with ls -l ( date, size,..) Thanks Bala (3 Replies)
Discussion started by: balareddy
3 Replies

5. Shell Programming and Scripting

List files with *.i extension in a directory and all its subdirectories + 30days old then remove

I need to write a script to : list files with *.i extension in a directory and all its subdirectories + 30days old, save it in a file and then remove (2 Replies)
Discussion started by: lena keung
2 Replies

6. Linux

List all files created today exclude last one

Hi, ALL thanks in advance, i listed all files using this command ls -ltr $(date +%Y%m%d)*.xmlbut i would like to exclude the last one created ; Best regard MEROUAN Use code tags, thanks. (4 Replies)
Discussion started by: merouan
4 Replies

7. Shell Programming and Scripting

How to list all Subdirectories and files with its full path in a parent directory?

How to list all Subdirectories and files with its full path in a parent directory? (1 Reply)
Discussion started by: johnveslin
1 Replies

8. Shell Programming and Scripting

Remove files from subdirectories given a list of filenames

Dear all, I have a dir structure like main_dir At_nn Ag_js Nf_hc .... mcd32 mgd43... mcd32 mgd43... mcd32 mgd43... and each subdir (e.g. mcd32, mgd43) contains files. Now, i... (15 Replies)
Discussion started by: yogeshkumkar
15 Replies

9. Shell Programming and Scripting

Filter only gz files from list of subdirectories

Hi, I have a very big directory structure that consists of many sub-directories inside.There are around 50 ".gz" files under this dir structure. I want to copy all the gz files alone to a seperate location. Plz help me. (2 Replies)
Discussion started by: villain41
2 Replies

10. UNIX for Dummies Questions & Answers

list largest files in a directory & its subdirectories

I need to find the largest files in a directory & it's subdirectories. I'm not sure what options on ls -l will work to give me this. or is there another way to do this? Thanks, igidttam (6 Replies)
Discussion started by: igidttam
6 Replies

Featured Tech Videos