02- file operations and directory management

A, Linux basic file attributes

  Linux system is a typical multi-user system, users have different permissions.

  In Linux use in or ll ls -l command to display the file attributes, and user and group file belongs:

ll
或
ls -l

 

 

 

 

 

 

   bin first attribute file with the " d " represents, " d " in Linux representation that the file is a directory file. (The first character represents the file is a directory, file, files or hyperlinks, etc.).

  

When as [d] is a directory 
when is [ - ] is a file; 
if [l] is expressed as document links (link file); 
if [b] indicates that the interface device is a device for storage of the files inside (may random access unit); 
if [c] is expressed as a file inside the device serial port device, such as a keyboard, a mouse (one reading device).

A group of three, and are [ rwx ] The combination of three parameters:

[R] Representative read (Read) 
[W] Representative write (Write) 
[X] Representative executable (Execute) 

three permission position is not changed if there is no authority, there will [ -]

 

 Digital is the meaning of the expression:

  Bit 0 determine file types, positions 1-3 to determine the owner (owner of the file ) have access to the file. The first 4-6 determine is a group (with the owner's user group) have access to the file, 7-9 bits determine other users have access to the file.

 

 

   There owner read, write, execute permissions; other users of the same group owner has readable and executable permissions; other users can read and executable permissions. root user has full privileges.

Change file attributes:

  1, change the file belongs to the group:

chgrp [- R] is a group filename

 -R: recursive change the file belongs to the group, that is, change is a group of files in a directory, if coupled with -R parameter, then all the files in that directory will belong to the group change.

  2, change the file owner, you can also change the file belongs to the group at the same time:

chown [-R] owner name of the file name 
chown [ -R & lt] owner name: name of the file name is a group

For example: to enter the / root directory (~) will install.log owner changed bin this account:

 cd ~
 chown bin install.log
 ls -l

-rw-r--r--  1 bin  users 68495 Jun 25 08:53 install.log

The intall.log owner changed root :

 chown root:root install.log
 ls -l

-rw-r--r--  1 root root 68495 Jun 25 08:53 install.log

  3, change the file nine attributes:

  Character file permissions is: " -rwxrwxrwx " nine permissions are three groups of three. May use digital rights to represent each, the score for each permissions table below:

r:4
w:2
x:1

  Each identity (owner / group / others) of each of three permission (r / w / x) score is required additive, for example, when authority is: [-rwxrwx ---] score is:

owner = rwx = 4+2+1 = 7
group = rwx = 4+2+1 = 7
others= --- = 0+0+0 = 0

The authority digital file is 770 . Command to change permissions chmod syntax is as follows:

chmod [-R] xyz file or directory
xyz: is the digital rights attribute type just mentioned, the attribute value is added to rwx.
-R: recursive (recursive) continues to change, that is, together with all files in subdirectories change

For example: .bashrc file permissions:

 ls -al .bashrc

-rw-r--r--  1 root root 395 Jul  4 11:45 .bashrc

 chmod 777 .bashrc
 ls -al .bashrc

-rwxrwxrwx  1 root root 395 Jul  4 11:45 .bashrc

There is another set permissions:

The file permissions to  -rwxr-XR,  , may be used chmod u = rwx, g = rx , o = r filename set: 

touch test1 // create test1 file 
 LS -al test1 // View test1 default permissions

 -rw-r - r-- 1 root root 0 Nov 15 10:32 test1 

 chmod U = rwx, G = rx, O = r test1 / / modify authority test1 
 LS - Al test1

 -rwxr the root-XR, the root. 1 0 15-Nov 10:32 test1

For example, to remove all of the people of executable permissions, then:

chmod  a-x test1
ls -al test1

-rw-r--r-- 1 root root 0 Nov 15 10:32 test1

Two, Linux file and directory management

    • Absolute path:
      the wording path from the root directory / write from, for example : / usr / share / doc directory.
    • Relative path:
      writing path, not by / write from, for example, the / usr / share / doc you want to / usr / share / man when the bottom, can be written as: cd ../man This is the wording of a relative path.

Common command processing directory:

ls: List directory 
cd: Change directory 
pwd: displays the current directory 
mkdir: create a new directory 
rmdir: delete an empty directory 
cp: copy a file or directory 
rm: remove a file or directory 
mv: move files and directories, or modify the name of the file and directory

Need help using a man to use a document, for example:

man cp

1, ls (list directory)

ls -al all files in this directory are listed in the file name # to view and permissions (including hidden files)
- A: All of the documents, together with (. Is the beginning of the file) file lists together to hide the (common)
 - D: List only the directory itself, instead of listing the file data (commonly used) in the directory
 -l: data string length List, comprising attribute data file permissions, and the like; (common)

2, cd (change directory) (Change Directory):

 cd [a relative or absolute path]
.. cd
 # represents the current go to the parent directory

3, pwd (shows the current directory)

pwd [-P]
Plus pwd -P the option will not display the data link file, but the correct full path ah!

4, mkdir (create a new directory)

mkdir [-mp] directory name
- m: Oh permissions profile! Direct configuration, do not need to see the default permissions (umask) face ~
 -p: help you directly to the required directory (containing the parent directory) recursively create up! 
# Mkdir Test // mkdir - m 711 test2 // mkdir -p test1 / test2 / Test3 / Test4

5, rmdir (remove empty directories)

rmdir [-p] directory name
-p: together with upper level "empty" directory is also deleted together

Note that this rmdir can only delete empty directories, you can use the rm command to remove a non-empty directory.

6, cp (copy the file or directory)

 cp [-adfilprsu] source file (source) of the target gear (Where do you want)
-a: equivalent - pdr meaning, as pdr refer to the following instructions; (common)

 - D: If the source file is a link file attribute (link file), link file attribute is copied rather than the file itself;

 - F: is forced (force) meaning, if the target file already exists and can not be turned on, and then try to remove once;

 - i: If the target file (destination) already exists in the coverage will be asked to operate the (common)

 - l: Hard-links (hard link) to create a link file, rather than copy the file itself;

 - P: attribute file copy together with the past, instead of using the default attributes (common backup);

 - R & lt: recursively continuous replication, for copying directories; (common)

 - S: copy the files become symbolic link (symbolic link), namely "shortcut" files;

 -u: If the destination before upgrading older than the source destination!

Example: use root identity of the root . Directory under bashrc copied to / tmp under, and named bashrc

~ CP / .bashrc / tmp / bashrc 
 CP -i ~ / .bashrc / tmp / bashrc 

CP: Overwrite ` / tmp / bashrc ' n-<== n-does not cover, y cover?

7, rm (remove file or directory)

 rm [-fir] file or directory
- f: is the force of meaning, ignore the file does not exist, no warning message;
 - i: interactive mode, before deleting the user will be asked whether the action
 -r: recursive delete ah! The most commonly used in the directory deleted! This is a very dangerous option! ! !

The best plus -i option will take the initiative to ask Oh, avoid deleting the wrong file name! (Deleted before each plus -i ).

8, mv (move files and directories, or modify the name)

mv [- FIU] Source Where do you want 
mv [Options] source1 source2 Source3 .... Directory

 - f: Force mandatory sense, if the target file already exists, but will not be asked directly cover;
 - i: If the target file (destination) already when there is, it will ask whether to overwrite!
-u: If the destination file already exists, and the source is relatively new, will upgrade (update)

For example: copy a file, create a directory, move the file to the directory:

cd /tmp
cp ~/.bashrc bashrc
mkdir mvtest
mv bashrc mvtest

The renamed file name:

etc. mvtest mvtest2

Linux file contents View

cat from the first line displays the file contents 
tac beginning to show from the last row, you can see the tac is cat written backwards! 
nl when displayed, take the opportunity to output line number! 
more page by page display file contents 
less and more similar, but better than more, he can move forward flip! 
Look at the first few lines head 
tail look tail lines
CAT [- AbEnTv]
-A: the equivalent - VET of integration options to list some special characters and not just blank; - b: lists the line number, line number only done for non-blank line display, blank lines are not marked lines number! - E: The end of the broken line shown byte $; -n: print line number, there will be a blank line together with the line number, and - the option b different; -T: The [Tab] button to ^ the I displayed ; -v: list some do not see the special characters
NL [- BNW] File

 - B: specified line number specified manner, there are mainly two:
 -ba: indicates whether the line is empty, also lists the line number (similar CAT - n-);
 - BT: if available row, the row is not empty lists the line number (the default);
 - n-: List line number indicated method, there are three:
 - n-LN: row number is displayed in the far left of the screen;
 - n-RN: the line number in the far right column of his own show, and do not add 0;
- the n-rz: the line number in the far right column of his own show, and add 0;
 -w: the number of bits occupied by the line number field.
More / etc / man_db.config 

spacebar (space): on behalf of a down turn; 
the Enter: turned down on behalf of "line";
 / string: this represents the content displayed them down search for "string" this keyword; 
: f: immediately shows the file name and line number currently displayed; 
q: representatives leave more immediately, no longer displays the contents of the file. 
b or [Ctrl] -b: representatives back flip, but this action only useful for files on the pipeline useless.
less / etc / the man.config 

blank keys: Scroll down one; 
[PageDown]: Scroll down one; 
[PageUp]: turning up one page;
 / string: down search "string" of; 
? string: up search 'string' of; 
the n-: before repeating a search (and / or related?!) 
N: the reverse of a search before repeating (and / or related?!) 
q: leave less of this program;
head - [ n-Number] file 
head -n 20 in the /etc/man.config # front display 20 lines
 
-n: followed by the number representing the meaning of the display lines
tail [- n-Number] file 
tail -n 20 / etc / the man.config 

displays the last 20 lines, by default, display the last ten lines.

Guess you like

Origin www.cnblogs.com/lishuntao/p/11780302.html