Marco Linux-- the second week of work

1, the system will log the user's current information into the capital to /tmp/who.out saved as a file.

[root@centos7 ~]#who | tr [:lower:] [:upper:] > /tmp/who.out
[root@centos7 ~]#cat /tmp/who.out 
ROOT     :0           2019-06-03 15:45 (:0)
ROOT     PTS/0        2019-06-03 15:59 (192.168.30.1)

 

2, calculates the sum of 1 + 2 + 3 + ... + 99 + 100.

[root@centos7 ~]#echo {1..100} | tr ' ' + | bc
5050
[root@centos7 ~]#seq -s + 100 | bc
5050

 

3, common user and file management commands which, and demonstrate command and usage.

 User management commands:

Change password

passwd

[root@centos7 ~]#echo '12345678' | passwd --stdin kkk
Changing password for user kkk.
passwd: all authentication tokens updated successfully.

Create a user

useradd

[root@centos7 ~]#useradd user001

Modify user information

usermod

[root@centos7 ~]#usermod -g kkk -aG root -u 6666 user001

delete users

userdel

[root@centos7 ~]#userdel -r user1

Creating user groups

groupadd

[root@centos7 ~]#groupadd group001

Modify user group information

groupmod

[root@centos7 ~]#groupmod -g 6666 -n group002 group001

Deleting User Groups

groupdel

[root@centos7 ~]#groupdel group002

Displaying a user, group information

getent

