{"id":7293,"date":"2018-03-31T08:52:51","date_gmt":"2018-03-31T00:52:51","guid":{"rendered":"http:\/\/rmohan.com\/?p=7293"},"modified":"2018-03-31T08:52:51","modified_gmt":"2018-03-31T00:52:51","slug":"rhel-7-notes","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=7293","title":{"rendered":"RHEL -7 Notes"},"content":{"rendered":"<p>study notes 2<\/p>\n<p>&#8212; command line file<\/p>\n<p>1, create and delete files<\/p>\n<p>Create a file touch xxxx<\/p>\n<p>touch -t 20151225 create a file and specify time properties<\/p>\n<p>rm xxx delete the file<\/p>\n<p>rm -rf forced to delete files<\/p>\n<p>2. Create a directory and delete the directory<\/p>\n<p>mkdir -p xxx\/yyy recursively create directories;<\/p>\n<p>rmdir xxx delete empty directories;<\/p>\n<p>rm -rf XXX forcibly remove non-empty directories;<\/p>\n<p>3, copy files and directories<\/p>\n<p>cp \/path1\/xxx \/path2\/xxx\/<\/p>\n<p>cp -p \/path1\/xxx \/path2\/yyy copy files to retain the original file attributes;<\/p>\n<p>cp -Rf (or -rf)\/path1\/ \/path2\/ copy files to a directory directory path1 path2<\/p>\n<p>cp -a cp -dR &#8211;preserve=all<\/p>\n<p>4 Cut files<\/p>\n<p>mv \/path1\/xx \/path2\/yy<\/p>\n<p>5 View Files<\/p>\n<p>cat xx less<br \/>\nmore<br \/>\nless<\/p>\n<p>3&#8211; redirection and piping<\/p>\n<p>Redirect correct content:<\/p>\n<p>cat xx.file&gt; yy.file equivalent<\/p>\n<p>cat xx.file 1&gt; yy.file redirected to the file contents yy.file, will overwrite the original file contents;<\/p>\n<p>cat \/etc\/passwd &amp; &gt;&gt; \/tmp\/xx<\/p>\n<p>cat \/etc\/passwd &gt; \/tmp\/xx 2&gt;&amp;1<\/p>\n<p>tail -f \/var\/log\/messages &gt;\/tmp\/xx 2&gt;\/tmp\/yy<\/p>\n<p>ps aux | grep tail | grep -v &#8216;grep&#8217;<\/p>\n<p>ls -al \/dev\/<\/p>\n<p>to redirect the file contents input to a command<\/p>\n<p>tr<\/p>\n<p>cat &gt; \/tmp\/xxx &lt;&lt;EOF<br \/>\n&gt;test1<br \/>\n&gt;test2<br \/>\n&gt;test3<br \/>\n&gt;EOF<\/p>\n<p>cat &lt;&lt;EOF&gt; \/tmp\/xxx<br \/>\n&gt;test2<br \/>\n&gt;test3<br \/>\n&gt;test4<br \/>\n&gt;EOF<\/p>\n<p>number of rows grep -n before looking for the number of rows plus -i ignore case, -A 3 looking for then displayed, B 3 show the number of rows -v looking for negative keywords before after content, -q Do not display output;<\/p>\n<p>grep -n1 B1 -A root \/etc\/passwd<\/p>\n<p>ifconfig | grep &#8216;inet&#8217;|grep -v &#8216;inet6&#8217;| awk &#8216;BEGIN{print &#8220;IP\\t\\tnetmask&#8221;}{print $2,&#8221;\\t&#8221;,$4}END{}&#8217;<\/p>\n<p>ifconfig | grep &#8216;inet&#8217;|grep -v &#8216;inet6&#8217;| tee -a \/tmp\/yy|awk &#8216;BEGIN{print &#8220;IP\\t\\tnetmask&#8221;}{print $2,&#8221;\\t&#8221;,$4}END{}&#8217;<\/p>\n<p>4 &#8211; Vim editor use<\/p>\n<p>1, gedit graphical editing files<\/p>\n<p>2, Vim operating a file, if the file exists is opened, if the file does not exist, it is created:<\/p>\n<p>When using Vim to edit the file to open, the default is the command-line mode:<\/p>\n<p>4. When you edit the file, enter the command line insert mode, press the following keys to enter:<\/p>\n<p>i, from the current cursor enters;<\/p>\n<p>a, from the current cursor one character to enter;<\/p>\n<p>o, in the current row into the next row;<\/p>\n<p>I, from the current cursor jump to the beginning of the line and into the Bank;<\/p>\n<p>A, skip to the end and enter the Bank;<\/p>\n<p>O, in the Bank of the line to insert a row;<\/p>\n<p>r, to replace the current character;<\/p>\n<p>R, to replace the current character and move to the next character;<\/p>\n<p>number + G: jump to a specific row, such as 10G jumps to line 10, GG jump to the last line, gg jump to the first line;<\/p>\n<p>number + yy: copy current number of rows down, in any line can be pasted by p;<\/p>\n<p>number + dd: Cut down the number of rows currently in any line adhesive according to p;<\/p>\n<p>u: undo the last step of the operation;<\/p>\n<p>ctrl + r: to restore the previous step;<\/p>\n<p>ctrl + v: to enter visual block mode, the cursor moves up and down, select the content, press y copy selected content, at any position by pasting;<\/p>\n<p>Fast beginning of the line to add a comment #, move the cursor to select the line, then press I to the start position,<\/p>\n<p>press #, press ESC to exit<\/p>\n<p>#abrt:x:173:173::\/etc\/abrt:\/sbin\/nologin<br \/>\n#pulse:x:171:171:PulseAudio System Daemon:\/var\/run\/pulse:\/sbin\/nologin<br \/>\n#gdm:x:42:42::\/var\/lib\/gdm:\/sbin\/nologin<br \/>\n#gnome-initial-setup:x:993:991::\/run\/gnome-initial-setup\/:\/sbin\/nologin<br \/>\n:split?ctrl+w<\/p>\n<p>To view detailed help Vim, you can enter Vimtutor.<\/p>\n<p>5, line mode to save the file, find, property settings, replacement and other operations<\/p>\n<p>Enter the last line mode, ESC from insert into command mode, enter \ud83d\ude41 \/ or generally used to find, n from the look down, N from the look-up)<\/p>\n<p>Save: wq to save and exit, or x;<\/p>\n<p>Force Quit: q without saving the file content;!<\/p>\n<p>Display line numbers: set nu, if the default display line numbers, you will need to modify the home directory vimrc file or \/ etc \/ vimrc, no file is created, insert a row set nu;<\/p>\n<p>Switching specified line: direct input line number;<\/p>\n<p>Replace: 1,$s \/old \/new \/g Replace globally all<\/p>\n<p>m, ns \/old \/new \/g replace m row to match the contents of all n rows, on behalf of the current line, $representatives last line,<br \/>\n$ -. 1 represents the penultimate line, (1, $) can also be used to replace%,<br \/>\nThey are expressed full text. If you want to match the contents of which have special characters such as \/, *, etc., to be added in front of the escape character \\<\/p>\n<p>You can use the s # old # new #, using the # separator, the special characters do not need to escape;<\/p>\n<p>Find backslash below, if you want to ignore the case, look at the back of the content plus \\ c, for example: \/ servername \\ c<\/p>\n<p>study notes 5&#8211; manage users and user groups<\/p>\n<p>[root@RHEL7HARDEN \/]# passwd &#8211;help<br \/>\nUsage: passwd [OPTION&#8230;] &lt;accountName&gt;<br \/>\n-k, &#8211;keep-tokens keep non-expired authentication tokens<br \/>\n-d, &#8211;delete delete the password for the named account (root only)<br \/>\n-l, &#8211;lock lock the password for the named account (root only)<br \/>\n-u, &#8211;unlock unlock the password for the named account (root only)<br \/>\n-e, &#8211;expire expire the password for the named account (root only)<br \/>\n-f, &#8211;force force operation<br \/>\n-x, &#8211;maximum=DAYS maximum password lifetime (root only)<br \/>\n-n, &#8211;minimum=DAYS minimum password lifetime (root only)<br \/>\n-w, &#8211;warning=DAYS number of days warning users receives before password expiration (root only)<br \/>\n-i, &#8211;inactive=DAYS number of days after password expiration when an account becomes disabled (root only)<br \/>\n-S, &#8211;status report password status on the named account (root only)<br \/>\n&#8211;stdin read new tokens from stdin (root only)<\/p>\n<p>Help options:<br \/>\n-?, &#8211;help Show this help message<br \/>\n&#8211;usage Display brief usage message<br \/>\n[root@RHEL7HARDEN \/]#<\/p>\n<p>[root@RHEL7HARDEN \/]# chage &#8211;help<br \/>\nUsage: chage [options] LOGIN<\/p>\n<p>Options:<br \/>\n-d, &#8211;lastday LAST_DAY set date of last password change to LAST_DAY<br \/>\n-E, &#8211;expiredate EXPIRE_DATE set account expiration date to EXPIRE_DATE<br \/>\n-h, &#8211;help display this help message and exit<br \/>\n-I, &#8211;inactive INACTIVE set password inactive after expiration<br \/>\nto INACTIVE<br \/>\n-l, &#8211;list show account aging information<br \/>\n-m, &#8211;mindays MIN_DAYS set minimum number of days before password<br \/>\nchange to MIN_DAYS<br \/>\n-M, &#8211;maxdays MAX_DAYS set maximim number of days before password<br \/>\nchange to MAX_DAYS<br \/>\n-R, &#8211;root CHROOT_DIR directory to chroot into<br \/>\n-W, &#8211;warndays WARN_DAYS set expiration warning days to WARN_DAYS<\/p>\n<p>root@RHEL7HARDEN \/]# useradd &#8211;help<br \/>\nUsage: useradd [options] LOGIN<br \/>\nuseradd -D<br \/>\nuseradd -D [options]<\/p>\n<p>Options:<br \/>\n-b, &#8211;base-dir BASE_DIR base directory for the home directory of the<br \/>\nnew account<br \/>\n-c, &#8211;comment COMMENT GECOS field of the new account<br \/>\n-d, &#8211;home-dir HOME_DIR home directory of the new account<br \/>\n-D, &#8211;defaults print or change default useradd configuration<br \/>\n-e, &#8211;expiredate EXPIRE_DATE expiration date of the new account<br \/>\n-f, &#8211;inactive INACTIVE password inactivity period of the new account<br \/>\n-g, &#8211;gid GROUP name or ID of the primary group of the new<br \/>\naccount<br \/>\n-G, &#8211;groups GROUPS list of supplementary groups of the new<br \/>\naccount<br \/>\n-h, &#8211;help display this help message and exit<br \/>\n-k, &#8211;skel SKEL_DIR use this alternative skeleton directory<br \/>\n-K, &#8211;key KEY=VALUE override \/etc\/login.defs defaults<br \/>\n-l, &#8211;no-log-init do not add the user to the lastlog and<br \/>\nfaillog databases<br \/>\n-m, &#8211;create-home create the user&#8217;s home directory<br \/>\n-M, &#8211;no-create-home do not create the user&#8217;s home directory<br \/>\n-N, &#8211;no-user-group do not create a group with the same name as<br \/>\nthe user<br \/>\n-o, &#8211;non-unique allow to create users with duplicate<br \/>\n(non-unique) UID<br \/>\n-p, &#8211;password PASSWORD encrypted password of the new account<br \/>\n-r, &#8211;system create a system account<br \/>\n-R, &#8211;root CHROOT_DIR directory to chroot into<br \/>\n-s, &#8211;shell SHELL login shell of the new account<br \/>\n-u, &#8211;uid UID user ID of the new account<br \/>\n-U, &#8211;user-group create a group with the same name as the user<br \/>\n-Z, &#8211;selinux-user SEUSER use a specific SEUSER for the SELinux user mapping<\/p>\n<p>[root@RHEL7HARDEN \/]# usermod &#8211;help<br \/>\nUsage: usermod [options] LOGIN<\/p>\n<p>Options:<br \/>\n-c, &#8211;comment COMMENT new value of the GECOS field<br \/>\n-d, &#8211;home HOME_DIR new home directory for the user account<br \/>\n-e, &#8211;expiredate EXPIRE_DATE set account expiration date to EXPIRE_DATE<br \/>\n-f, &#8211;inactive INACTIVE set password inactive after expiration<br \/>\nto INACTIVE<br \/>\n-g, &#8211;gid GROUP force use GROUP as new primary group<br \/>\n-G, &#8211;groups GROUPS new list of supplementary GROUPS<br \/>\n-a, &#8211;append append the user to the supplemental GROUPS<br \/>\nmentioned by the -G option without removing<br \/>\nhim\/her from other groups<br \/>\n-h, &#8211;help display this help message and exit<br \/>\n-l, &#8211;login NEW_LOGIN new value of the login name<br \/>\n-L, &#8211;lock lock the user account<br \/>\n-m, &#8211;move-home move contents of the home directory to the<br \/>\nnew location (use only with -d)<br \/>\n-o, &#8211;non-unique allow using duplicate (non-unique) UID<br \/>\n-p, &#8211;password PASSWORD use encrypted password for the new password<br \/>\n-R, &#8211;root CHROOT_DIR directory to chroot into<br \/>\n-s, &#8211;shell SHELL new login shell for the user account<br \/>\n-u, &#8211;uid UID new UID for the user account<br \/>\n-U, &#8211;unlock unlock the user account<br \/>\n-Z, &#8211;selinux-user SEUSER new SELinux user mapping for the user account<\/p>\n<p>[root@RHEL7HARDEN \/]# useradd test1<br \/>\n[root@RHEL7HARDEN \/]# mkdir \/home\/test<br \/>\nroot@RHEL7HARDEN \/]# usermod -d \/home\/test1 test<br \/>\nusermod: user &#8216;test&#8217; does not exist<br \/>\n[root@RHEL7HARDEN \/]# cp -a \/etc\/skel\/.[^.]* \/home\/test\/<br \/>\n[root@RHEL7HARDEN \/]# groups test1<br \/>\ntest1 : test1<br \/>\nusermod -a -G mohan test1<\/p>\n<p>usermod -g<\/p>\n<p>[root@RHEL7HARDEN \/]# gpasswd &#8211;help<br \/>\nUsage: gpasswd [option] GROUP<\/p>\n<p>Options:<br \/>\n-a, &#8211;add USER add USER to GROUP<br \/>\n-d, &#8211;delete USER remove USER from GROUP<br \/>\n-h, &#8211;help display this help message and exit<br \/>\n-Q, &#8211;root CHROOT_DIR directory to chroot into<br \/>\n-r, &#8211;delete-password remove the GROUP&#8217;s password<br \/>\n-R, &#8211;restrict restrict access to GROUP to its members<br \/>\n-M, &#8211;members USER,&#8230; set the list of members of GROUP<br \/>\n-A, &#8211;administrators ADMIN,&#8230;<br \/>\nset the list of administrators for GROUP<br \/>\nExcept for the -A and -M options, the options cannot be combined.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>study notes 2<\/p>\n<p>&#8212; command line file<\/p>\n<p>1, create and delete files<\/p>\n<p>Create a file touch xxxx<\/p>\n<p>touch -t 20151225 create a file and specify time properties<\/p>\n<p>rm xxx delete the file<\/p>\n<p>rm -rf forced to delete files<\/p>\n<p>2. Create a directory and delete the directory<\/p>\n<p>mkdir -p xxx\/yyy recursively create directories;<\/p>\n<p>rmdir xxx delete [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[73],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7293"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7293"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7293\/revisions"}],"predecessor-version":[{"id":7294,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7293\/revisions\/7294"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7293"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7293"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7293"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}