Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

list of directory in unix

Status
Not open for further replies.

hendnov

Technical User
Feb 27, 2006
73
AU
Hi guys,

probably this is basic question for some of you, but I was just wondering about this.
what command to see the list of directory only, I've tried :
Code:
adoc syducmp02 ~/cobaajaskrg> ls -l
total 4
drwxrwxr-x   2 adoc     adoc         512 Mar 31 15:24 knpdir/
-rwxrwxr-x   1 adoc     adoc           7 Mar 31 15:24 knpfile*

but if I tried :
Code:
adoc syducmp02 ~/cobaajaskrg> ls -d
./

I want the result is :
drwxrwxr-x 2 adoc adoc 512 Mar 31 15:24 knpdir/
 
Thx chipperMDW,

what about if I want to list files only ?

Cheers,

 
The first code snippet I gave prints only the lines that start with a [tt]d[/tt] character; those are the directories.

Regular files are shown on lines that begin with a [tt]-[/tt] (hyphen) character. So to print only the lines that start with a -, you'd do:
Code:
ls -l |grep ^-

Or, using the find method I posted in the other thread:
Code:
find . -maxdepth 1 -type f -print0 |xargs -0 ls
The [tt]f[/tt] argument to [tt]-type[/tt] means regular files.
 
Alrite here's my code

Code:
#!/bin/ksh

cd /opt/adoc/cobaajaskrg
for dir in `ls -l | grep ^d`
do
baru=`echo $dir | sed s/np/Np/`
echo mv ${dir} ${baru}
done

but the result is :
mv drwxrwxr-x drwxrwxr-x
mv 2 2
mv adoc adoc
mv adoc adoc
mv 512 512
mv Mar Mar
mv 31 31
mv 15:24 15:24
mv knpdir kNpdir

which I want is :

mv knpdir kNpdir


Cheers,

 
Also see my reply in your other thread - and don't post repeats, please.

When one door closes another one bangs shut too.
 
Sorry guys, if I'm asking too much. Coz I'm pretty new in unix.

what about finding directory using find command.

Cheers mate,
 
Use

Code:
#!/bin/ksh

cd /opt/adoc/cobaajaskrg
for dir in `ls -l | grep ^d | awk '{print $9}'`
do
baru=`echo $dir | sed s/np/Np/`
echo mv ${dir} ${baru}
done

The print $9 means print column 9; you may have to change to suit you *nix version.

Mike

"A foolproof method for sculpting an elephant: first, get a huge block of marble, then you chip away everything that doesn't look like an elephant."

 
To use find

find /opt/adoc/cobaajaskrg -type d -print > /tmp/dirlist

while read line;
do
echo $line
done < /tmp/dirlist

Mike

"A foolproof method for sculpting an elephant: first, get a huge block of marble, then you chip away everything that doesn't look like an elephant."

 
henguard said:
what about finding directory using find command.
I suppose you could actually read the thread I keep referring you to... thread619-1203128.
 
THX Guys for your inputs,

much appreciated. But I'll use mrn way which is best result.

Thx.. I love this forum :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top