Files and Folders
Everything in Linux is a file in one big tree starting at /. Moving around, creating, copying, moving and deleting files are the most common terminal tasks, and they work the same on every Linux server and on Mac.
Moving around
Example
$ pwd
/home/asha
$ mkdir shop
$ cd shop
$ pwd
/home/asha/shop
$ mkdir -p src/images logs
$ ls
logs
src
$ cd ..
$ pwd
/home/ashacd folder- go into a folder;cd ..- up one level;cd ~or justcd- your home foldermkdir -p a/b/c- make folders, including the ones in betweenls- list;ls -aalso shows hidden files (names starting with a dot);ls -lshows details
Making, copying, moving, deleting
Example
$ mkdir notes
$ cd notes
$ touch todo.txt
$ echo "buy stock" > todo.txt
$ cp todo.txt todo-backup.txt
$ mv todo-backup.txt old.txt
$ ls
old.txt
todo.txt
$ rm old.txt
$ ls
todo.txttouch file- create an empty filecp a b- copy;cp -r folder copy- copy a whole foldermv a b- move or renamerm file- delete;rm -r folder- delete a folder and everything in it
Careful:
rm doesn't use a recycle bin - deleted is gone. Double-check before rm -r, and never run a command like rm -rf / that you've seen online without understanding it.Paths
- Absolute path starts from the top:
/home/asha/shop/logs - Relative path starts from where you are:
shop/logs,../notes ~means your home folder;.means "here"
Key points
- pwd, ls and cd move around.
- mkdir, touch, cp, mv and rm manage files.
- rm deletes permanently - be careful.
📝 Test yourself
1. Which command goes up one folder?
2. What does mv old.txt new.txt do?
3. Fill in the option that also creates the folders in between:
mkdir a/b/c
