Linux Basics Common Linux commands

Source: Internet
Author: User
Tags parent directory

Common Linux commands: CD, CP, LS, MV, RM

CD command : Switch the current working directory to dirName (directory parameter)

Where dirName can be either an absolute path or a relative path. If the directory name is omitted, it is transformed to the user's home directory (that is, the directory where login was first).

In addition, "~" is also indicated as the home directory meaning, "." is the current directory, "." Represents the current directory location of the previous level of the directory.

CD [DirName]

Parameters:

    • DirName: The target directory to switch to.

Instance:

Jump to/usr/bin/:

Cd/usr/bin

Jump to your home directory:

CD ~

Jump to the top two of the current directory:

Cd.. /..

CP command : Copy files or directories

CP [Options] Source Dest

Parameter description:

    • -A: This option is typically used when replicating a directory, preserving links, file attributes, and copying everything under the directory. Its function equals the DPR parameter combination.
    • -D: Keep the link when copying. The link here is equivalent to a shortcut in a Windows system.
    • -F: Overwrite the existing target file without prompting.
    • -I: In contrast to the-f option, a prompt is given before overwriting the target file, asking the user to confirm whether to overwrite, and the target file will be overwritten when the "Y" is answered.
    • -P: In addition to copying the contents of the file, the modification time and access rights are also copied to the new file.
    • -R: If the given source file is a directory file, all subdirectories and files under that directory will be copied.
    • -L: Do not copy files, just generate linked files

Instance:

Using the instruction "CP" to copy all files under current directory "test/" to the new directory "Newtest", enter the following command:

Cp–r Test/newtest

ls command : Lists the files and subdirectories contained in the current working directory

LS [-ALRTAFR] [name]

Parameters:

    • -a displays all files and directories (LS default starts the filename or directory name as ".") As hidden files, not listed)
    • -L In addition to the file name, also the file type, permissions, owner, file size and other information detailed list
    • -r Displays the file in reverse order (originally alphabetical order)
    • -T lists the files in the order of establishment time
    • -A with-a, but not listed "." (current directory) and ".." (Parent directory)
    • -F adds a symbol after the listed file name, for example, the executable file adds "*" and the Directory adds "/".
    • -R If there are documents under the catalogue, the following documents are also listed

Instance:

List all directories under the root directory (/):

LS/

List all directories and file details below the/bin directory:

Ls-lr/bin

mkdir Command : Create a folder

mkdir [-P] DirName

Parameter description:

    • -p Ensure that the directory name exists and that it does not exist.

Instance:

Under working directory, create a subdirectory named Taotao:

mkdir Taotao

In the Taotao directory under the working directory, create a subdirectory named data. If the Taotao directory does not already exist, create one. (Note: If this example does not add-p and the original Taotao directory does not exist, an error is generated.) )

Mkdir-p Taotao/data

MV Command : Used to rename a file or directory, or to move a file or directory into another location

MV [options] source DESTMV [options] Source directory

Parameter description:

    • -I: If the specified directory already has the same name file, first ask whether to overwrite the old file;
    • -F: Do not give any indication when the MV operation is to overwrite an existing target file;

MV parameter setting and running result

Command format Run results
MV FileName File name Change source file to target file name
MV FileName Directory Name To move a file to the destination directory
MV Directory name Directory name

The destination directory already exists and the source directory is moved to the target directory;

Rename if destination directory does not exist

MV Directory name File name Error

Instance:

Rename the file Taotao.txt to Wulitaotao.txt:

MV Taotao.txt Wulitaotao.txt

Put the info directory in the logs directory. Note that if the logs directory does not exist, the command renames info to logs.

MV Info/logs

If you move all files and directories under/usr/student to the current directory, the command behavior:

mv/usr/student/*  .

RM Command : Delete a file or directory

RM [Options] Name

Parameters:

    • -I ask for confirmation before deleting.
    • -F Even if the original file attribute is set to read-only, it is deleted directly without confirmation.
    • -R the directory and the following files are also deleted.

Instance:

Delete files can be directly using the RM command, if you delete the directory you must match the option "-r", for example:

# RM   " Test.txt "? y   # RM  Homework  RM: Unable to delete directory "homework": is a  directory # RM  -  R  Homework"homework"

Delete all files and directories under the current directory, command behavior:

RM-  R  

References

Beginner's Tutorial: Linux commands Daquan

Linux Basics Common Linux commands

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.