Home>Article>Operation and Maintenance> What is the method of moving and copying folders under Linux?
Copying a folder is the process of copying all the contents of a folder to another location. The following are some basic command options and parameters:
cp [选项] 源目录 目标目录
Among them, thecp
command is used to copy files or folders. You need to provide the source and destination directory addresses and specify the locations of the source and destination folders.
For example, if you want to copy all the contents in the/home/lihuanyu/Data/Mini_imagenet/MyImagenet
directory to/home/lihuanyu/code/06paper1/01model_pretraining/data /
directory, you can use the following command:
cp -r /home/lihuanyu/Data/Mini_imagenet/MyImagenet /home/lihuanyu/code/06paper1/01model_pretraining/data/
In this example, the-r
parameter means recursively copy the entire directory. You can also change this parameter to control how replication behaves.
Moving a folder is the process of moving a folder from one location to another. The following are some basic command options and parameters:
mv [options] source directory target directory
Among them, themv
command is used to move files or folder. You need to provide the source and destination directory addresses and specify the locations of the source and destination folders.
For example, if you want to move the/home/user/project
directory to the/backup/project
directory, you can use the following command:
mv /home/lihuanyu/Data/tiny-imagenet-200 /home/lihuanyu/code/06paper1/01model_pretraining/data/
In this example, themv
command will move the/home/lihuanyu/Data/tiny-imagenet-200
directory to/home/lihuanyu/code/06paper1 /01model_pretraining/data/
directory.
Now let’s see how to use the move and copy operations of folders in actual applications.
Suppose you have an important configuration file stored in the/etc
directory. To back up this file, you can copy the entire directory to the backup directory. The following is an example of copying the/etc
directory to the backup directory/backup/etc
:
cp -r /etc /backup
If you want to move a completed project to another location to free up local disk space, you can use themv
command to Move folders. The following is an example of moving the/home/user/project
directory to the/backup
directory:
mv /home/user/project /backup
When working with larger folders, you may need to archive data to save disk space. The tar command can package multiple files into a single archive. The following is an example of archiving the/home/user/project
directory into the/backup/project.tar.gz
file:
tar -czvf /backup/project.tar.gz /home/user/project
In this example,-c
means creating a new archive file,-z
Indicates using the gzip algorithm to compress files,-v
indicates displaying progress information and outputting it to the terminal,-f
indicates specifying the output archive file name.
The above is the detailed content of What is the method of moving and copying folders under Linux?. For more information, please follow other related articles on the PHP Chinese website!