Post History
#3: Post edited
- # MWE
- With the following tree:
- ```txt
- l1
- └── l2
- ├── d0
- │ ├── f0
- │ ├── f1
- │ ├── f2
- │ ├── f3
- │ ├── f4
- │ └── f5
- ├── d1
- │ ├── f0
- │ ├── f1
- │ ├── f2
- │ ├── f3
- │ ├── f4
- │ └── f5
- ├── d2
- │ ├── f0
- │ ├── f1
- │ ├── f2
- │ ├── f3
- │ ├── f4
- │ └── f5
- ├── d3
- │ ├── f0
- │ ├── f1
- │ ├── f2
- │ ├── f3
- │ ├── f4
- │ └── f5
- ├── d4
- │ ├── f0
- │ ├── f1
- │ ├── f2
- │ ├── f3
- │ ├── f4
- │ └── f5
- └── d5
- ├── f0
- ├── f1
- ├── f2
- ├── f3
- ├── f4
- └── f5
- 8 directories, 36 files
- ```
- created by this script:
- ```bash
- #!/bin/bash
- path=l1/l2
- mkdir -p $path
- for dir in {0..5}; do
- mkdir $path/d$dir
- for file in {0..5}; do
- touch $path/d$dir/f$file
- done
- done
- ```
- # Problem
- How do I list the first three files of each directory?
- First three being the first three alphabetically sorted.
- # Tried
- I can get each file via:
- ```bash
- find l1 -mindepth 3 -maxdepth 3 -type f
- ```
- but I can't find a way in the manual to specify the match depth.
- The output from find is also unsorted, and so, the first three would not
- be the first three alphabetically.
- # Notes
- My goal is to make a trimmed copy of a large dataset for preliminary,
- quick testing as I develop my code. Performing this trim within the code
- unnecessarily complicates the test code and will be a wasted effort as
- it will be removed for the real deal. Without it in place, I am able to
- test what will be the final product.
- The real target using the real dataset may be sub directories and not
- files. In other words, "give me the the first 3 directories in level 2".
- Ideally, if I can find a way to list the files, I can pipe them to a
- `cp` command.
- # MWE
- With the following tree:
- ```txt
- l1
- └── l2
- ├── d0
- │ ├── f0
- │ ├── f1
- │ ├── f2
- │ ├── f3
- │ ├── f4
- │ └── f5
- ├── d1
- │ ├── f0
- │ ├── f1
- │ ├── f2
- │ ├── f3
- │ ├── f4
- │ └── f5
- ├── d2
- │ ├── f0
- │ ├── f1
- │ ├── f2
- │ ├── f3
- │ ├── f4
- │ └── f5
- ├── d3
- │ ├── f0
- │ ├── f1
- │ ├── f2
- │ ├── f3
- │ ├── f4
- │ └── f5
- ├── d4
- │ ├── f0
- │ ├── f1
- │ ├── f2
- │ ├── f3
- │ ├── f4
- │ └── f5
- └── d5
- ├── f0
- ├── f1
- ├── f2
- ├── f3
- ├── f4
- └── f5
- 8 directories, 36 files
- ```
- created by this script:
- ```bash
- #!/bin/bash
- path=l1/l2
- mkdir -p $path
- for dir in {0..5}; do
- mkdir $path/d$dir
- for file in {0..5}; do
- touch $path/d$dir/f$file
- done
- done
- ```
- # Problem
- How do I list the first three files of each directory?
- First three being the first three alphabetically sorted.
- Desired output:
- ```txt
- l1/l2/d0/f0
- l1/l2/d0/f1
- l1/l2/d0/f2
- l1/l2/d1/f0
- l1/l2/d1/f1
- l1/l2/d1/f2
- l1/l2/d2/f0
- l1/l2/d2/f1
- l1/l2/d2/f2
- l1/l2/d3/f0
- l1/l2/d3/f1
- l1/l2/d3/f2
- l1/l2/d4/f0
- l1/l2/d4/f1
- l1/l2/d4/f2
- l1/l2/d5/f0
- l1/l2/d5/f1
- l1/l2/d5/f2
- ```
- # Tried
- I can get each file via:
- ```bash
- find l1 -mindepth 3 -maxdepth 3 -type f
- ```
- but I can't find a way in the manual to specify the match depth.
- The output from find is also unsorted, and so, the first three would not
- be the first three alphabetically.
- # Notes
- My goal is to make a trimmed copy of a large dataset for preliminary,
- quick testing as I develop my code. Performing this trim within the code
- unnecessarily complicates the test code and will be a wasted effort as
- it will be removed for the real deal. Without it in place, I am able to
- test what will be the final product.
- The real target using the real dataset may be sub directories and not
- files. In other words, "give me the the first 3 directories in level 2".
- Ideally, if I can find a way to list the files, I can pipe them to a
- `cp` command.
#2: Post edited
- # MWE
- With the following tree:
- ```txt
- l1
- └── l2
- ├── d0
- │ ├── f0
- │ ├── f1
- │ ├── f2
- │ ├── f3
- │ ├── f4
- │ └── f5
- ├── d1
- │ ├── f0
- │ ├── f1
- │ ├── f2
- │ ├── f3
- │ ├── f4
- │ └── f5
- ├── d2
- │ ├── f0
- │ ├── f1
- │ ├── f2
- │ ├── f3
- │ ├── f4
- │ └── f5
- ├── d3
- │ ├── f0
- │ ├── f1
- │ ├── f2
- │ ├── f3
- │ ├── f4
- │ └── f5
- ├── d4
- │ ├── f0
- │ ├── f1
- │ ├── f2
- │ ├── f3
- │ ├── f4
- │ └── f5
- └── d5
- ├── f0
- ├── f1
- ├── f2
- ├── f3
- ├── f4
- └── f5
- 8 directories, 36 files
- ```
- created by this script:
- ```bash
- #!/bin/bash
- path=l1/l2
- mkdir -p $path
- for dir in {0..5}; do
- mkdir $path/d$dir
- for file in {0..5}; do
- touch $path/d$dir/f$file
- done
- done
- ```
- # Problem
- How do I list the first three files of each directory?
- First three being the first three alphabetically sorted.
- # Tried
- I can get each file via:
- ```bash
- find l1 -mindepth 3 -maxdepth 3 -type f
- ```
- but I can't find a way in the manual to specify the match depth.
- The output from find is also unsorted, and so, the first three would not
- be the first three alphabetically.
- # Notes
- My goal is to make a trimmed copy of a large dataset for preliminary,
- quick testing as I develop my code. Performing this trim within the code
unneccesarily complicates the test code and will be a wasted effort as- it will be removed for the real deal. Without it in place, I am able to
- test what will be the final product.
- The real target using the real dataset may be sub directories and not
- files. In other words, "give me the the first 3 directories in level 2".
- # MWE
- With the following tree:
- ```txt
- l1
- └── l2
- ├── d0
- │ ├── f0
- │ ├── f1
- │ ├── f2
- │ ├── f3
- │ ├── f4
- │ └── f5
- ├── d1
- │ ├── f0
- │ ├── f1
- │ ├── f2
- │ ├── f3
- │ ├── f4
- │ └── f5
- ├── d2
- │ ├── f0
- │ ├── f1
- │ ├── f2
- │ ├── f3
- │ ├── f4
- │ └── f5
- ├── d3
- │ ├── f0
- │ ├── f1
- │ ├── f2
- │ ├── f3
- │ ├── f4
- │ └── f5
- ├── d4
- │ ├── f0
- │ ├── f1
- │ ├── f2
- │ ├── f3
- │ ├── f4
- │ └── f5
- └── d5
- ├── f0
- ├── f1
- ├── f2
- ├── f3
- ├── f4
- └── f5
- 8 directories, 36 files
- ```
- created by this script:
- ```bash
- #!/bin/bash
- path=l1/l2
- mkdir -p $path
- for dir in {0..5}; do
- mkdir $path/d$dir
- for file in {0..5}; do
- touch $path/d$dir/f$file
- done
- done
- ```
- # Problem
- How do I list the first three files of each directory?
- First three being the first three alphabetically sorted.
- # Tried
- I can get each file via:
- ```bash
- find l1 -mindepth 3 -maxdepth 3 -type f
- ```
- but I can't find a way in the manual to specify the match depth.
- The output from find is also unsorted, and so, the first three would not
- be the first three alphabetically.
- # Notes
- My goal is to make a trimmed copy of a large dataset for preliminary,
- quick testing as I develop my code. Performing this trim within the code
- unnecessarily complicates the test code and will be a wasted effort as
- it will be removed for the real deal. Without it in place, I am able to
- test what will be the final product.
- The real target using the real dataset may be sub directories and not
- files. In other words, "give me the the first 3 directories in level 2".
- Ideally, if I can find a way to list the files, I can pipe them to a
- `cp` command.
#1: Initial revision
How to list the first x files in each directory
# MWE With the following tree: ```txt l1 └── l2 ├── d0 │ ├── f0 │ ├── f1 │ ├── f2 │ ├── f3 │ ├── f4 │ └── f5 ├── d1 │ ├── f0 │ ├── f1 │ ├── f2 │ ├── f3 │ ├── f4 │ └── f5 ├── d2 │ ├── f0 │ ├── f1 │ ├── f2 │ ├── f3 │ ├── f4 │ └── f5 ├── d3 │ ├── f0 │ ├── f1 │ ├── f2 │ ├── f3 │ ├── f4 │ └── f5 ├── d4 │ ├── f0 │ ├── f1 │ ├── f2 │ ├── f3 │ ├── f4 │ └── f5 └── d5 ├── f0 ├── f1 ├── f2 ├── f3 ├── f4 └── f5 8 directories, 36 files ``` created by this script: ```bash #!/bin/bash path=l1/l2 mkdir -p $path for dir in {0..5}; do mkdir $path/d$dir for file in {0..5}; do touch $path/d$dir/f$file done done ``` # Problem How do I list the first three files of each directory? First three being the first three alphabetically sorted. # Tried I can get each file via: ```bash find l1 -mindepth 3 -maxdepth 3 -type f ``` but I can't find a way in the manual to specify the match depth. The output from find is also unsorted, and so, the first three would not be the first three alphabetically. # Notes My goal is to make a trimmed copy of a large dataset for preliminary, quick testing as I develop my code. Performing this trim within the code unneccesarily complicates the test code and will be a wasted effort as it will be removed for the real deal. Without it in place, I am able to test what will be the final product. The real target using the real dataset may be sub directories and not files. In other words, "give me the the first 3 directories in level 2".