Don't have tree, need advise to differentiate dir from file from this alternative that uses find


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Don't have tree, need advise to differentiate dir from file from this alternative that uses find
# 1  
Old 02-05-2019
Don't have tree, need advise to differentiate dir from file from this alternative that uses find

Hi,

I don't have tree on the Solaris server and our SA don't want to install it. I found this example from One Line Linux Command to Print Out Directory Tree Listing | systemBash that more or less does what I am mainly looking for.

Example run is as below:

Code:
$: find ./ | sed -e 's/[^-][^\/]*\//--/g;s/--/ |-/'
 |-
 |-files
 |---lib
 |-----libserver12.a
 |-------qksvc.o
 |-etc
 |---config
 |-----actions.xml
 |-----inventory.xml
 |-README.txt
$: ls -ld *
-rwxr-xr-x   1 oracle   dba         6078 Mar 15  2017 README.txt
drwxr-xr-x   3 oracle   dba         4096 Mar 15  2017 etc
drwxr-xr-x   3 oracle   dba         4096 Mar 15  2017 files
$: ls -ld files/*
drwxr-xr-x   3 oracle   dba         4096 Mar 15  2017 files/lib
$: ls -ld files/lib/*
drwxr-xr-x   2 oracle   dba         4096 Mar 15  2017 files/lib/libserver12.a
$: ls -ld files/lib/libserver12.a/*
-rwxr-xr-x   1 oracle   dba       164056 Mar 15  2017 files/lib/libserver12.a/qksvc.o

I want to know if it is possible to change the same one liner so that the output is able to differentiate between a directory to a file. Maybe for example if it is a directory, it displays a * or [DIR] at the end of it.

Please advise. Thanks.
# 2  
Old 02-05-2019
Just do find -type f and you'll know that every top-level name you find is a file and everything beneath must be a folder, i.e. /path/to/filename
These 2 Users Gave Thanks to Corona688 For This Post:
# 3  
Old 02-05-2019
The following versions are closer to the original and help to see the directories better:
Code:
find . | sed 's#[^/]*/#|  #g; s#^\([| ]*|\)  #\1--#'

Code:
find . | sed 's#[^/]*/#|  #g; s#^\([| ]*\)|  #\1+--#'


Last edited by MadeInGermany; 02-05-2019 at 03:22 PM..
These 2 Users Gave Thanks to MadeInGermany For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Tips/advise on alternative to doing egrep -v

Hi all, At the moment, I am doing the following to exclude some exception strings. The more I need to exclude, the longer the string becomes and it has become error prone as I edit the list manually. $ cat output.txt host=192.168.1.99 user=mickey host=192.168.1.99 user=mickey... (4 Replies)
Discussion started by: newbie_01
4 Replies

2. Shell Programming and Scripting

KSH - Find paths of multiple files in CC (dir and sub-dir))

Dear Members, I have a list of xml files like abc.xml.table prq.xml.table ... .. . in a txt file. Now I have to search the file(s) in all directories and sub-directories and print the full path of file in a output txt file. Please help me with the script or command to do so. ... (11 Replies)
Discussion started by: Yoodit
11 Replies

3. UNIX for Advanced & Expert Users

Don't find file from foxbase 2.1.2d

Hi there, finally i'm installed Sco Foxbase 2.1.2d over my Sco Open Server 5.0.7v server. Well at this point almost is working fine, but, when i Run mi application i receive the next error: "sh: the_name_of_file": does not exist". I checked it over the Hard Disk and the file exist, the... (1 Reply)
Discussion started by: danilosevilla
1 Replies

4. Shell Programming and Scripting

Find zero byte file but don't need path

Just i want to ask How to search and display name of zero byte file I have used find command but it is showing complete file path Thanks find . -size 0 giving me zero byte file with location 1)/home/user/a (4 Replies)
Discussion started by: vivek1489
4 Replies

5. Shell Programming and Scripting

A script to find dir, delete files in, and then del dir?

Hello!! I have directories from 2008, with files in them. I want to create a script that will find the directoried from 2008 (example directory: drwxr-xr-x 2 isplan users 1024 Nov 21 2008 FILES_112108), delete the files within those directories and then delete the directories... (3 Replies)
Discussion started by: bigben1220
3 Replies

6. Shell Programming and Scripting

Find Oldest file in a directory tree

This might just be one command. Any1 having the solution? Thanks, Rahul. (25 Replies)
Discussion started by: rahulrathod
25 Replies

7. UNIX for Dummies Questions & Answers

Will i see a file/dir I don't have read access to

Hi all, if I have a dir with a mixture of files and directories in it and one of the directories *only* has read permission for the owner and I am not the owner - will I see it with an 'ls -la'. I do not have access to a unix box at present to try this out. Any thoughts gratefully received (1 Reply)
Discussion started by: ajcannon
1 Replies

8. UNIX for Dummies Questions & Answers

Move A File With Same Date,don't Change The Desitination Dir Date

Assume, I created one file three years back and I like to move the file to some other directory with the old date (Creation date)? Is it possible? Explain? (1 Reply)
Discussion started by: jee.ku2
1 Replies

9. UNIX for Dummies Questions & Answers

how to differentiate a file from a folder in a FIND?

I have to read a complete folder and if it is a file older that 7 days I have to copy it elsewhere and if it is a folder nothing to make. The way I do it: for I in `find /home/. -name "*" -mtime +7` do cp -Rf $I /home/elsewhere/. done Am I okay with the way I want to do it? Help... (3 Replies)
Discussion started by: denysQC
3 Replies

10. Shell Programming and Scripting

a script to clone a dir tree, & overwrite the dir struct elsewhere?

hi all, i'm looking for a bash or tcsh script that will clone an empty dir tree 'over' another tree ... specifically, i'd like to: (1) specify a src directory (2) list the directory tree/hiearchy beneath that src dir, w/o files -- just the dirs (3) clone that same, empty dir hierarchy to... (2 Replies)
Discussion started by: OpenMacNews
2 Replies
Login or Register to Ask a Question