[Linux] Practical Instructions: Instructions for File Directory Classes

pwd, ls, cd: current path, display file or directory information, switch directories

pwd instruction

pwd: Display the absolute path of the current job

ls command

ls [选项][目录或文件]

Commonly used:

lsls -lls -al

Common options:

​:-a Displays files and directories indexed by the current directory, including hidden ones.

​:-l Display information in a list

cd command

cd [参数: switch to the specified directory

Common parameters

​ Absolute and relative paths

cd ~Or cd: go back to your home directory

cd ..: go back to the previous directory of the current directory

Example:

  • The /root directory enters the /home directory

    • Absolute path: cd /home. That is, starting from the root directory/
    • Relative path: cd ../home. That is, navigate from the current working directory to the desired directory
  • Use a relative path to enter the /root directory. Supposed to be in /user/lib

    • Query the current directory:pwd

    • cd ../../root

mkdir, rmdir, touch: create and delete directories, create empty files

mkdir

mkdirCreate a directory (make directory)

mkdir [选项] 要创建的目录

Common options:

-p: create a multi-level directory

Example:

mkdir /home/dog: Create a dog directory under home

mkdir -p /home/animal/tiger: create a multi-level directory

rmdir

rmdir:delete空目录

rmdir [选项] 要删除的空目录

Note: If there is content in the deleted directory, it cannot be deleted. Need to userm -rf

touch

touch: create empty file

touch 文件名称

Note: It is also ok to create multiple files at one time. For example:touch t1.txt t2.txt

cp, rm, mv: basic operations copy and paste removal

cp

cp:copy file to specified directory

cp [选项] source dest: source:copy source file dest:copy to destination file

Options:

​:-r recursively copy the entire folder

Example:

  • Copy /home/aaa.txt to the /home/bbb directory [copy a single file]
    • cp aaa.txt bbb/orcp aaa.txt ./bbb
  • Copy the entire folder recursively: copy the entire directory of /home/test to /home/zwj
    • cp -r test/ zwj/orcp -r ./test ./zwj
    • Be sure to pay attention to the current directory location, and then accurately locate the source directory and target directory

Note: Forcibly overwrite methods that do not prompt: \cp

Example: \cp -r test/ zwj/And cp -r test/ zwj/if there is a file to be pasted in the target directory, it will remind whether to overwrite.

rm

rm: remove a file or directory

rm [选项] 要删除的文件或目录

Options:

-r: Recursively delete entire folder

-f: Force delete without reminder

Example:

  • delete /home/aaa.txt
    • rm aaa.txt
  • Recursively delete the entire folder /home/bbb
    • rm -rf bbb

Note: The method of forced deletion without reminder:-f

mv: (clip)

mv 移动文件与目录或重命名

mv oldNameFile new NameFile:Rename

mv /temp/moveFile /targetFolder: move file

Example:

  • Rename the /home/aaa.txt file to pig.txt
    • mv aaa.txt pig.txt
  • Move pig.txt to /root/
    • mv pig.txt /root/

cat, more, less: View file content

cat

cat [选项] 要查看的文件: You can only browse, not modify. Equivalent to read-only.

Options

-n: display line number

Example:

  • /etc/profile shows line numbers
    • cat -n /etc/profile | more: Open the file and display pagination by spaces
    • | more:pipe command
more

more: A text filter based on the VI editor to display the content of a text file in full screen by page number

more 要查看的文件

less

less: View file contents in split screen. The function is similar to more, but more powerful than more. It doesn't appear that the entire file is loaded at once. Improve efficiency for large files

less 要查看的文件

Shortcut key: enter: next line space: page turn

notes

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325478120&siteId=291194637