Linux Common Commands (3)-File and directory management __linux

Source: Internet
Author: User
Tags chmod file copy gz file mkdir file permissions
(1), Linux file permissions and directory configuration
Linux files are divided into three identities owner, group, others. Three types of permissions read, write, execute
Drwxr-xr-x 1 root root 4230 2012-09-12 17:21 jdk-7u7
Corresponding file permission connection number user group user file size last Modified Date file name
Where [d] is represented as a directory
[-] is represented as a file
The file type and permissions three are one group, a total of three groups, where the first group is the file owner permission, the second group is the user group permissions, the third group is the other user rights, each group has [RWX] three parameter combinations. [R] stands for read, [W] is written, [x] represents an executable if there is no permission, it is [-], or it can be r:4 with a digital table W:2 x:1
Changing file properties and Permissions
CHGRP: Changing file-owned user groups Chgrp [-r] Users Install.log [-r] represents recursion, including all files and directories under subdirectories
Chown: Change file owner Chown [-R] Oracle:oracle Install.log
chmod: Changing the identity and permissions of file permissions needs to be cumulative, such as [-rwxrwx---],
Corresponds to Owner = rwx = 4+2+1 = 7
Group = RWX = 4+2+1 = 7
others =---= 0+0+0 = 0
So the permission number is 770.
chmod [-R] 770 files and directories
Increase and removal of permissions
For example, to add an executable permission
chmod a+x files and directories, plus executable permissions for all users, empathy chmod a-x Remove executable permissions for all users
Available options [A,o,g,u]

(2), File and directory creation, delete, find, copy, paste,
Number of #ls |wc-l statistics files and directories
#pwd-P. Displays the current directory (path), [P] shows the correct file, not the path to the connection file (shortcuts inside windows)
#mkdir-M 777 test1. Create a new directory and give this directory 777 permissions.
#mkdir-P TEST1/TEST2 directories can be created only one layer by default, plus the [P] system automatically creates TEST1,TEST1/TEST2
#rmdir-P Test1/test2. The default can only be one layer to delete the directory, and the directory must be empty, [P] The system will delete multiple layers at once. If the deleted directory is not empty, you need to use the following command.
#rm-R test2. Delete all items in the directory.
#rm-RF test2. Delete all items in the directory including the Test2 directory.
#rm-RF! (Rbeijing.mid | RBEIJING.MIF) These two commands are combined to delete files other than Rbeijing.mid and RBEIJING.MIF.
#ls | Xargs-n rm-fr ls Delete a lot of trivial files
#cp-a/var/test1/var/test2 copy files test1 to test2. [A] copies the source and destination data, and the permissions and identity times are exactly the same as the current user. [R] is a directory that can be replicated. [i] ask the user if the file copy already exists is overwritten
#scp Remote File copy
For example, to copy the current file to another host on the remote, you can command the following.
#scp/home/daisy/full.tar.gz Root@
If you want to reverse the operation, it is also easy to copy the files from the remote host to the current system.
#scp root@/full.tar.gz home/daisy/full.tar.gz
#cat-N test to view the contents of the file, [n] shows the line number.
Find test.pdf files #find-name test.pdf
#find/trs-name Protect Find all protect directories in TRS directory
-type find a file of a certain type
B-block device files.
C-Character device files.
P-pipe file.
L-Symbolic link file.
F-Normal files.
# find-type D Lookup Directory
#mv move files/or rename commands
MV 1.txt desfile to move 1.txt files into the Desfile directory, similar to cutting
MV 1.txt 2.txt name 1.txt file 2.txt
#dd If=1.txt of=2.txt copies 1.txt of content into 2.txt text files and supports block copies
#grep find text in text
-C: Only the count of matching rows is output.
-N: Displays matching rows and line numbers.
-V: Find rows that do not contain a match
Like what:
$ grep ' test ' d* #显示所有以d开头的文件中包含 the row of test.
$ GREP-VN "Data.doc" #输出所有不包含48的行
$ grep-i "AB" Data.doc #输出所有含有ab或Ab的字符串的行
$ grep–e "ABC|EFG" filename//Find string containing ABC or EFG from file contents
$grep "17071" 20120406.txt | grep "2012-04-06 06:28:08" | grep "Word2"//find rows that meet both 17071,2012-04-06 06:28:08, word2 three strings
-N Line number specifies the number of rows to display per screen
The + line number starts at the specified line number
1. To display the last ten lines of the notes file, enter:
Tail notes
2. To specify the number of rows to begin reading from the end of the Notes file, enter:
Tail-n notes
Number of statistics files #wc-L Catalog
-C Statistics the number of bytes.
-L statistic line count.
-W counts the number of words.
Archive and File System packaging compression

(3), archive and file system packaging compression
A, compression instructions
Under Linux, compressed files have *.tar extensions, *.tar.gz,*.gz
*.GZ gzip program compressed file;
The data packaged by the *.tar tar program has not been compressed;
*.tar.gz Tar program packaging files, and did a compression;
*.tgz Tar package compressed files.

b, packing instructions
#tar-CVF File.tar File//Package
#tar-cvzf file.tar.gz File//package and compress
TAR-CVFZ 05.tgz/mnt/ctb/data/traffic/backup/2014/05//package and compress
#tar-XVF eclipse-jee-juno-linux-gtk.tar.gz//Decompression Pack
Optional parameters [C] Create a new archive
[v] verbosely list files processed, process output related information
[F] Use archive file or device archive, compressed file name
[z]--gzip,--gunzip,--ungzip filter the archive through GZIP, compressed format

[x] Extract files from the archive to extract the file from the archive

Related Article

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: 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.