File and Directory Management
Creating a File
Section titled “Creating a File”touch
creates an empty file.
If the file already exists, it updates its modification timestamp.
touch file.txt
Creating a Directory
Section titled “Creating a Directory”mkdir projectmkdir -p folder1/folder2/folder3
Deleting a File or Directory
Section titled “Deleting a File or Directory”rm file.txt
→ delete a filerm -r folder
→ delete a directory and its contentsrm -rf folder
→ force delete without confirmation ⚠️
Copying a File or Directory
Section titled “Copying a File or Directory”cp file.txt copy.txtcp -r folder1 folder2
Moving or Renaming a File
Section titled “Moving or Renaming a File”mv file.txt newname.txtmv file.txt Documents/
Command Summary
Section titled “Command Summary”Command | Description | Example |
---|---|---|
touch | Create an empty file | touch file.txt |
mkdir | Create a directory | mkdir project |
mkdir -p | Create nested directories | mkdir -p a/b/c |
rm | Delete a file | rm file.txt |
rm -r | Delete a directory | rm -r project |
cp | Copy a file | cp file.txt copy.txt |
cp -r | Copy a directory | cp -r folder1 folder2 |
mv | Move or rename a file | mv file.txt newname.txt |
Best Practices
Section titled “Best Practices”- Verify your location with
pwd
before runningrm -r
. - Use
rm -i
to prompt for confirmation. - Prefer
mkdir -p
to avoid errors. - Check results with
ls
.