Table of Contents
File operation related" >File operation related
#File permission related
" >#File permission related
Linux file name wildcard expression" >Linux file name wildcard expression
#Summary
" >#Summary
Home Operation and Maintenance Linux Operation and Maintenance Related command tutorials about Linux file management

Related command tutorials about Linux file management

Aug 02, 2017 pm 04:03 PM
linux Related manage

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

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

$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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to view the docker process How to view the docker process Apr 15, 2025 am 11:48 AM

Docker process viewing method: 1. Docker CLI command: docker ps; 2. Systemd CLI command: systemctl status docker; 3. Docker Compose CLI command: docker-compose ps; 4. Process Explorer (Windows); 5. /proc directory (Linux).

What computer configuration is required for vscode What computer configuration is required for vscode Apr 15, 2025 pm 09:48 PM

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

vscode cannot install extension vscode cannot install extension Apr 15, 2025 pm 07:18 PM

The reasons for the installation of VS Code extensions may be: network instability, insufficient permissions, system compatibility issues, VS Code version is too old, antivirus software or firewall interference. By checking network connections, permissions, log files, updating VS Code, disabling security software, and restarting VS Code or computers, you can gradually troubleshoot and resolve issues.

Can vscode be used for mac Can vscode be used for mac Apr 15, 2025 pm 07:36 PM

VS Code is available on Mac. It has powerful extensions, Git integration, terminal and debugger, and also offers a wealth of setup options. However, for particularly large projects or highly professional development, VS Code may have performance or functional limitations.

What is vscode What is vscode for? What is vscode What is vscode for? Apr 15, 2025 pm 06:45 PM

VS Code is the full name Visual Studio Code, which is a free and open source cross-platform code editor and development environment developed by Microsoft. It supports a wide range of programming languages ​​and provides syntax highlighting, code automatic completion, code snippets and smart prompts to improve development efficiency. Through a rich extension ecosystem, users can add extensions to specific needs and languages, such as debuggers, code formatting tools, and Git integrations. VS Code also includes an intuitive debugger that helps quickly find and resolve bugs in your code.

How to run java code in notepad How to run java code in notepad Apr 16, 2025 pm 07:39 PM

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

What is the main purpose of Linux? What is the main purpose of Linux? Apr 16, 2025 am 12:19 AM

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

vscode Previous Next Shortcut Key vscode Previous Next Shortcut Key Apr 15, 2025 pm 10:51 PM

VS Code One-step/Next step shortcut key usage: One-step (backward): Windows/Linux: Ctrl ←; macOS: Cmd ←Next step (forward): Windows/Linux: Ctrl →; macOS: Cmd →

See all articles