Folder tree

Feb 16th, 2019
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. Spawn a folder tree!
  2. My course has 4 blocks of several parts, each containing lessons
  4. $ mkdir -p Block{1..4}/Pt{1..6}
  5. $ touch Block{1..4}/Pt{1..6}/{0..1}{0..9}.txt
  7. 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.
  8. 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.
  9. 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.
  11. Included for extra.
  12. Delete oo.txt in every folder
  13. $ rm Block{1..4}/Part{1..6}/00.txt
  14. Delete every file in every folder
  15. $ rm Block{1..4}/Part{1..6}/*
  16. Duplicate a file 39 times and number them
  17. $ for i in {0..3}{0..9}; do cp test.ogg "test$i.ogg"; done
  18. Append something onto all files in a folder. "*" glob grabs the file names.
  19. $ for i in *; do echo 'hi there' >> $i; done
Add Comment
Please, Sign In to add comment