Linux Learning Notes Lesson Four

Source: Internet
Author: User
Tags create directory

**************************************************

Mkdir,rmdir,rm,cp,mv,chown,chmod has the-v option visualization with alias hints to avoid hints with absolute paths

/bin/cp

/bin/mv

/bin/rm

/bin/chown

/bin/chmod

**************************************************



I. Directory-related commands (mkdir, RmDir, RM, CP, MV)

Ii. file-related commands (touch, Cat, TAC, rev, more, less, head, tail)

Third, file-related properties

Iv. Modifying Directory file permissions (CHOWN,CHMOD)

V. Related extensions (umask, file types)






I. Directory-related commands (mkdir, RMDIR,RM)

1. mkdir Create Directory

mkdir dir1 DIR2/TMP/DIR1/DIR2 can create multiple directories at once

Mkdir-p/dir1/dir1/dir1/dir1-p Creating a directory recursively

Mkdir-pv/tmp/123/123/123-v displaying information about the creation process

TREE-CLD 2/etc Color display two-level directory tree under/etc

2, rmdir can only delete non-empty directory

-P Recursive Delete,-v display delete process

Rmdir-pv/dir1/dir1/dir1 Dir1 Empty directory cannot have files

3, RM Delete file,-r Delete directory

which RM alias rm= ' Rm-i '

RM-RF JDFSJKDFLDSKF//Regardless of the file exists in the No, are deleted, do not prompt any error, easy to use but need caution

4. CP Copy File

-R Copy Directory

CP 123.tx/tmp/

Cp-r Dir1 Dir2

5. MV Move and rename

MV file1/tmp/move file1 to/tmp

MV File1/tmp/file2 move file1/tmp and rename to File2

Note:/bin/cp,/bin/rm,/bin/mv overwrite copy, delete, move or name without prompting


Ii. file-related commands:

1. Touch create file, or modify file time

Touch file1 file2 fiel3 Create multiple files at once

2. View files (Cat, TAC, rev, head, tail, more, less)

Cat/etc/inittab Viewing files normally

Tac/etc/inittab Portrait Reverse View File

Rev/etc/inittab Horizontal reverse order production See file

HEAD/ETC/PASSWD Display the first 10 rows by default

Head-20/etc/init.d/iptables Show Top 20 lines

Tail/etc/init.d/iptables default display tail 10 lines

TAIL-20/ETC/PASSWD is the same as Tail-n 20/etc/passwd

Tail-f/var/log/secure dynamic display of log files

Sed ' 5 ' p/etc/passwd shows line 5th. Later introduction

More/etc/protocols

Blank Space Downward flip screen

b Flip up the screen

Carriage return down one line

Q exit

Less/etc/protocols (j,k,g,g,ctrl+f/b,/,?)

CTRL + F: Page Down

CTRL + B: Page up

J: up One line

K: Line Down

/: Search down: n down, n upwards

? : Search up: n upwards, n down

G: Go to the last line

G: Jump to the first line


Iii. File and Directory properties

[Email protected] ~]# Ls-fa/root

./  .. /anaconda-ks.cfg. bash_history. bash_logout. Bash_profile bashrc. CSHRC install.log Install.log.syslog. ssh/. TCSHRC test/

-F View File properties,/directory, @ Soft link

[Email protected] ~]# ll/etc/

drwxr-xr-x .    2 root root   4096 3 month    9 10:56 alternatives

1. File type: D,-, c,l,b,s,p (Introduction later)

2. File permissions

3,. Centos5 not, related to SELinux. If it is +, it is associated with the ACL. Just to know.

4. There are several files using the same inode number

5. The owner and group of the file

6, the file size, the byte unit. -H

7. Time of Creation or change

8. File name

**********************************************

Ls-f view the file type. @ Soft Connect,/directory *

**********************************************


Iv. modification of file owners and permissions

1. Chown change the owner of the specified directory or file

-R recursively change all file directories under directory

Chown User1 1.txt

Chown:group1 1.txt

Chown user1:group1 1.txt:. All the same.

Chown User1.group1 1.txt

2. chmod Change Permissions

R=4, W=2,x=1

-R recursively change the directory itself and all permissions under directory changes

[Email protected] ~]# chmod u=r,g=w,o= 1.txt

-R---W----. 1 root root 0 March 10:09 1.txt

[Email protected] ~]# chmod u+rwx,g+rw,o+rx 1.txt

[Email protected] ~]# chmod 777 1.txt

3, Umask

