


How to use Linux commands to move/copy files/directories to a specified directory
Linux commands to move/copy files/directories to the specified directory
1. Copy files or folders under the same server
1.1 Copy files
Copy files: Copy 1.txt to the sbin directory under the root directory
cp +文件名(可带路径)+目标路径(带路径) 如:cp 1.txt ~/sbin/
1,2 Copy directory
Copy directory: Copy release to the root directory Under the nfs directory under the directory
(1). [cp] [-r] [Directory name (can have path)] [Target path (with path)] -r means copying all subdirectories under the directory and File
如:cp -r release ~/nfs/
(2).[cp] [Directory name/*] [Target path (with path)] /* indicates all files and directories in the directory * is a wildcard character
如: cp release/* ~/nfs/
2. Copy files or folders across servers
scp is the abbreviation of secure copy, which is a command used to remotely copy files under Linux. A similar command is cp, but cp only copies locally and cannot cross servers, and scp transmission is encrypted.
When your server hard disk becomes a read-only system, use scp to help you move the files out.
2.1 Command format
scp [参数] [原路径] [目标路径]
2.2 Instructions
Copy from local server to remote server
2.2.1 Copy files:
$scp local_file remote_username@remote_ip:remote_folder $scp local_file remote_username@remote_ip:remote_file $scp local_file remote_ip:remote_folder $scp local_file remote_ip:remote_file
If the user name is specified, the user password needs to be entered after the command is executed;
If the user name is not specified, After the command is executed, you need to enter the user name and password;
2.2.2 Copy directory:
$scp -r local_folder remote_username@remote_ip:remote_folder $scp -r local_folder remote_ip:remote_folder
The first one specifies the user name, and the command is executed After that, you need to enter the user password;
The second one does not specify a user name, and you need to enter the user name and password after the command is executed;
3. Usage examples
3.1. Example 1: Copy files from the server to the local directory
$scp root@10.6.159.147:/opt/soft/demo.tar /opt/soft/
Instructions: From /opt/soft/ on the 10.6.159.147 machine Download the demo.tar file from the directory to the local /opt/soft/ directory
3.2. Example 2: Copy the folder from the server to the local
$scp -r root@10.6.159.147:/opt/soft/test /opt/soft/
Instructions: From the 10.6.159.147 machine Download the test directory from /opt/soft/ to the local /opt/soft/ directory.
3.3. Example 3: Upload local files to the specified directory on the remote server
$scp /opt/soft/demo.tar root@10.6.159.147:/opt/soft/scptest
Instructions: Copy the file demo.tar in the local opt/soft/ directory to the opt/ of the remote machine 10.6.159.147 soft/scptest directory
3.4, Example 4: Upload the local directory to the specified directory on the remote machine
$scp -r /opt/soft/test root@10.6.159.147:/opt/soft/scptest
Instructions: Upload the local directory/opt/soft/test to the remote machine 10.6.159.147/opt /soft/scptest directory
4. Move the folder to another folder
mv 文件名 目标文件夹路径
Set Linux command alias
In When operating Linux, you may encounter some very long commands. This command is used frequently, and it will be very troublesome every time you enter it and execute it. It is convenient if you set a long command to a short alias.
Linux’s alias command can help us set aliases for long commands.
List of alias commands on the server
Execute the alias command on the Linux server and you will see several familiar commands. As follows.
[test@271ba307f4954c74955b28c8389bc648 ~]$ alias alias egrep='egrep --color=auto' alias fgrep='fgrep --color=auto' alias grep='grep --color=auto' alias l.='ls -d .* --color=auto' alias ll='ls -l --color=auto' alias ls='ls --color=auto' alias vi='vim' alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
For example: the ll command is not a Linux command, ll is executed by setting an alias ls -l --color=auto.
alias Add alias
2.1 alias Add alias syntax
alias The syntax for adding alias is: alias [alias]='real command'.
2.2 alias Steps to add an alias
As shown below, add the command alias svccdl to the current Linux user test in order to enter the log file path of the day. The steps are as follows.
Enter the current user's home path, execute vi .bashrc, and add the following line of text:
alias svccdl='cd /home/test/logs/`date +%Y-%m-%d`'
The edited .bashrc file content is as follows.
# .bashrc # Source global definitions if [ -f /etc/bashrc ]; then . /etc/bashrc fi alias svccdl='cd /home/test/logs/`date +%Y-%m-%d`' # Uncomment the following line if you don't like systemctl's auto-paging feature: # export SYSTEMD_PAGER= # User specific aliases and functions
Execute source .bashrc to make the alias permanent.
[test@271ba307f4954c74955b28c8389bc648 ~]$ source .bashrc
Use test
[test@271ba307f4954c74955b28c8389bc648 ~]$ svccdl [test@271ba307f4954c74955b28c8389bc648 2022-08-30]$ pwd /home/test/logs/2022-08-30
The above is the detailed content of How to use Linux commands to move/copy files/directories to a specified directory. For more information, please follow other related articles on the PHP Chinese website!

The key steps in Linux system management and maintenance include: 1) Master the basic knowledge, such as file system structure and user management; 2) Carry out system monitoring and resource management, use top, htop and other tools; 3) Use system logs to troubleshoot, use journalctl and other tools; 4) Write automated scripts and task scheduling, use cron tools; 5) implement security management and protection, configure firewalls through iptables; 6) Carry out performance optimization and best practices, adjust kernel parameters and develop good habits.

Linux maintenance mode is entered by adding init=/bin/bash or single parameters at startup. 1. Enter maintenance mode: Edit the GRUB menu and add startup parameters. 2. Remount the file system to read and write mode: mount-oremount,rw/. 3. Repair the file system: Use the fsck command, such as fsck/dev/sda1. 4. Back up the data and operate with caution to avoid data loss.

This article discusses how to improve Hadoop data processing efficiency on Debian systems. Optimization strategies cover hardware upgrades, operating system parameter adjustments, Hadoop configuration modifications, and the use of efficient algorithms and tools. 1. Hardware resource strengthening ensures that all nodes have consistent hardware configurations, especially paying attention to CPU, memory and network equipment performance. Choosing high-performance hardware components is essential to improve overall processing speed. 2. Operating system tunes file descriptors and network connections: Modify the /etc/security/limits.conf file to increase the upper limit of file descriptors and network connections allowed to be opened at the same time by the system. JVM parameter adjustment: Adjust in hadoop-env.sh file

This guide will guide you to learn how to use Syslog in Debian systems. Syslog is a key service in Linux systems for logging system and application log messages. It helps administrators monitor and analyze system activity to quickly identify and resolve problems. 1. Basic knowledge of Syslog The core functions of Syslog include: centrally collecting and managing log messages; supporting multiple log output formats and target locations (such as files or networks); providing real-time log viewing and filtering functions. 2. Install and configure Syslog (using Rsyslog) The Debian system uses Rsyslog by default. You can install it with the following command: sudoaptupdatesud

When choosing a Hadoop version suitable for Debian system, the following key factors need to be considered: 1. Stability and long-term support: For users who pursue stability and security, it is recommended to choose a Debian stable version, such as Debian11 (Bullseye). This version has been fully tested and has a support cycle of up to five years, which can ensure the stable operation of the system. 2. Package update speed: If you need to use the latest Hadoop features and features, you can consider Debian's unstable version (Sid). However, it should be noted that unstable versions may have compatibility issues and stability risks. 3. Community support and resources: Debian has huge community support, which can provide rich documentation and

This article describes how to use TigerVNC to share files on Debian systems. You need to install the TigerVNC server first and then configure it. 1. Install the TigerVNC server and open the terminal. Update the software package list: sudoaptupdate to install TigerVNC server: sudoaptinstalltigervnc-standalone-servertigervnc-common 2. Configure TigerVNC server to set VNC server password: vncpasswd Start VNC server: vncserver:1-localhostno

Configuring a Debian mail server's firewall is an important step in ensuring server security. The following are several commonly used firewall configuration methods, including the use of iptables and firewalld. Use iptables to configure firewall to install iptables (if not already installed): sudoapt-getupdatesudoapt-getinstalliptablesView current iptables rules: sudoiptables-L configuration

The steps to install an SSL certificate on the Debian mail server are as follows: 1. Install the OpenSSL toolkit First, make sure that the OpenSSL toolkit is already installed on your system. If not installed, you can use the following command to install: sudoapt-getupdatesudoapt-getinstallopenssl2. Generate private key and certificate request Next, use OpenSSL to generate a 2048-bit RSA private key and a certificate request (CSR): openss


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 English version
Recommended: Win version, supports code prompts!

WebStorm Mac version
Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Zend Studio 13.0.1
Powerful PHP integrated development environment