File/Directory Management commands:
CD command is mainly to change the function of the directory
CD ~ Return to login directory
CD/return system root directory
Cd.. /or CD. Return to the top level directory
CD-Returns the directory that was last accessed
The PWD command is used to display the user's current path, directory
file content View :
Cat song.log: View Song.log file contents
Head S.log: View the first 10 lines of the contents of the S.log file
Head-n S.log: View the first 20 lines of S.log file contents
Tail S.log: View the 10 lines of the contents of the S.log file
Tail-n s.log: View the 20 lines of the contents of the S.log file
More S.log: View the contents of the S.log in the form of page flipping (press SPACEBAR to flip, not up)
Less s.log: View the contents of S.log in the form of a page turn (press the up and down keys to page up and down, press Q to exit)
To view files :
Basic syntax: Find find location Lookup parameters
Find. -name *java* Find files with Java characters in the current location
Find. -perm 777 find a file with a permission of 777 under the current location
Find/-user Ouyang finds files in the system that the user is Ouyang
Find. -type d look for files of type folder in the current location
Find parameters:
-name-perm-user-group-ctime-type-size
New :
mkdir [option] Dir
mkdir A: Create Directory folder A
Mkdir-p A/B/C/D: Create multiple directories under current directory
touch [option] filename
Touch a.txt: Create file A.txt
[[Email protected] ~]$ cd dir1[[email protected]ng dir1]$mkdirdir_1 dir_2 dir_3 #创建目录 [[email protected] dir1]$Touchfile_1 file_2 #创建文件 [[email protected] dir1]$Touch-D'4/4/18 00:00'file_3 #创建文件并改变时间戳 [[email protected] dir1]$ ll total dosage0DRWXRWXR-X.2Songshichao Songshichao6April5 +: +DIR_1DRWXRWXR-X.3Songshichao Songshichao -April5 +: ADIR2DRWXRWXR-X.2Songshichao Songshichao6April5 +: +DIR_2DRWXRWXR-X.2Songshichao Songshichao6April5 +: +dir_3-rw-rw-r--.1Songshichao Songshichao0April5 +: -File_1-rw-rw-r--.1Songshichao Songshichao0April5 +: -file_2-rw-rw-r--.1Songshichao Songshichao0April4 xx:xxFile_3
Rename:
Rename AAA BBB
Delete :
RM [option] File
R: Delete all contents of a directory when deleting a directory
F: Ignores subdirectories that do not exist in the deleted directory, and does not prompt the user when deleting
[Email protected] dir1]$RMFile_1
[Email protected] dir1]$ rmdir dir_2 #删除空白目录 [[email protected] dir1]$RMdir_3 #目录含有其他的目录或文件RM: Cannot delete"dir_3": is a directory [[email protected] dir1]$RM-RF dir_3 #删除目录及目录中的所有文件和子目录, to mate options R and F[[email protected] dir1]$ ll total dosage0DRWXRWXR-X.2Songshichao Songshichao6April5 +: +DIR_1DRWXRWXR-X.3Songshichao Songshichao -April5 +: ADir2-rw-rw-r--.1Songshichao Songshichao0April5 +: -file_2-rw-rw-r--.1Songshichao Songshichao0April4 xx:xxFile_3
Move :
mv FileName dir
FileName: File or directory name that needs to be moved
Dir: The position after the move and the file name, if the file specified by the parameter already exists, overwrite the existing file, if it does not exist, then move the file and rename it .
[[email protected] dir1]$ MV dir_1 dir2/ [[email protected] dir1]$ CD dir2[[email protected] dir2]$ ll total dosage 0 drwxrwxr -x 2 Songshichao songshichao 6 April 5 21 : 32 dir_ 1DRWXRWXR -x 2 songshichao songshichao 6 April 5 21 : 22 dir3
[Email protected] dir1]$ mkdir dir3
[Email protected] dir1]$ mv-i dir3 dir2/#覆盖文件
MV: Do you want to overwrite "Dir2/dir3"? Y
[Email protected] dir1]$ CD DIR2
[email protected] dir2]$ LL
Total dosage 0
Drwxrwxr-x. 2 Songshichao Songshichao 6 April 5 21:32 dir_1
Drwxrwxr-x. 2 Songshichao Songshichao 6 April 5 21:58 dir3
Copy :
CP [option] filename Directory
FileName: The source file to copy
Directory: Copy the new location of the file, and if this parameter is a new directory name, rename the file when you copy the file to a new location
[Email protected] dir2]$CP/home/songshichao/dir1/file_2./#复制到当前目录下 [[email protected] dir2]$CP/home/songshichao/dir1/file_2./file_2_1 #复制并重命名 [[email protected] dir2]$ ll total dosage0DRWXRWXR-X.2Songshichao Songshichao6April5 +: +DIR_1DRWXRWXR-X.2Songshichao Songshichao6April5 +: -Dir3-rw-rw-r--.1Songshichao Songshichao0April5 A: -file_2-rw-rw-r--.1Songshichao Songshichao0April5 A: ,File_2_1[[email protected] dir1]$CP-r/home/songshichao/dir1/dir2/home/songshichao/dir1/dir_2_1 #复制目录dir2到dir1, including subdirectories and files [[email protected] dir1]$ ll total dosage0DRWXRWXR-X.4Songshichao Songshichao AApril5 A: ,DIR2DRWXRWXR-X.4Songshichao Songshichao AApril5 A: -Dir_2_1-rw-rw-r--.1Songshichao Songshichao0April5 +: -file_2-rw-rw-r--.1Songshichao Songshichao0April4 xx:xxFile_3
To modify file properties :
Chgrp Modifying a group of files
CHGRP users l.log modify file L.log belong to user group
Chown Modify Owner
Chown Bin Install.log Modify the owner of the Install.log to bin
chmod Modify Permissions
Linux files have 9 basic permissions, namely OWENR, group, others three identities each have their own R, W, and X. If the permission character of the file is: "-rwxrwxrwx", these 9 permissions are three three groups, we can use the number to express the permission:
R->4
W->2
X->1
So, when the file permission is "-rwxrwx---", The score is:
Owner->4+2+1=7
Group->4+2+1=7
Others->0+0+0=0
At this point the file's permission number is 770.
If there is a file bashrc, the permission character is "-rwxrwxrwx", we need to change to "-rwxr-xr--", the calculated permission number is 754, so, execute the command:
- # chmod 754 BASHRC
There is also a way to change permissions. We know that the file has 9 basic permissions, respectively, the owner, group and others three identities each of the three permissions, we use U, G, O for three identities, with a (all) representing all identities, get the following table:
For example, we can set permissions for file BASHRC:
- # chmod U=rwx,go=rx BASHRC
That is, the user permission for both Rwx,group and others is RX.
If we want everyone to write to the file BASHRC, you can:
- # chmod A+w BASHRC
And if you want to remove the permissions, use-. For example, we remove all of the people's execution rights:
- # chmod A-x BASHRC
Basic operation of Linux files