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

Linux File Management and characteristics of bash

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article focuses on "Linux file management and bash features", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor to take you to learn "Linux file management and bash features" it!

File management commands on Linux

Directory management commands:

Mkdir:make directories

Mkdir [OPTION]... DIRECTORY...

-p: automatically create a parent directory on demand

-v: verbose, showing the detailed process

-m MODE: directly given permissions

Note: the path base name is the object of the command; the path before the base name must exist.

Rmdir:remove empty directories

Rmdir [OPTION]... DIRECTORY...

-p: delete a directory if its parent directory is empty

-v: display proc

File management command

Cp command: copy

Source file

Single source replication: cp [OPTION]... [- T] SOURCE DEST

Multi-source replication: cp [OPTION]... SOURCE... DIRECTORY

Cp [OPTION]... -t DIRECTORY SOURCE...

Single source replication: cp [OPTION]... [- T] SOURCE DEST

If DEST does not exist: create this file in advance and copy the data stream of the source file to DEST

If DEST exists:

If DEST is a non-directory file: overwrite the target file

If DEST is a directory file: first create a file with the same name as the source file in the DEST directory and copy its data stream

Multi-source replication: cp [OPTION]... SOURCE... DIRECTORY

Cp [OPTION]... -t DIRECTORY SOURCE...

If DEST does not exist: error

If DEST exists:

If DEST is a non-directory file: error

If DEST is a directory file: copy each file to the target directory separately and keep the original name

Common options:

-I: interactive replication, that is, remind the user to confirm before overwriting

-f: force overwriting of the target file

-r,-R: recursively copy directory

-d: copy the symbolic link file itself instead of the source file it points to

-a:-dR-preserve=all, archive, used for archiving

-preserv=

Mode: permission

Ownership: owners and subordinate groups

Timestamps: timestamp

Context: security label

Xattr: extended attribut

Links: symbolic link

All: all the above attributes

Mv command: move

Mv [OPTION]... [- T] SOURCE DEST

Mv [OPTION]... SOURCE... DIRECTORY

Mv [OPTION]... -t DIRECTORY SOURCE..

Common options:

-I: interactive

-f:force

Rm command: remove

Rm [OPTION]... FILE...

Common options:

-i:interactive

-f:force

-r: recursive

Characteristics of bash

The execution status result of the command

The status result of the command execution:

Bash outputs this result with a status return value:

Success: 0

Failure: 1-255

Command line expansion

~: automatically expand to the user's home directory, or the specified user's home directory

{}: can host a comma-separated list of paths and expand it into multiple paths

Create the following under the / tmp directory: astatc, afigd, bounc, baild

Touch {a,b} _ {c,d}

Under the / tmp/mylinux directory

Mkdir-pv / tmp/mylinux/ {bin,boot/grub,dev,etc/ {rc.d/init.d,sysconfig/network- scripts}, lib/modules,lib64,proc,sbin,sys,tmp,usr/local/ {bin,sbin}, var/ {lock,log,run}}

File metadata

File metadata mainly includes permissions, size, inode, owner, group, access time, modify time, change time,etc...

The metadata of the file can be viewed with the stat command.

The touch command can modify the timestamp:

Touch [OPTION]... FILE...

-c: will not be created if the specified file path does not exist

-a: modify only access time

-m: modify only modify time

-t STAMP

[[CC] YY] MMDDhhmm [.ss]

Command alias & refers to the execution result of the command

You can use the alias name=value form to define command aliases.

Refer to the execution result of the command:

$(COMMAND)

Or `COMMAND`

Practice

Displays all files or directories under the / var directory that begin with l and end with a lowercase letter with at least one digit (which can have other characters) in the middle.

Ls-ld / var/l* [0-9] * [amerz]

Displays files or directories under the / etc directory that begin with any number and end with a non-number.

Ls-ld / etc/ [0-9] * [^ [: digit:]]

Display the / etc directory, starting with a non-letter, followed by a letter and any other file or directory of any length and any character.

Ls-ld / etc/ [^ [: alpha:]] [amerz] *

Create a file under the / tmp directory that starts with tfile, followed by the current date and time, with a file name such as: tfile-2016-05-27-09-32-22.

Touch / tmp/tfile- `date +% Ymuri% mmi% dmure% Hmure% MMI% S`

Copy all files or directories under the / etc directory that begin with p and end with non-numeric numbers into the / tmp/mytest1 directory.

Cp-r / etc/p* [^ 0-9] / tmp/mytest1/

Copy all files or directories ending in .d under the / etc directory into the / tmp/mytest2 directory.

Cp-r / etc/*.d / tmp/mytest2/

Copy all files under the / etc/ directory that begin with l or m or n and end with .conf to the / tmp/mytest3 directory.

Cp-r / etc/ [lmn] * .conf / tmp/mytest3/

At this point, I believe you have a deeper understanding of "Linux file management and bash features". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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