1. File system
1.1 File system structure
For Linux, use a unified directory tree structure
/
/home/ysa
/root
/bin
/mnt
user
etc
Note: There is no concept of drive letter C:D: under Linux
1.2 User Directory
One directory per user, such as /home/xiaoyang
Special case: super user root, whose user directory is /root
Permission mechanism: For an ordinary user, the only directory he can operate is the user directory.
The root user has no restrictions and can operate any files and directories.
1.3 Create directories and files
Directory operations: create directory/delete/rename
file operations: edit text files
All the above operations are performed in the user directory
/home/ysa
2. Common commands under Linux
2.1 Command line: file list
ls
ls, that is, list, lists all items in the directory
Example:
View current directory
ls
View the /home/ysa directory
ls /home/ysa
View root directory
ls /
View in detailed mode
ls -l /home/ysa
in,-lis the parameter, and the parameter is generally expressed in the form of-beginning
2.2 Command line: switch directories
Show current location pwd
pwd
pwd,即print working directory
Case demonstration:
pwd
switch directory cd
cd, that is, change directory, switch directories
Case demonstration:
switch to user home directory
cd
switch to a directory
cd /home/ysa/MyFolder
Several special directories
~Represents the current user's home directory
.Represents the current directory
…Represents the upper-level directory (two dots, not three dots, there is a problem with the editor here)
switch to home directory
cd ~
Switch to the MyFolder directory under the home directory
cd ~/MyFolder
Switch to the upper-level directory and then to the xiaoyang subdirectory
cd ../xiaoyang
The above command can also be used similarly for ls
2.3 Command line: directory operations
mkdir, that is, make directory creates a directory
mkdir abc
mkdir -p abc/123/test
use-pParameters, you can create all hierarchical directories of the path
rmdir, remove directory delete empty directory
rmdir abc
If the directory is not empty, the deletion fails
rm, which is remove to delete files or directories
rm -rf abc
Delete the abc directory and delete it together with the subkeys.
Among them, r means recursive and f means force.
cp, copy files or directories
Copy the folder MyFolder to MyFolder2:
cp -rf MyFolder MyFolder2
mv, that is, move, moves files or directories (renames)
mv hello.txt helloworld.txt
Key points:
For files,rm/cp/mvThese three commands are also applicable
2.4 Command line: archive compression
Archive
tar, that is, tape archive file packaging
to create an archive package
tar -cvf MyFolder.tar MyFolder
Among them,
c means create to create a file
v, means verbose to display details
f, means file
can also be packaged in multiple directories
tar -cvf xxx.tar file1 file2 file3
Restore archive
tar -xvf MyFolder.tar
tar -xvf MyFolder.tar -C outdir
Among them, the -C parameter specifies the target directory. By default, it will be extracted to the current directory.
Archive and compress.
The previous tar format was not compressed. The larger
tar format
was archived and compressed.
tar -zcvf MyFolder.tar.gz MyFolder
unzip
tar -xzvf MyFolder.tar.gz
tar -xzvf MyFolder.tar.gz -C outdir
Usually what we see is*.tar.gzthis format
2.5 Command line: soft link
Soft link, that is, the use of "shortcut" under Windowslncommand (link) to create a soft link
ln -s source link
in,-sRepresents soft soft link (default is hard)
for example
ln -s MyFolder MyFolder2
Characteristics of soft links:
1. Deleting the soft link will have no impact on the source file.
2. Deleting the source file will cause the soft link to fail.
byls -lWhen viewing file details, you can see the target path
. For example,ls -l /
It can be found,/binWhat actually points to is/user/binTable of contents
3. User management
3.1 Add user
sudo useradd -m ysa2
in,sudo, indicating executing as an administrator
1. Add user
sudo useradd -m ysa2
Among them, the -m parameter means adding a user directory under /home
2. Modify user password
passwd ysa2
3. Delete user
userdel ysa2
sudo rm -rf /home/ysa2/
Key points and details
1 When logging in to the system, logging in as the root user is not allowed by default.
2 Only special users can execute sudo
. For example, ysa can execute sudo solidly, but ysa2 cannot.Under Linux, the user who can execute sudo commands is calledsudoer
3.2 Super User
The super user root is similar to the Administrator user (blank line)
under Windows . Switch to the root user. It has full permissions and can directly use commands such as useradd.
1. When using for the first time, you need to set a password for root
sudo passwd root
2. Switch to the root user
su root
3. Exit
exit
Key points and details
1. su root is only effective for the current session (terminal)
and does not affect the current desktop environment .
2. root has too much power and needs to be used with caution.
3.3 Users and groups
Multiple users can be created under Linux, and users can be managed using groups.
For example:
boys group boys,
ming bo gang qiang
girls group girls
fang hong yue yuan
Create group
grounpadd boys
Create user
useradd -m -g boys ysa ming
Among them, -g means adding a user and adding the user to the boys group at the same time.
Modify existing users to new groups
usermod -g boys ysa
Among them, usermod means modifying user information
How to view users and groups?
cat /etc/group
Each line represents the information of a group, name + ID
How to view user list?
cat /etc/passwd
Each row represents information about a user
Key points:
When there are not many users, the concept of groups is not used in management
useradd a1
useradd b1
. One root and two ordinary users a1 and b1 are enough!
(Blank line)
By default, a group a1 with the same name will be created for user a1, which means that he is the only one in this group.
3.4 Log in to the desktop as root
By default, Ubuntu does not allow root login to the desktop environment.
(root has already set a password)
4. File permissions
4.1 File permissions
-owner: the owner of the file owner
-r: whether the file is readableread
-w: whether the file is writablewrite
-x: whether the file is executablexcute
For example, there are users in the system: ysa and ming
A file simple.txt, created by ysa
So, can ming access this access? Is it readable? Is it writable?
uselsCommand to view a file
ls -l simple.txt
-rw-r–r==.1 ysa ysa 13 April 21 03:48 simplie.txt
Among them, rw-r–r– indicates the access permissions of the file
Permissions are divided into three parts: self | group | others
. For example:
Own | Same group | other people | ||||||
---|---|---|---|---|---|---|---|---|
r | w | x | r | w | x | r | w | x |
r | w | x | r | w | x | - | - | - |
r | w | x | - | - | - | - | - | - |
In the folder window, go to File | Properties | Permissions to view
4.2 Modify file permissions
chmod
, that is, change file mode to modify the access permissions of the file
For example, a file simple.txt allows others to modify it. Among
chmod o+w simple.txt
them,
o
, means other
+w
, means adding write permission.
Everyoneall Add w permission:
chmod a+w simple.txt
Everyone all minus w permissions:
chmod a-w simple.txt
Only user user’s own permissions +w:
chmod u+w simple.txt
Modify other people's permissions -w:
chmod o-w simple.txt
Key points:
1. Only the owner or root of the file can modify the file permissions.
2. Omit the writing.
chmod +w simple.txt
chmod +w simple.txt
The default is to modify the permissions of yourself and the group.
4.3 Modify file owner
chown
, that is, change owner modifies the owner of the file
Generally speaking, each user only operates his or her own user directory, so
chown
the command is not commonly used.
Example:
1. Create a folder software in the /opt directory
2. Assign the software directory to user ysa
su root
mkdir /opt/software
chown -R ysa /opt/software
ls -ld /opt/software
Key points:
Only the owner and root of the file have the right to change the owner