Home  >  Article  >  System Tutorial  >  The principle and usage of ll command to view directory information list in Linux

The principle and usage of ll command to view directory information list in Linux

PHPz
PHPzOriginal
2024-06-12 10:27:59742browse

Linux 中 ll 命令查看目录信息列表的原理与使用方法

Study and summarize the document yourself. It’s a bit messy, don’t blame me

1. What does the total dose in Linux mean?

In Linux, we often use the ll command (ls-l) to view the directory information list, see the picture on the right:

查看用户的命令Linux_linux的chmod命令_打开终端的命令Linux

In the picture above, what does "Total 92" refer to? The "total" here, which can also be called "total dosage" or "total", refers to the number of blocks used in the directory. How is this number of blocks estimated? See picture on the right:

打开终端的命令Linux_查看用户的命令Linux_linux的chmod命令

The value on the right side of the above figure is the sum of the number of blocks (number of blocks) occupied by directories and files, 4x8+40+12+8=92, which is equal to "total 92", among which, the "ll-s" command also It can be written as "ls-ls" or "ls-l--size", and use "ls--help" to view the ls command parameter information, see the picture on the right (partial screenshot):

Note that "-s" here is capitalized, and the size of each file is listed in blocks.

To sum up, the "total" value in the ll or ls-l query results refers to the total number of blocks occupied by all files and subdirectories in the directory.

2. Linux return to root directory command

1. cd.. means to go to the upper directory;

2. cd-, means to return to the previous directory, similar to windows return;

3. cd/ means returning to the root directory.

4. cdlinux chmod command, return to normal user

查看用户的命令Linux_打开终端的命令Linux_linux的chmod命令

1. The command to switch users is: su+username

2. Switch from ordinary user to root user: sudosu

3. Return to the original user: exit command or logout, or ctrl+d

4. If you want to switch to the working environment of a new user: su-username such as su-root

5.# represents ordinary users, $ represents super users. That is root user

3. Linux file permissions

There are three types of file permissions: read (r), write (w) and execute (x). In addition to being represented by r, w and x, we can also use two's complement numbers to represent the three permissions. It is represented by a 3-digit two's complement number. A permission corresponds to a two's complement bit. If the bit is 1, it means that you have this permission. If the bit is 0, it means you do not have this permission, as shown in Table

打开终端的命令Linux_linux的chmod命令_查看用户的命令Linux

If you have done microcontroller development, you will also find that the three permissions r, w and x are the same as the register bits on the microcontroller

By different combinations, you can get different two's complement numbers and eight's complement numbers. 3-digit permissions can create 8 different permission combinations, as shown in the table

linux的chmod命令_打开终端的命令Linux_查看用户的命令Linux

The eight's complement number corresponding to the permission is the multiplication of the bits corresponding to each permission. For example, the permission rwx is 4+2+1=7. The permissions of the following file test.c are "rw-rw-r--", so its ten's complement representation is: 664.

In addition, we also started to use a, u, g and o to indicate the ownership of files, and =, + and - to indicate changes in file permissions,

查看用户的命令Linux_打开终端的命令Linux_linux的chmod命令

linux的chmod命令_查看用户的命令Linux_打开终端的命令Linux

For the file test.c, we want to change its ownership user (zuozhongkai) to have executable permissions on it, so we can

Use: u+x. If you want to set the owned user and its user group to have executable permissions on it, you can use: gu+x.

1. Permission management commands

Use Shell to operate file permission management, mainly using the two commands "chmod" and "chown",

Permission change command chmod

The command "chmod" is used to change the permissions of files or folders. The permissions can be represented by the numbers mentioned above or they can be

is represented by letters, and the command format is as follows:

chmod[parameter][file name/directory name]

The main parameters are as follows:

-c is similar to the "-v" parameter, but only the modified part is echoed.

-f does not display error messages.

-R recursively processes all files in the specified directory and their sub-file directories together.

查看用户的命令Linux_打开终端的命令Linux_linux的chmod命令

-v displays the execution process of the instruction.

Let's first learn how to use the command "chmod" to modify the permissions of a file in commonly used Linux systems and create a

in the user root directory.

File mytest, then check its default permissions,

We created a file: mytest. The default permissions of this file are "rw-rw-r--". We changed its permissions to "rwxrw-rw". The corresponding number is 766. The operation is as follows:

查看用户的命令Linux_linux的chmod命令_打开终端的命令Linux

Earlier we used numbers to change permissions. Let’s use letters to change permissions.

打开终端的命令Linux_查看用户的命令Linux_linux的chmod命令

File owner change command chown

The chown command is used to change the owner user or user group of a file or directory. The command format is as follows:

chown[parameter][username.][filename/directory]

where [username.] indicates the user or user group to which the file or directory is to be changed. The user name and group name are

Separated by ".", either the user name or group name can be omitted. The main parameters of the command are as follows:

-c has a similar effect to -v, but only the modified part is displayed.

打开终端的命令Linux_查看用户的命令Linux_linux的chmod命令

-f does not display error messages.

-h only processes all files and subdirectories in the specified directory.

-v displays the processing process. Create a test file in the user root directory and check the user and user group to which the folder belongs

linux的chmod命令_打开终端的命令Linux_查看用户的命令Linux

4. linuxc disk management

The file /etc/fstab records the hard disk partition situation in Ubuntu in detail,

查看用户的命令Linux_linux的chmod命令_打开终端的命令Linux

There is a line "/wason/dev/sda1duringinstallation", which means that the root directory "/" is on /dev/sda1 Linux chmod command , where "/" is the mount point, " /dev/sda1" is the hard drive where we install the Ubuntu system. Because our system is installed in a virtual machine. You can view the c drive in the current system through the following command:

ls/dev/sd*The above command is to copy all the device files starting with /dev/sd,

There are four c drive device files in

, where sd indicates a SATA hard drive or other external device, and the last

The number in

represents the nth partition on the hard disk. For example, /dev/sda1 represents the first partition on drive c. sda. picture

all start with /dev/sda, indicating that there is currently only one hard drive. If you plug in a U disk, SD card, etc., /dev/sdb, /dev/sdc, etc. may appear. If your USB flash drive has two partitions, device files such as /dev/sdb1 and dev/sdb2 may also appear.

打开终端的命令Linux_查看用户的命令Linux_linux的chmod命令

c drive management command

1. Disk partition command fdisk

If you want to partition a certain c drive, you can use the command fdisk. The command format is as follows:

fdisk

[parameter]

The main parameters are as follows:

-b

Specify the size of each partition.

-l

List the partition table of the specified device.

-s

Output the specified partition size to standard output, in blocks.

-u combined with the "-l" parameter will use the number of partitions instead of the number of cylinders to represent the starting address of each partition.

For example, if I want to partition the U disk, I must not partition the Ubuntu system I installed! ! ! You can use the following command

Command: sudofdisk/dev/sdb

linux的chmod命令_打开终端的命令Linux_查看用户的命令Linux

The above is the detailed content of The principle and usage of ll command to view directory information list in Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn