Related command tutorials about Linux file management

巴扎黑
Release: 2017-08-02 16:03:27
Original
1645 people have browsed it

After understanding the background knowledge of Linux file management After that, we can learn some commands to manage our files.

File operation related

There are some commands that can help us "prun" the file tree we saw before.

$touch a.txt

If a.txt does not exist, generate a new empty document a.txt. If a.txt exists, only the time information of the document is changed. (This command is not actually widely used, but it can help us create an empty file to experiment with the following operations)

$ls .

is the abbreviation of list, lists all the file names in the current directory

##$ls -l a.txt

List file details

$cp a.txt b .txt

cp is the abbreviation of copy, used to

copy files. In the working directory, copy a.txt to the file b.txt##$cp a.txt ..

Copy a.txt Copy a.txt to the parent directory

##$mv a.txt c.txt

mv is the abbreviation of move, used to move

files. Move a.txt to c.txt (equivalent to rename)


$mv c.txt /home/vamei

Move c.txt to the /home/vamei directory


##$rm a.txt


#rm is the abbreviation of remove, used for
delete
document. Delete a.txt


$rm -r /home/vamei


Delete the entire sub-file system from /home/vamei downwards. -r means recursive, which refers to repeated deletion operations. The /home/vamei folder is empty, and then the /home/vamei folder itself is deleted.


(Programmers are always interested in this command, $rm -rf / It will delete the entire file tree. The purpose of f is to tell rm to just go ahead and not confirm again... Under normal circumstances, no one will use this command)


$mkdir /home/vamei/good

Create a new directory

##$rmdir /home/vamei/good

Delete an empty directory

#File permission related

$chmod 755 a.txt

(You must be the owner of the file a.txt to run this command. Or run this command as a super user by $sudo chmod 755 a.txt.)

#change mode Change the read, write and execution permissions of a.txt. Remember that each file has nine-bit read, write, and execute permissions (see Linux file management background knowledge), and is divided into three groups, corresponding to the owner, users in the owner group, and all other users ( other). Here, too, we have three numbers, 755, corresponding to three groups. 7 is assigned to the owner, 5 to the owning group, and the last 5 to other users. Linux regulations: 4 means the right to read, 2 means the right to write, and 1 means the right to execute. The 7 we see is actually 4 + 2 + 1, which means that the owner has three rights: read, write, and execute. (Think about what 5 means)

##At this time, run $ls -l a.txt, you should see that the nine-digit permissions have changed to rwxr-xr-x. According to your own needs, you can use, for example, 444, 744 instead of 755 to give the file different permissions.

$sudo chown root a.txt

change owner Change the owner of the file to the root user. This command requires superuser privileges to execute, so we add sudo before the command.


#$sudo chgrp root a.txt


change group Change the file’s owning group to the root group


Linux file name wildcard expression

##(wild card, also called filename pattern matching)

##The commands mentioned before, such as ls, mv, cp, can receive multiple parameters, such as:

##$ls -l a.txt b.txt c.txt

## will list all the information of these three files.

# Sometimes, we want to list the information of all files ending with .txt in the working directory. We can use the following method:


##$ls -l *.txt

## The writing method of
#*.txt uses Linux wildcard expressions. It is similar to regular expressions, but the syntax is different.


##Filename Pattern Matching Corresponding meaning


*                                                                                                                                                                 A character

[kl]                                                                                                                                                                                                                          ## [0-4] Number 0 to 4 characters in a

## [B-E] B to E characters A



#[^mnp]                                                                                                                                   

Linux will find file names that match the expression and then pass these file names as parameters to the command. Note that when using rm, be very careful. The following two commands only differ by one space, but the effects are very different:


##$rm * .txt

$rm *.txt

##The first command will delete all files in the current directory!

#Summary

##touch, ls , mv, cp, rm, mkdir, rmdir

#chmod, chown, chgrp

##wild card

The above is the detailed content of Related command tutorials about Linux file management. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!