Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Spawn a folder tree!
- My course has 4 blocks of several parts, each containing lessons
- $ mkdir -p Block{1..4}/Pt{1..6}
- $ touch Block{1..4}/Pt{1..6}/{0..1}{0..9}.txt
- First make the directories with mkdir. The -p option means that for a given a folder path it creates the in-between folders if they do not exist.
- The curlies are bracket expansion. The number range inside it is expanded like a counter. AND if two sets of bracket are within the same string (not separated by a space) then they behave like a nested loop, creating 6 'Part' folders in each 4 'Block' folders.
- The blank text files are created with 'touch' (originally intended for modifying permissions), the paths now already exist. The double brackets for the file names give a two character name starting 00.txt, it's like a crude zero-padded counter. If it started on 1 it would only count to 9.
- Included for extra.
- Delete oo.txt in every folder
- $ rm Block{1..4}/Part{1..6}/00.txt
- Delete every file in every folder
- $ rm Block{1..4}/Part{1..6}/*
- Duplicate a file 39 times and number them
- $ for i in {0..3}{0..9}; do cp test.ogg "test$i.ogg"; done
- Append something onto all files in a folder. "*" glob grabs the file names.
- $ for i in *; do echo 'hi there' >> $i; done
Add Comment
Please, Sign In to add comment