Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Summary of commands related to Linux file management

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains the "Linux file management related command summary", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's train of thought slowly in depth, together to study and learn "Linux file management related command summary"!

$ls.

Is an abbreviation for list, listing all file names in the current directory

$ls-l a.txt

List the details of the file

$cp a.txt b.txt

Cp is short for copy and is used to copy files. In the working directory, copy a.txt to the file b.txt

$cp a.txt..

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

$mv a.txt c.txt

Mv is short for move and is used to move files. Move a.txt to c.txt (equivalent to renaming rename)

$mv c.txt / home/vamei

Move c.txt to the / home/vamei directory

$rm a.txt

Rm is an abbreviation for remove and is used to delete files. Delete a.txt

$rm-r / home/vamei

Delete the entire subfile system downward from / home/vamei. -r means recursive, which means that the / home/vamei folder is empty, and then delete the / home/vamei folder itself.

(programmers are always interested in this command, $rm-rf / it deletes the entire file tree. The purpose of F is to tell rm to do it without further confirmation. Under normal circumstances, no one should use this command.)

$mkdir / home/vamei/good

Create a new directory

$rmdir / home/vamei/good

Delete an empty directory

File permissions related

$chmod 755 a.txt

(you must be the owner of the file a.txt to run this command. Or run the command as a superuser as $sudo chmod 755 a.txt.)

Change mode changes the read, write, and execute permissions of a.txt. Remember that each file has nine read and write permissions (see Linux file management background), divided into three groups, corresponding to the owner (owner), the users in the ownership group (owner group), and all other users (other). Here, we also have three numbers, 755, corresponding to three groups. 7 is assigned to the owner, 5 is assigned to the ownership group, and the last 5 is assigned to other users. Linux stipulates that 4 has the right to read, 2 has the right to write, and 1 has 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 point, run $ls-l a.txt, and you should see that the nine-digit permissions become rwxr-xr-x. Depending on your needs, you can use, for example, 444744 instead of 755 to give files different permissions.

$sudo chown root a.txt

Change owner changes 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 changed the file ownership group to root group

Linux file name wildcard expression

(wild card, also called filename pattern matching)

The commands mentioned earlier, such as ls, mv, and cp, can accept multiple parameters, such as:

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

You can list all the information about these three files.

Sometimes, we want to list all the files in the working directory that end in .txt, in the following way:

$ls-l * .txt

* .txt is written using Linux wildcard expressions. It is similar to regular expressions, but the syntax is different.

Filename Pattern Matching corresponding meaning

* any number of arbitrary characters

? Any character

[kl] character k or character l

[0-4] one of the 0 to 4 characters of the number

[bmure] one of the b to e characters

[^ mnp] one character, this character is not mline ndiary p

Linux finds file names that match the expression and passes them as arguments to the command. Note that you should be extra careful when using rm. The following two commands differ only by one space, but the effects are quite different:

$rm * .txt

$rm * .txt

The first command deletes all files in the current directory!

Thank you for your reading, the above is the content of "Linux file management related command summary", after the study of this article, I believe you have a deeper understanding of the Linux file management related command summary of this problem, the specific use of the situation also needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report