Hostxpeed
Login Get Started →
Getting Started

How to Copy and Move Files

5 min read
25 views
Jun 13, 2026

Prerequisites

Before copying or moving files, make sure you have:

  • SSH access to your VPS
  • Read permissions for source files
  • Write permissions for destination directory

Copy Files (cp Command)

Connect to your VPS:

ssh hxroot@YOUR_SERVER_IP -p 22

Basic Copy

cp source.txt destination.txt

Copy to Directory

cp file.txt /path/to/directory/

Copy Multiple Files to Directory

cp file1.txt file2.txt file3.txt /target/directory/

Copy Directory Recursively

cp -r source_folder/ destination_folder/

Copy with Preservation (Permissions, Timestamps)

cp -p file.txt destination.txt

Copy with Archive Mode (Preserves Everything)

cp -a source_folder/ destination_folder/

Interactive Copy (Ask Before Overwrite)

cp -i file.txt destination.txt

Verbose Copy (Show What's Being Copied)

cp -v file.txt destination.txt

Force Copy (Overwrite Without Asking)

cp -f file.txt destination.txt

Copy with Backup of Existing Files

cp --backup file.txt destination.txt

Move/Rename Files (mv Command)

Rename File

mv oldname.txt newname.txt

Move File to Directory

mv file.txt /target/directory/

Move Multiple Files to Directory

mv file1.txt file2.txt file3.txt /target/directory/

Move Directory

mv source_folder/ /target/directory/

Interactive Move (Ask Before Overwrite)

mv -i file.txt destination.txt

Verbose Move

mv -v file.txt destination.txt

Force Move (Overwrite Without Asking)

mv -f file.txt destination.txt

Move Without Overwriting Existing Files

mv -n file.txt destination.txt

Practical Examples

Backup a file before editing:

cp config.conf config.conf.backup

Move all log files to archive:

mv /var/log/*.log /var/log/archive/

Copy website files to new location:

cp -r /var/www/oldsite/ /var/www/newsite/

Rename with timestamp:

mv access.log "access_$(date +%Y%m%d).log"

Preserve File Attributes

Preserve timestamps, ownership, permissions:

cp -p file.txt destination.txt

Preserve all attributes including SELinux context:

cp -a source/ destination/

Copy Between Different Users

Copy file as different user:

sudo cp /root/private.txt /home/user/

Move file and change ownership:

sudo mv /root/private.txt /home/user/
sudo chown user:user /home/user/private.txt

Advanced cp Options

  • -u - Copy only when source is newer than destination
  • -l - Create hard links instead of copying
  • -s - Create symbolic links instead of copying
  • -n - Do not overwrite existing files

Copy only newer files:

cp -u source.txt destination.txt

Script for Safe Copy

#!/bin/bash
SOURCE="$1"
DEST="$2"
if [ ! -e "$SOURCE" ]; then
    echo "Error: Source does not exist"
    exit 1
fi
if [ -e "$DEST" ]; then
    echo "Destination exists. Overwrite? (y/n)"
    read answer
    if [ "$answer" != "y" ]; then
        echo "Copy cancelled"
        exit 0
    fi
fi
cp "$SOURCE" "$DEST"
echo "Copy complete"

Bulk Rename with mv

Add prefix to all .txt files:

for file in *.txt; do mv "$file" "prefix_$file"; done

Change extension from .htm to .html:

for file in *.htm; do mv "$file" "${file%.htm}.html"; done

Convert filenames to lowercase:

for file in *; do mv "$file" "$(echo $file | tr '[:upper:]' '[:lower:]')"; done

✅ You can now copy and move files and directories on your Hostxpeed VPS.

Was this article helpful?