Unix虽然强大但是有着昂贵的授权费用,并且不开放源代码,于是有人发起了GNU运动(GNU IS NOT UNIX,带有那么一丝嘲讽),模仿 Unix 的界面和使用方式,从头做一个开源的版本。在1987年荷兰有个大学教授安德鲁写了一个Minix,类似于Unix,专用于教学。当Minix流传开来之后,世界各地的黑客们纷纷开始使用并改进,希望把改进的东西合并到Minix中,但是安德鲁觉得他的系统是用于教学的,不能破坏纯净性,于是拒绝了。
test@ubuntu-server:~$ su - study
Password:
study@ubuntu-server:~$
可以看到,切换用户后名称已经修改为study了,我们使用exit即可退出当前用户回到test。
输入who可以查看当前登录账号(注意是登录的账号)输入whoami可以查看当前的操作账号:
12345678
test@ubuntu-server:~$ su study
Password:
study@ubuntu-server:/home/test$ cd ~
study@ubuntu-server:~$ who
test pts/0 2022-01-24 03:57 (192.168.10.3)
study@ubuntu-server:~$ whoami
study
study@ubuntu-server:~$
study@ubuntu-server:~$ sudo -s
[sudo] password for study:
study is not in the sudoers file. This incident will be reported.
正是因为没有加入到sudo用户组,这里我们来尝试将其添加到sudo用户组:
12
test@ubuntu-server:~$ id study
uid=1001(study)gid=1001(study)groups=1001(study)
使用usermod命令来对用户的相关设置进行修改,参数与useradd大致相同:
123
test@ubuntu-server:~$ sudo usermod study -G sudo
test@ubuntu-server:~$ id study
uid=1001(study)gid=1001(study)groups=1001(study),27(sudo)
接着切换到study用户就可以使用sudo命令了:
123456
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root"for details.
study@ubuntu-server:/home/test$ sudo -s
[sudo] password for study:
root@ubuntu-server:/home/test#
test@ubuntu-server:~$ ls -al
total 44
drwxr-xr-x 4testtest4096 Jan 2408:55 .
drwxr-xr-x 4 root root 4096 Jan 2404:24 ..
-rw------- 1testtest2124 Jan 2404:29 .bash_history
-rw-r--r-- 1testtest220 Feb 252020 .bash_logout
-rw-r--r-- 1testtest3771 Feb 252020 .bashrc
drwx------ 2testtest4096 Jan 2115:48 .cache
drwx------ 3testtest4096 Jan 2314:49 .config
-rw-r--r-- 1testtest807 Feb 252020 .profile
-rw------- 1testtest34 Jan 2404:17 .python_history
-rw-r--r-- 1testtest0 Jan 2115:52 .sudo_as_admin_successful
-rw------- 1testtest7201 Jan 2408:55 .viminfo
test@ubuntu-server:~$ chmod 664test
test@ubuntu-server:~$ ll test
-rw-rw-r-- 1testtest0 Jan 2409:32 test
如果我们想修改文件的拥有者或是所属组,可以使用chown和chgrp命令:
12345678
test@ubuntu-server:~$ sudo chown root test
test@ubuntu-server:~$ ls -l
total 0
-rw-rw-r-- 1 root test0 Jan 2410:43 test
test@ubuntu-server:~$ sudo chgrp root test
test@ubuntu-server:~$ ls -l
total 0
-rw-rw-r-- 1 root root 0 Jan 2410:43 test
再次操作该文件,会发现没权限:
12
test@ubuntu-server:~$ chmod 777test
chmod: changing permissions of 'test': Operation not permitted
接着我们来看文件的复制、移动和删除,这里我们先创建一个新的目录并进入到此目录用于操作:
123
test@ubuntu-server:~$ mkdir study
test@ubuntu-server:~$ cd study
test@ubuntu-server:~/study$
test@ubuntu-server:~/study$ cp ../test test
test@ubuntu-server:~/study$ ls
test
那么如果我们想要将一整个目录进行复制呢?我们需要添加一个-r参数表示将目录中的文件递归复制:
1234567
test@ubuntu-server:~/study$ cd ~
test@ubuntu-server:~$ cp -r study study_copied
test@ubuntu-server:~$ ls -l
total 8
drwxrwxr-x 2testtest4096 Jan 2410:16 study
drwxrwxr-x 2testtest4096 Jan 2410:20 study_copied
-rw-rw-r-- 1testtest0 Jan 2409:32 test
test@ubuntu-server:~$ mkdir study2
test@ubuntu-server:~$ mv test study2
test@ubuntu-server:~$ ls
study study2 study_copied
test@ubuntu-server:~$ cd study2
test@ubuntu-server:~/study2$ ls
test
现在我们想要移动个目录到另一个目录中,比如我们想将study目录移动到study2目录中:
123456
test@ubuntu-server:~$ mv study study2
test@ubuntu-server:~$ ls
study2 study_copied
test@ubuntu-server:~$ cd study2
test@ubuntu-server:~/study2$ ls
study test
Fields Management for window 1:Def, whose current sort field is %MEM
Navigate with Up/Dn, Right selects for move then <Enter> or Left commits,
'd' or <Space> toggles display, 's' sets sort. Use 'q' or <Esc> to end!
按下q键即可退出监控界面。
我们可以直接输入free命令来查看当前系统的内存使用情况:
1234
test@ubuntu-server:~$ free -m
total used free shared buff/cache available
Mem: 3919 212 2706 1 999 3523
Swap: 3922 0 3922
其中-m表示以M为单位,也可以-g表示以G为单位,默认是kb为单位。
最后就是磁盘容量,我们可以使用lsblk来查看所有块设备的信息,其中就包括我们的硬盘、光驱等:
1 2 3 4 5 6 7 8 91011
test@ubuntu-server:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 48.9M 1 loop /snap/core18/2127
loop1 7:1 0 28.1M 1 loop /snap/snapd/12707
loop2 7:2 0 62M 1 loop /snap/lxd/21032
sr0 11:0 1 1024M 0 rom
nvme0n1 259:0 0 20G 0 disk
├─nvme0n1p1 259:1 0 512M 0 part /boot/efi
├─nvme0n1p2 259:2 0 1G 0 part /boot
└─nvme0n1p3 259:3 0 18.5G 0 part
└─ubuntu--vg-ubuntu--lv 253:0 0 18.5G 0 lvm /
test@ubuntu-server:~$ sudo shutdown
[sudo] password for test:
Shutdown scheduled for Mon 2022-01-24 11:46:18 UTC, use 'shutdown -c' to cancel.
test@ubuntu-server:~$ sudo shutdown now
Connection to 192.168.10.6 closed by remote host.
Connection to 192.168.10.6 closed.
test@ubuntu-server:~$ tar -zcvf test.tar.gz *.txt
1.txt
2.txt
3.txt
test@ubuntu-server:~$ ls
1.txt 2.txt 3.txt test.tar.gz
test@ubuntu-server:~$
接着我们删除刚刚三个文件,再执行解压操作,得到压缩包中文件:
123456789
test@ubuntu-server:~$ rm *.txt
test@ubuntu-server:~$ ls
test.tar.gz
test@ubuntu-server:~$ tar -zxvf test.tar.gz
1.txt
2.txt
3.txt
test@ubuntu-server:~$ ls
1.txt 2.txt 3.txt test.tar.gz
同样的,我们也可以对一个文件夹进行打包:
1 2 3 4 5 6 7 8 9101112131415161718
test@ubuntu-server:~$ mv *.txt test
test@ubuntu-server:~$ tar -zcvf test.tar.gz test/
test/
test/1.txt
test/2.txt
test/3.txt
test@ubuntu-server:~$ rm -r test
test@ubuntu-server:~$ ls
test.tar.gz
test@ubuntu-server:~$ tar -zxvf test.tar.gz
test/
test/1.txt
test/2.txt
test/3.txt
test@ubuntu-server:~$ ls
test test.tar.gz
test@ubuntu-server:~$ ls test1.txt 2.txt 3.txt
I was hard on people sometimes, probably harder than I needed to be.
I remember the time when Reed was six years old, coming home, and I had just fired somebody that day.
And I imagined what it was like for that person to tell his family and his young son that he had lost his job.
It was hard.
But somebody’s got to do it.
I figured that it was always my job to make sure that the team was excellent, and if I didn’t do it, nobody was going to do it.
You always have to keep pushing to innovate.
Dylan could have sung protest songs forever and probably made a lot of money, but he didn’t.
He had to move on, and when he did, by going electric in 1965, he alienated a lot of people.
test@ubuntu-server:~$ python3
Python 3.8.10 (default, Nov 26 2021, 20:14:08)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print("HelloWorld!")
HelloWorld!
>>> exit()
public class Main{
public static void main(String[] args){
System.out.println("Hello World!");
}
}
12345
test@ubuntu-server:~$ javac Main.java
test@ubuntu-server:~$ ls
Main.class Main.java
test@ubuntu-server:~$ java Main
Hello World!
接着我们来部署一下Redis服务器:
1
test@ubuntu-server:~$ sudo apt install redis
安装完成后,可以直接使用redis-cli命令打开Redis客户端连接本地的服务器:
123
test@ubuntu-server:~$ redis-cli
127.0.0.1:6379> keys *
(empty list or set)
使用和之前Windows下没有区别。
接着我们安装一下MySQL服务器,同样的,直接使用apt即可:
1
sudo apt install mysql-server-8.0
我们直接直接登录MySQL服务器,注意要在root权限下使用,这样就不用输入密码了:
1 2 3 4 5 6 7 8 9101112131415
sudo mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.27-0ubuntu0.20.04.1 (Ubuntu)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> exit
mysql> create user test identified by '123456';
Query OK, 0 rows affected (0.01 sec)
mysql> grant all on book_manage.* to test;
Query OK, 0 rows affected (0.00 sec)
test@ubuntu-server:~$ mysql -u test -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 8.0.27-0ubuntu0.20.04.1 (Ubuntu)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| book_manage |
| information_schema |
+--------------------+
2 rows in set (0.01 sec)