[Linux] Basic Instructions (1)

Linux is a common operating system, and all operations under Linux are performed under the command line terminal.
The command format is:Command name [Operation option] [Operation object ]
The command name and the operation option are connected with the operation object by a space , [] is optional.

The directories under Linux can be roughly divided into five categories:

  • Directory related commands
  • File related commands
  • Compress and decompress commands
  • Match find command
  • Other commands

In this blog, I will briefly introduce you to the directory-related commands and their usage.

1. Directory related commands

ls instruction: Browse the contents of the directory (folder), and browse the current directory by default.
Syntax: ls [options] [directory or file]
common options:

  • ls -a: View all files, including hidden files.
  • ls -l: View the detailed information of the file.
  • ls -d: Display the directory as a file instead of displaying the files under it.
  • ls -i: The index information of the i node of the output file.
  • ls -k: Express the size of the file in k bytes.
  • ls-n: Use numeric UID, GID instead of name.
  • ls -F: Attach a character to each file name to indicate the type of the file, "*" means executable ordinary file; "/" means directory; "@" means symbolic link; "|" means FIFOs; "=" means sockets. (Catalog type recognition)
  • ls -r: Reverse sorting of directories.
  • ls -t: Sort by time.
  • ls -s: output the size of the file after l file name. (Sorted by size, how to find large files in a directory)
  • ls -R: List files in all subdirectories. (Recursive)
  • ls -1: Only output one file per line.

pwd command: Display the path of the current directory.
Syntax: pwd

cd command: Change the working directory, change the current working directory to the specified directory.
Syntax: cd directory name
Example: cd ~ //return home directory
cd-//return to the most recently visited directory

mkdir instruction:Create a directory.
Syntax: mkdir [option] [file name]
Example: mkdir -p: Recursively create a directory at multiple levels, from the outside to the inside, which level does not exist.
mkdir ./tmp/abc: Create abc files in the tmp folder.

rmdir instruction && rm instruction: Rmdir deletes directories, rm deletes files.
Syntax: rmdir [option] [file name]
Syntax: rm [option] [file name]
Common options:

  • rmdir: delete empty directories.
  • rmdir -p: Recursively delete directories at multiple levels. From the outside to the inside, delete which level is empty.
  • rm -r: Recursively delete all files in the directory, and finally delete the directory.
  • rm -ir: Prompt whether you really want to delete the file, if so, delete all files in the directory recursively, and finally delete the directory.
  • rm -f: Even if the file attribute is read-only (that is, write-protected), delete it directly.

cp instruction: Copy a file to another location.
Syntax: cp [option] source file or directory target file or directory
description: cp instruction is used to copy files or directories, if two or more files or directories are specified at the same time, and the destination is an existing directory, it All files or directories specified earlier will be copied to this directory. If multiple files or directories are specified at the same time, and the destination is not an existing directory, an error message will appear.
Common options

  • cp -r: Recursively copy a directory and its internal files to the specified location. (Copy the entire folder)
  • cp -f: Forcibly copy files or directories, regardless of whether the destination file or directory already exists.
  • cp -i: Ask the user before overwriting the file.
  • cp -R: Recursive processing, processing the files and subdirectories in the specified directory together.

Example:

cp -r tmp/workspace/danggui: Copy tmp to workspace and rename it to danggui.

mv instruction: Used to move files or rename files, often used to back up files or directories.
Syntax: mv [options] source file or directory target file or directory
Common options:

  • mv -f: force means mandatory. If the target file already exists, it will be overwritten without asking.
  • mv -i: If the target file already exists, it will ask whether to overwrite it.

Example:

mv workspace /tmp/ ./test: Move the workspace to tmp and rename it to test.

mv ./test/ ./tmp: Move test in the current directory to tmp in the current directory (tmp does not exist), and rename the file .

Guess you like

Origin blog.csdn.net/weixin_45177279/article/details/109170164