[root@centos7 ~]#getent passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
stop: x: 7 : 0 : wait: / sbin: / sbin / halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:999:998:User for polkitd:/:/sbin/nologin
abrt:x:173:173::/etc/abrt:/sbin/nologin
libstoragemgmt:x:998:997:daemon account for libstoragemgmt:/var/run/lsm:/sbin/nologin
rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin
colord:x:997:996:User for colord:/var/lib/colord:/sbin/nologin
saslauth:x:996:76:Saslauthd user:/run/saslauthd:/sbin/nologin
rtkit:x:172:172:RealtimeKit:/proc:/sbin/nologin
chrony:x:995:993::/var/lib/chrony:/sbin/nologin
qemu:x:107:107:qemu user:/:/sbin/nologin
tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin
geoclue:x:994:991:User for geoclue:/var/lib/geoclue:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
radvd:x:75:75:radvd user:/:/sbin/nologin
setroubleshoot:x:993:990::/var/lib/setroubleshoot:/sbin/nologin
pulse:x:171:171:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
gnome-initial-setup:x:992:987::/run/gnome-initial-setup/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
Kkk: X: 1000 : 1000 : Kkk, IT, 10086 , 10000 : / Home / Kkk: / Bin / Bash
tomcat:x:1001:1004::/home/tomcat:/bin/bash
mysql:x:1002:1005::/home/mysql:/bin/bash
user2:x:1004:1008::/home/user2:/bin/bash
user3:x:1005:1009::/home/user3:/bin/bash
[root@centos7 ~]#getent group
root:x:0:
am: x: 1 :
daemon:x:2:
sys:x:3:
adm:x:4:
tty:x:5:
disk:x:6:
lp:x:7:
mem:x:8:
kmem:x:9:
wheel:x:10:
cdrom:x:11:
mail:x:12:postfix
man:x:15:
dialout:x:18:
floppy:x:19:
games:x:20:
tape:x:30:
video:x:39:
ftp:x:50:
lock:x:54:
audio: x: 63 :
nobody:x:99:
users:x:100:
utmp:x:22:
utempter:x:35:
input:x:999:
systemd-journal:x:190:
systemd-network:x:192:
dbus:x:81:
polkitd:x:998:
abrt:x:173:
libstoragemgmt:x:997:
rpc:x:32:
colord:x:996:
cgred:x:995:
dip:x:40:
ssh_keys:x:994:
saslauth:x:76:
rtkit:x:172:
chrony:x:993:
kvm:x:36:qemu
qemu:x:107:
tss: x: 59 :
libvirt:x:992:
usbmuxd:x:113:
geoclue:x:991:
rpcuser:x:29:
nfsnobody:x:65534:
radvd:x:75:
setroubleshoot:x:990:
pulse-access:x:989:
pulse-rt:x:988:
press: x: 171 :
gdm:x:42:
gnome-initial-setup:x:987:
sshd:x:74:
opens: x: 70 ;
slocate:x:21:
postdrop:x:90:
postfix:x:89:
ntp:x:38:
stapusr:x:156:
stapsys:x:157:
stapdev:x:158:
tcpdump:x:72:
Kkk: X: 1000 : Kkk
webs:x:1001:
apps:x:1002:tomcat
dbs:x:1003:mysql
tomcat:x:1004:
mysql:x:1005:
user001:x:1006:
user2:x:1008:
user3:x:1009:
user1group:x:1010:
[root@centos7 ~]#getent shadow
root:$6$fhGPsICHwt401JgQ$5X5y3oDmIBzerlIbNeRFjnXs01bgbVTMLa4oRDQjP8z5fJKDHAGSL7IBjjqB5c9BifVSHXhwlnoVD./0fLhok1::0:99999:7:::
bin:*:17110:0:99999:7:::
daemon:*:17110:0:99999:7:::
adm:*:17110:0:99999:7:::
lp:*:17110:0:99999:7:::
sync:*:17110:0:99999:7:::
shutdown:*:17110:0:99999:7:::
halt:*:17110:0:99999:7:::
mail:*:17110:0:99999:7:::
operator:*:17110:0:99999:7:::
games:*:17110:0:99999:7:::
ftp:*:17110:0:99999:7:::
nobody:*:17110:0:99999:7:::
systemd-network:!!:18033::::::
dbus:!!:18033::::::
polkitd: !!: 18033 ::::::
Abrt: !!: 18033 ::::::
libstoragemgmt: !!: 18033 ::::::
rpc:!!:18033:0:99999:7:::
colord:!!:18033::::::
saslauth: !!: 18033 ::::::
rtkit: !!: 18033 ::::::
chrony:!!:18033::::::
qemu:!!:18033::::::
TSS: !!: 18033 ::::::
usbmuxd:!!:18033::::::
geoclue:!!:18033::::::
rpcuser:!!:18033::::::
nfsnobody:!!:18033::::::
radvd:!!:18033::::::
setroubleshoot:!!:18033::::::
pulse:!!:18033::::::
gdm:!!:18033::::::
gnome-initial-setup:!!:18033::::::
sshd:!!:18033::::::
avahi:!!:18033::::::
postfix:!!:18033::::::
ntp:!!:18033::::::
tcpdump:!!:18033::::::
kkk: $ 6 $ $ BMwLhCs1 yuv9kNhqstfVbNx10wZg9sV72pds1I2utcPDRDxgzzGjzfV / eJjVBeduqF8n.3J4flhrXZ.9QR / GLn7NBZ0 / o0: 18051 : 0 : 99999 : 7 :::
tomcat:!!:18051:0:99999:7:::
mysql:!!:18051:0:99999:7:::
user2:!!:18051:0:99999:7:::
user3:!!:18051:0:99999:7:::
[root@centos7 ~]#getent gshadow
root:::
bin:::
daemon:::
sys:::
adm:::
tty:::
disk:::
lp:::
mem:::
kmem:::
wheel:::
cdrom:::
mail:::postfix
man:::
dialout:::
floppy:::
games:::
tape:::
video:::
ftp:::
lock:::
audio:::
nobody:::
users:::
utmp:!::
utempter: ! ::
input:!::
systemd-journal:!::
systemd-network:!::
dbus:!::
polkitd: ! ::
Abrt: ! ::
libstoragemgmt: ! ::
rpc:!::
colord:!::
cgred:!::
dip:!::
ssh_keys:!::
saslauth: ! ::
rtkit: ! ::
chrony:!::
kvm:!::qemu
qemu:!::
TSS: ! ::
libvirt:!::
usbmuxd:!::
geoclue:!::
rpcuser:!::
nfsnobody:!::
radvd:!::
setroubleshoot:!::
pulse-access:!::
pulse-rt:!::
pulse:!::
gdm:!::
gnome-initial-setup:!::
sshd:!::
avahi:!::
slocate:!::
postdrop:!::
postfix:!::
ntp:!::
Stpusr: ! ::
stapsys:!::
Stpdev: ! ::
tcpdump:!::
kkk: $ 6 $ NpCZ5 / 9u878 / $ yzrgz8nItDezMkPawxAIKV.40SQPLPUuV21yr0w.MKU32AhMiFc6uVZMqVNj31dTP31IseNtBufAC5AMedQG7 / :: kkk
webs:!::
apps:!::tomcat
dbs:!::mysql
tomcat:!::
mysql:!::
user001:!::
user2:!::
user3:!::
user1group:!::

