Linux learning (1) - Command basic format and file handling commands

table of Contents

Linux Command Format

Command Format

Content Query directory: ls

Description file permissions

Linux directory processing command

Create a directory: mkdir

Switching directory: cd

View the current directory location: pwd

Delete empty directories: rmdir

Delete files or directories: rm

Copy command: cp

Cut or rename command: mv

Introduction root directory

Links command: ln


 

Video tutorial lesson but learning Mu: https://www.imooc.com/video/3472

This section summarizes the study and made notes.

 

Linux Command Format

Command symbol explanation:

  • []:it's meaningless

  • root: the representative of the currently logged on user, the administrator account is the root Linux

  • @: No special meaning

  • localhost: represents the current host computer name

  • ~: Current directory (home directory, that the initial login location), the administrator and the user's home directory different from ordinary users

  • #: Superuser prompt, prompt ordinary users is $

Command Format

命令 [选项] [参数]

Note: Use individual commands do not follow this format, when there are multiple options, you can write with simplified options and complete options. [] Representation is optional.

Content Query directory: ls

ls [选项] [文件或目录]
选项:
	-a 显示所有文件,包括隐藏文件(在Linux中,隐藏文件是以点“.”开头)
	-l 显示详细信息
	-d 查看目录属性
	-h 人性化显示文件大小
	-i 显示inode

Example. 1: LS command

Example 2: LS -l command to view the details of each file in the current directory (and ll command equivalent)

FIG 6 above behavior of the total embodiment, interpreted as follows:

  • The first digit indicates the type of file, "-" represents a normal file.
  • Then the back nine characters, each a set of three, file permissions on behalf of the owner, will be explained below.
  • Adhesive "."
  • Then "1" represents the reference count, on behalf of this file is called several times.
  • Then the first representative of a root file owner
  • Then the second root represents the owner of the file belongs to the user group.
  • Then, "24772" indicates the size of the file in bytes.
  • "At 02:27 on March 17" indicates that the file was last modified date.
  • Finally, a "install.log" is the file name.

Example. 3: LS-LH command to display the file information humanization

You can see the file size information into a scene of K, M and other units.

Description file permissions

-rw-r--r--
	- 表示文件类型(其中“-”表示文件、“d”表示目录、“l”表示软链接文件,除此之外还有块设备文件、字符设备文件、套接字文件和管道文件)
	rw- 所有者(u)
	r-- 所属组(g)
	r-- 其他人(o)
	r表示读,w表示写,x表示执行

 

Linux directory processing command

Create a directory: mkdir

grammar:

mkdir -p [目录名]
	-p 递归创建(意思是先创建上一级目录,再创建要创建的目录)
	命令英文原意:make directories

From m A K E the dir ectories

Example 1: mkdir one command, create a directory named one of the ls command to view the creation of one folder

Example 2: mkdir -p two / three / four commands , create two directories in the current directory, create three listings within two directory, create directory under three four directory, created recursively.

Switching directory: cd

grammar:

cd [目录]
	命令英文原意:change directory

简化操作
	cd ~ 进入当前用户的家目录
	cd 
	cd - 进入上次目录
	cd .. 进入上一级目录
	cd . 进入当前目录
  • Relative path: refers to the current directory, to find

  • Absolute path: Specifies the start from the root directory, a recursive lookups level. In any catalog, you can enter the designated location

Linux can fill the whole catalog and order by the Tab key

Example 1: cd two / three / four commands using relative path, jump to four directory

Example 2: cd / root / two / three commands , using an absolute path, "/" represents the root directory, three jump to the directory

View the current directory location: pwd

grammar:

pwd 
	命令英文原意:print working directory

Example 1: pwd command to view the current location of the directory where

Delete empty directories: rmdir

grammar:

rmdir [目录名]
	命令英文原意:remove empty directories

From r E m Ove empty dir ectories, only delete empty directories.

Example 1: rmdir one command , delete empty directories, only delete empty directories, where "one" refers to delete empty directories.

Delete files or directories: rm

grammar:

rm -rf [文件或目录]
	命令英文原意:remove
	选项:
		-r 删除目录
		-f 强制

rm -rf / can execute the command to delete all the files in the root directory.

Example 1: rm -rf abc command , force delete abc directory and its subordinate documents, "abc" is to be deleted directory

Copy command: cp

grammar:

cp [选项] [原文件或目录] [目标目录]
	命令英文原意:copy
	选项:
		-r 复制目录
		-p 连带文件属性复制
		-d 若源文件是链接文件,则复制链接属性
		-a 相当于-pdr

Example 1: cp -a two / root / three / command to copy in / root absolute path / three / two file or the directory of all

Cut or rename command: mv

grammar:

mv [原文件或目录] [目标目录]
	命令英文原意:move
	如果原文件和目标目录不在一个目录下则是剪切,如果是在同一个目录下则是改名。

Example 1: mv two three command , the two three directory rename directory

Example 2: mv three / root / six / command , the three cut to the directory / root / six / lower

Introduction root directory

By cd / command, jump to the root directory, and then view the directory by ls command which there is in this directory:

Common Catalog role:

(Using the cd / command to jump to the root directory view these directories)

  • / Root directory

  • / Bin command to save directory (ordinary users can read commands)

  • / Boot startup directory, is to start the relevant documents

  • / Dev device file directory

  • / Etc configuration file directory

  • / Home general user's home directory

  • / Lib directory to save the system library

  • / Mnt directory mount system

  • / Media mount directory

  • / Root super-user's home directory

  • / Tmp temporary directory

  • / Sbin command to save the directory (the directory super user to use)

  • / Proc write directly to memory

  • /sys

  • / Usr directory system software resources

    • / Usr / bin / command system (normal user)

    • / Usr / sbin / command system (super user)

  • / Var system-related document content

bin and sbin at the root, bin and sbin directories under usr, these four directories are used to store system commands.

proc and sys directory can not be directly manipulated, saved these two directories is the memory of the overload point.

At home directory root or home, and casually put tmp directory content.

Links command: ln

grammar:

ls -s [原文件] [目标文件]
	命令英文原意:link
	功能描述:生成链接文件
	选项:
		-s 插件软链接

You can create soft links and hard links by ln command.

Hard link feature:

  • 1, have the same memory block and the i-node block, it can be seen as a same file

  • 2, node i can be identified by

  • 3, can not cross partitions

  • 4, can not use for directory

Soft link feature:

  • 1, similar to Windows shortcuts

  • 2, soft links and nodes have their own I Block block, but only to save the original data block file name and i-node number, and not the actual file data

  • 3, soft link file permissions are rwxrwxrwx. Soft links Irwxrwxrwx I represent a soft link file

  • 4, modify any file, another has changed

  • 5, delete the original file, soft links can not be used

Note: If you do a soft link source file must write the absolute path

Example 1: ln test.log test.log.hard command to create a hard link called test.log.hard for test.log

Example 2: ln -s test.log test.log.soft command , create a soft link to a file named test.log.soft for test.log

Published 500 original articles · won praise 77 · views 160 000 +

Guess you like

Origin blog.csdn.net/cnds123321/article/details/104920216