Linux Basic Command Ⅱ

Source: Internet
Author: User
Tags printable characters

1 environment variable Path


1 Environment variables

The variables of Linux can be divided into two categories: environment variables and local variables

environment variables, or global variables, exist with all the shells, and when you log into the system, you have the corresponding system-defined environment variables. The environment variables of Linux are inherited, that is, the child shell inherits the environment variables of the parent shell. \

Local variables, variables in the current shell, it is clear that the local variables must contain environment variables. The non-environment variables of local variables of Linux are not inherited.

The small cases are as follows:

1, [[email protected] chenhaiying]# echo $PATH (echo= display, print out. The $ symbol indicates that followed by a variable)/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin2, [[email protected] ~]# path= $PATH:/tmp/ (add variable, temp.) [[email protected] ~]# vi/etc/profile (to permanently use the variable that you want to add in this configuration file)

2 CP Command

1, cp= copy2, cp-a source destination (cp-a commonly used) 3, cp-i (if the target file exists, the overwrite will be prompted whether to overwrite the common) 4, cp-r Copy the directory when the note needs to add/5, Cp-p (copy the properties of the file is copied together, Backup often used) 6, tree!$ The last parameter of the previous command

Small trials:

[Email protected] tmp]# cp/root/1.txt. Copy the file back to local and add some. [[email protected] ~]# cp-a/etc/passwd//tmp/chypasswd (properties and permissions will not change when copying) [[email protected] ~]# cp-r/tmp/chylinux//tmp/ch y1/Copy directory needs to add/[[email protected] ~]# cp-r/tmp/chylinux//tmp/chy1/(copy directory when the destination directory is the source directory will be placed in the target directory down) [[email protected] ~]# tre E! $tree/tmp/chy1//tmp/chy1/├──1.txt├──2.txt└──chylinux├──1.txt└──2.txt5 directories, 0 files

3 MV Command

[[email protected] ~]# mv 1.txt chy.txt  ( In one directory, the MV is the name of the change) [[email protected] ~]# mv /root/chy/ /tmp/chy/  (moving the directory to another directory, If no directory is changed after the name is moved, if there is the same directory, the original directory is moved to the target directory) [[EMAIL PROTECTED] ~]# MV /ROOT/1.TXT /ROOT/2. txt /root/3.txt /tmp/  (move a list of directories) [[email protected] ~]# mv -v *.txt  /tmp/  (mv -v  print Mobile information) "A.txt"  ->  "/tmp/a.txt" "C.txt"  ->  "/tmp/c.txt" " D.txt " -> "/tmp/d.txt "mv -uv *.txt /tmp/  (mv -u  can be updated when the source file is newer than the target file) [[ email protected] ~]# /usr/bin/mv -bv *.txt /tmp/  (mv -bv  is the meaning of the backup-) "A.txt"  ->  "/tmp/a.txt"   (Backup: "/tmp/a.txt~") "B.txt"  ->  "/tmp/b.txt"   (Backup: "/ tmp/b.txt~ ")" C.txt " -> "/tmp/c.txt "  (Backup:"/tmp/c.txt~ ") 

 4, document view Cat_more_less_head_tail

[[email protected] tmp]# cat chy.txt  viewing files [[Email protected] tmp]# tac  passwd  (Flashback view, Common) [[email protected] ~]# cat -a 3.txt111$222$  (-A: Display non-printable characters, end of line display "$";) [[EMAIL PROTECTED] TMP]# CAT -N PASSWD (cat -n  display line number)      1  root:x:0:0:root:/root:/bin/bash     2   bin:x:1:1:bin:/bin:/sbin/nologin     3  daemon:x:2:2:daemon:/ sbin:/sbin/nologin[[email protected] tmp]# more passwd  (one screen, one screen view   return down to see  ctrl+b   on screen) [[EMAIL PROTECTED] TMP]# LESS PASSWD (Support arrow key view,ctrl+b ,ctrl+f  down   After exiting the  /can be highlighted, press n down will look for whether there is a view of the content, n up to see if there is a view of the content)? The difference is with/to the different G-positioning line tail    g positioning the beginning of the   [[email  protected] tmp]# head -n 2 passwd  View the first two lines [[email protected] tmp]#  tail -n 2 passwd   (view the latter two lines) [[email protected] tmp]# tail -f passwd  (view the dynamic file, Read more about the log)

5  file or directory permissions chmod 

[[email protected] ~]# ls -l  View column Permissions total usage  12-rw-------.  1 root root  1695 5 Month   26 03:22 anaconda-ks.cfg-rw-r--r--  1 root root     0 6 Month    7 06:01 A.TBTRWX representative means r= readable  w= writable  x= Can be performed from the second position every three divided into three paragraphs, the first paragraph belongs to the owner, the second paragraph is divided into groups, the third section of other [[email protected] ~]# r=4 w=2 x=1  Permissions can also be used to indicate [[email protected] ~]# chmod =change mode  change permissions [[email protected]  ~]# mkdir 123  newly created file View permissions after discovering a bit, this point is subject to the &nbsp of SELinux, and when SELinux is closed it is not a bit when it is created. [[email protected] ~]# ls -l[[email protected] ~]# chmod -r 744  chy chmod -R  Batch Create permissions, the directory and the following subdirectories are given the same permissions. [[email protected] ~]# chmod u=rw,g=r,o=r chy  (Another way to change permissions) [[email protected ] ~]# chmod a+x chy  (a+x {a-x}  will be the owner, belong to the group, others are added {reduced}x rightsLimit. Similarly, u,g,o can increase or decrease permissions.

6 change owner and owning group Chown

[[Email protected] ~]# change owner

[[email protected] ~]# chown chy chy Change the owner of Chy

[[email protected] ~]# chgrp =change Group changed to groups)

[[email protected] ~]# chown chy:chy chy change owner and owning group

[Email protected] ~]# chown-r chy:chy/tmp/(-R recursive meaning. Is that the owner of this directory has the same permissions as the owning group)


7 Umask

[[email protected] ~]# umask0022[[email protected] ~]# umask Directory calculation = (rwxrwxrwx-rwx-w--w-) =---r-xr-x ( With 777-Go umask permissions equal to the proper permissions, directory must have execute permission) [[email protected] ~]# umask file algorithm = (rw-rw-rw-----w-r--) = rw-r--r--(with 666 minus umask permissions equals the proper file permissions)


8 Hiding Permissions Lsattr_chattr

[[email protected] ~]# chattr +i 1.txt set hidden permissions for a permission. (after setting the hidden file, cannot delete, cannot be modified, cannot move, but can copy,copy the past does not have the I permission) [[email protected] ~]# lsattr 2.txt View permissions have hidden permissions. [[email protected] ~]# chattr-i 1.txt (minus i permissions) [[email protected] ~]# chattr +a 1.txt (after appending, you can also touch this file, but cannot delete, Cannot move can copy but copy past without I permission) [[email protected] ~]# chattr-a 1.txt[[email protected] ~]# LSATTR-R/tmp (View/tmp all) [[Email PR Otected] ~]# lsattr-d/tmp (-D view the file itself) [[email protected] ~]# LSATTR-A/tmp (-A will list hidden files) chattr option Explanation: I: Do not alter the file or directory arbitrarily. A: Let the file or directory be used for additional purposes only (so that a file can only append data to it, but cannot be deleted)


Linux Basic Command Ⅱ

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.