linux_wiki:create_delete_copy_and_move_files_and_directories

Create Delete Copy And Move Files And Directories

General Information

Basic file/directory manipulation.


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

Rename file or directory

mv dir1 newdir
  • Renames “dir1” to “newdir”

Remove empty directory

rmdir dir1


Remove directory recursively

rm -rf dir1
  • -r ⇒ recursively
  • -f ⇒ force, do not prompt for confirmation

Copy file2 into dir2

cp file2 dir2/


Copy directory dir2 and its contents into newdir

cp -r dir2 /home/newdir/
  • -r ⇒ recursively

Move file1 into dir1

mv file1 dir1/

  • linux_wiki/create_delete_copy_and_move_files_and_directories.txt
  • Last modified: 2019/05/25 23:50
  • (external edit)