[[email protected] ~]# umask default 0022
0022

[[email protected] ~]# umask 001 Modifying the default mask

Attention:

Mkdir,rmdir,rm,cp,mv,chown,chmod has the-v option visualization with alias hints to avoid hints with absolute paths

/bin/cp

/bin/mv

/bin/rm

/bin/chown

/bin/chmod


V. Related extensions (umask, file types)

1. linux File types

According to the contents of the document, it can be broadly divided into:

Plain text file (ASCII): This is the most file type in a UNIX system and is called a plain text file because the content is data that we can read directly, such as numbers, letters, and so on. The settings file is almost all of this file type. For example, using the command "Cat ~/.BASHRC" You can see the contents of the file (cat reads the contents of the file).

Binary (binary): as we mentioned in the GNU history, the system only knows and can execute binaries (binary file). Executable files in Linux (scripts, batch files in text mode, not counted) are in this format. For example, the command cat is a binary file.

data Format files: Some programs will read files in certain formats while they are running, and those files in a particular format can be called data files. For example, when a user logs on, Linux logs the login data in the/var/log/wtmp file, which is a data file that can be read by the last command. However, when using cat, garbled characters are read. Because it is a file that belongs to a special format.

1, D directory (directory) For example [drwxrwxrwx].

2, l connection file (link): Similar to Windows under the shortcut. For example [lrwxrwxrwx].

3. Device and device: Some files related to system peripherals and storage are usually concentrated in the/dev directory. It is usually divided into two types:

Block device file: Is the interface device that stores data for system access, in simple terms a hard disk. For example, the code for a hard drive is a file such as/dev/hda1. The first property is [b].

C-character (character) device file: An interface device for a serial port, such as a keyboard, mouse, and so on.

4, S socket (sockets): This kind of file is usually used in network data connection. We can start a program to listen to the client's requirements, and the client can communicate through the socket. This type of file is most often seen in the/var/run directory.

5, P Pipeline (FIFO, pipe): FIFO is also a special type of file, its main purpose is to solve multiple programs to access a file at the same time caused by errors. FIFO is the abbreviation for first-in-first-out (first-in, FIFO).

Using the "ls-al" command, you can simply determine the type of the file by judging the first attribute of each file. In addition to the device files are very important in the system files, it is best not to modify the outside (usually it will not let you modify), another interesting file is the connection file. If you often put your application on the desktop, you should know that there are so-called "shortcuts" under Windows. Similarly, you can simply treat a connection file under Linux as a shortcut to a file or directory. Sockets and piping files are difficult to understand because they are closely related to the process. In addition, the system description can be viewed through the man FIFO and man socket.


2, Umask calculation method

① is converted in binary mode:

First, the total permissions (directory 777, File 666) and Umask values are converted to 2, and then Umask, and then two 2 binary values to do and operations, the resulting binary value is converted to decimal, that is, the permission,

[Plain] View plaincopy

For example:

666=0110 0110 0110

umask=000=0000 0000 0000 Not Operation 1111 1111 1111

0110 0110 0110

1111 1111 1111

------------------------------

0110 0110 0110=666

umask=011=0000 0001 0001 not operation 1111 1110 1110

0110 0110 0110

1111 1110 1110

------------------------------

0110 0110 0110=666

umask=022=0000 0010 0010 not operation 1111 1101 1101

0110 0110 0110

1111 1101 1101

------------------------------

0110 0100 0100=644

umask=033=0000 0011 0011 not operation 1111 1100 1100

0110 0110 0110

1111 1100 1100

------------------------------

0110 0100 0100=644

② the second method is to direct the permission number represents the field to write out, to compare and judge, relatively simple and intuitive, applicable to know umask and then calculate the permissions of the questions, and for giving permission and then calculate Umask the first method can be reference:

[Plain] View plaincopy

umask=000

(rw-rw-rw-)-(---------) =rw-rw-rw-=666

umask=011

(rw-rw-rw-)-(-----x--x) =rw-rw-rw-=666

umask=022

(rw-rw-rw-)-(----w--w-) =rw-r--r--=644

umask=033

(rw-rw-rw-)-(----wx-wx) =rw-r--r--=644

umask=044

(rw-rw-rw-)-(---r--r--) =rw--w--w-=622

umask=055

(rw-rw-rw-)-(---r-xr-x) =rw--w--w-=622


This article is from the Linux Learning Notes blog, so be sure to keep this source http://genxin.blog.51cto.com/665191/1621357

Linux Learning Notes Lesson Four

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.