View user id information

id

[root@centos7 ~]#id kkk
uid = 1000 (kkk) gid = 1000 (kkk) groups = 1000 (kkk)

Switch User

its

[root@centos7 ~]#su - kkk
Last login: Tue Jun  4 22:47:51 CST 2019 on pts/0

File management commands

Edit text file contents

nano

[root@centos7 ~]#nano f1

View catalog file

ls

[root@centos7 ~]#ls -a
.   anaconda-ks.cfg  .cache   dead.letter  Documents  .esd_auth      initial-setup-ks.cfg  Music     Public     Videos
..  .bash_history    .config  Desktop      Downloads  .ICEauthority  .local                Pictures  Templates

View the file properties list

ll、ls -l

[root@centos7 ~]#ll
total 12
-rw-------. 1 root root 1894 May 17 08:35 anaconda-ks.cfg
-rw-------. 1 root root   14 Jun  1 15:33 dead.letter
drwxr-xr-x. 2 root root    6 May 17 08:44 Desktop
drwxr-xr-x. 2 root root    6 May 17 08:44 Documents
drwxr-xr-x. 2 root root    6 May 17 08:44 Downloads
-rw-r--r--. 1 root root 1925 May 17 08:43 initial-setup-ks.cfg
drwxr-xr-x. 2 root root    6 May 17 08:44 Music
drwxr-xr-x. 2 root root    6 May 17 08:44 Pictures
drwxr-xr-x. 2 root root    6 May 17 08:44 Public
drwxr-xr-x. 2 root root    6 May 17 08:44 Templates
drwxr-xr-x. 2 root root    6 May 17 08:44 Videos

Modify the file owner, all groups

chown

[centos7 root @ ~] # Chown kkk: kkk / date / f1

View files three times

stat

[root@centos7 ~]#stat /data/f1 
  File: ‘/data/f1’
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: 803h/2051d      Inode: 67          Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/     kkk)   Gid: ( 1000/     kkk)
Context: unconfined_u:object_r:etc_runtime_t:s0
Access: 2019-06-05 01:52:08.860744447 +0800
Modify: 2019-06-05 01:52:08.860744447 +0800
Change: 2019-06-05 01:52:57.333748189 +0800
 Birth: -

copy

cp

[root@centos7 ~]#cp -a /data/f1 .

Move or rename files

mv

[root@centos7 ~]#mv /data/f1 /data/f2

delete

rm

[root@centos7 ~]#rm -f /data/f1
[root@centos7 ~]#rm -rf /data/dir1/

Create an empty directory

mkdir

[root@centos7 ~]#mkdir /data/dir1

Create an empty file

>>、touch、>

[root@centos7 ~]#>> /data/f2
[root@centos7 ~]#touch /data/f1
[root@centos7 ~]#> /data/f3

View text files

cat

[root@centos7 ~]#cat /data/f1 
test

Modify files for all groups

chgrp

