Create Delete Copy And Move Files And Directories
General Information
Basic file/directory manipulation.
Creating
Create new file “file1”
touch file1
Create three files
touch {file1,file2,file3}
Create new directory
mkdir dir1
Create new directory tree
mkdir -p newdir/dir1/dir2/dir3
- Creates newdir, dir1, dir2, and dir3 in that structure
- -p ⇒ Make parent directories if needed
View directory structure in tree outline
~$ tree
.
├── anaconda-ks.cfg
├── file1
├── newdir
│ └── dir1
│ └── dir2
│ └── dir3
├── newfile
├── otherdir
Renaming
Rename file or directory
mv dir1 newdir
- Renames “dir1” to “newdir”
Removing
Remove empty directory
rmdir dir1
Remove directory recursively
rm -rf dir1
- -r ⇒ recursively
- -f ⇒ force, do not prompt for confirmation
Copying
Copy file2 into dir2
cp file2 dir2/
Copy directory dir2 and its contents into newdir
cp -r dir2 /home/newdir/
- -r ⇒ recursively
Moving
Move file1 into dir1
mv file1 dir1/