Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ls all files in directory plus all files in directories one level down

Ok I have the following situation.

Caps are directories, lowercase are files.

A/aa
B/bb
C/cc
D/dd
D/E/ddd
D/F/G/dddd
a
b
c
d

I want to do a ls that lists

a
b
c
d
A/aa
B/bb
C/cc
D/dd

but not either

D/E/ddd
D/F/G/dddd
like image 987
MrBrightside Avatar asked Dec 21 '22 12:12

MrBrightside


2 Answers

Using find to find only files in the current directory or one directory down:

$ find . -maxdepth 2  -type f

Demo:

# Show whole directory structure, digits are files, letters are folders. 
$  find .
.
./1
./2
./3
./4
./A
./A/11
./B
./B/22
./C
./C/33
./D
./D/44
./D/E
./D/F
./D/F/444
./D/F/G
./D/F/G/4444

# Find only files at a maximum depth of 2
$  find . -maxdepth 2  -type f
./1
./2
./3
./4
./A/11
./B/22
./C/33
./D/44
like image 121
Chris Seymour Avatar answered Jan 13 '23 19:01

Chris Seymour


This one lists everything inside directories in your current working dir: ls -l */

A combination of two commands will include files in your current directory as well: ls -l */; ls -l

like image 35
Jarmund Avatar answered Jan 13 '23 19:01

Jarmund