[root@centos7 ~]#chgrp kkk /data/f1

Modify file permissions

chmod

[root@centos7 ~]#chmod 777 /data/f1

ACL settings file

setfacl

[root@centos7 ~]#setfacl -m u:user2:r /data/f1

View Files ACL

[root@centos7 ~]#getfacl /data/f1
getfacl: Removing leading '/' from absolute path names
# file: data/f1
# owner: root
# group: kkk
user::rwx
user:user2:r--
group::rwx
mask::rwx
other::rwx

 To view or modify the file permissions reservations

umask

[root@centos7 ~]#umask
0022
[root@centos7 ~]#umask 0024
[root@centos7 ~]#umask -p
umask 0024
[root@centos7 ~]#umask -S
u=rwx,g=rx,o=wx

Determine the file type

file

[root@centos7 ~]#file /usr/bin/cat
/usr/bin/cat: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=fac04659ab9a437b5384c09f4731023373821a39, stripped
[root@centos7 ~]#file /data/f1 
/data/f1: ASCII text

Create link

ln

[root@centos7 ~]#ln -s /data/f1 /root/f1_link

View source path corresponding soft link

readlink

[root@centos7 ~]#readlink f1_link 
/data/f1

 

4, create a user gentoo, additional group bin and root, the default shell is / bin / csh, annotation information "Gentoo Distribution".

[root@centos7 ~]#useradd -G bin,root -s /bin/csh -c "Gentoo Distribution" gentoo
[root@centos7 ~]#getent passwd gentoo
gentoo:x:6673:6675:Gentoo Distribution:/home/gentoo:/bin/csh
[root@centos7 ~]#id gentoo
uid=6673(gentoo) gid=6675(gentoo) groups=6675(gentoo),0(root),1(bin)

 

5, a new file in / testdir / dir created in the group automatically belong webs, members of the group apps such as: tomcat to have read and write access to these new documents, dbs group members such as: mysql can only read access to the new file, other users (not part webs, apps, dbs) can not access this folder.

[root@centos7 ~]#groupadd webs
[root@centos7 ~]#groupadd apps
[root@centos7 ~]#groupadd dbs
[root@centos7 ~]#useradd tomcat -G apps
[root@centos7 ~]#useradd mysql -G dbs
[root@centos7 ~]#mkdir -p /testdir/dir
[root@centos7 ~]#chgrp webs /testdir/dir/
[root@centos7 ~]#chmod g+s /testdir/dir/
[root@centos7 ~]#ll -d /testdir/dir/
drwxr-sr-x. 2 root webs 6 Jun  5 01:28 /testdir/dir/
[root@centos7 ~]#setfacl -Rm g:apps:6 /testdir/dir/
[root@centos7 ~]#setfacl -Rm g:dbs:4 /testdir/dir/
[root@centos7 ~]#setfacl -Rm o::0 /testdir/dir/
[root@centos7 ~]#getfacl /testdir/dir/
getfacl: Removing leading '/' from absolute path names
# file: testdir/dir/
# owner: root
# group: webs
# flags: -s-
user::rwx
group::r-x
group:apps:rw-
group:dbs:r--
mask::rwx
other::---

 

6, to find the ip address of ifconfig. The results show only requires IPv4 address of this machine.

[root@centos6 ~]#ifconfig | grep 'inet addr' | tr -s ' ' : | cut -d : -f 4
192.168.1.120
192.168.30.101
127.0.0.1

 

7, to identify the user name of the user maximum UID, UID and shell type.

[root@centos6 ~]#cut -d : -f 1,3,7 /etc/passwd | sort -t : -k 2 -nr | head -n 1
nfsnobody:65534:/sbin/nologin

 

8, the file to copy /etc/rc.d/init.d/functions the / tmp directory, replace / tmp / functions file / etc / sysconfig / init is / var / log.

:%s@/etc/sysconfig/init@/var/log@g

 

Guess you like

Origin www.cnblogs.com/keith946/p/10968507.html