Working with files
How do I make files and folders?
Section titled “How do I make files and folders?”mkdir projects # make a foldermkdir -p projects/a/b/c # make a whole chain of folders at oncetouch notes.txt # make an empty filetouch updates a file’s date, and if the file doesn’t exist, it creates an empty one (this is a very popular use).
How do I see what’s in a file?
Section titled “How do I see what’s in a file?”cat notes.txt # print the whole fileless notes.txt # scroll through a long file (q to quit)head notes.txt # first 10 linestail notes.txt # last 10 linesHow do I copy and move files?
Section titled “How do I copy and move files?”cp notes.txt backup.txt # copy a filecp -r projects projects-backup # copy a folder (-r means "and everything inside")mv notes.txt Documents/ # move a file into a foldermv backup.txt old-notes.txt # rename a fileThere’s no separate rename command. Renaming is just moving a file to a new name in the same place.
How do I delete files?
Section titled “How do I delete files?”rm old-notes.txt # delete a filermdir empty-folder # delete an empty folderrm -r projects-backup # delete a folder and everything in itWildcards
Section titled “Wildcards”* matches any text. The shell replaces it with every matching file name before running the command:
ls *.png # every file ending in .pngcp *.jpg backup/ # copy every .jpg into backup/This is called a glob.
Quick check: what does mv *.txt notes/ do?
It moves every file ending in .txt (in the folder you’re in) into the notes folder.