What are the Linux file management and bash features?


File Management Commands on Linux

Directory Management Commands:

mkdir:make directories


-p: Automatically create a parent directory on demand;

-v: verbose, showing the detailed process;

-m MODE: directly giving permissions;

Note: The path base name is the role of the command; the path before the base name must exist;

rmdir:remove empty directories


-p: After deleting a directory, if its parent directory is empty, delete it together;

-v: display process;

File Management Command

cp command: copy

source file; object file;

single source copy: cp [OPTION]… [-T] SOURCE DEST

multiple sources Copy: cp [OPTION]… SOURCE… DIRECTORY


Single source copy: 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 Medium;

If DEST exists:

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

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

Multi-source copy: cp [OPTION]… SOURCE… DIRECTORY


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 separately Files to the target directory and keep the original name;

Common options:

-i: Interactive copy, which reminds the user to confirm before overwriting;

-f: Force Override the target file;

-r, -R: recursively copy the directory;

-d: copy the symbolic link The piece itself, not the source file it points to;

-a:-dR –preserve=all, archive, for archiving;


mode: Permissions

ownership: owner and group

timestamps: timestamp

context: security tag

xattr: extended attribute

links: symbolic links

all: all of the above properties

mv command: move




Common Options:

-i: Interactive;


rmCommand: remove


Common Options:

- i:interactive


-r: recursive

characteristics of bash

execution status result of command

command State result of execution:

bash returns value through state Output this result:

Success: 0

Failure: 1-255

Command line expansion

~: Automatically expand to the user's home directory, or The home directory of the specified user;

{}: can host a comma-separated list of paths and can be expanded into multiple paths;

Create a /tmp directory: a_c , a_d, b_c, b_d

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


mkdir -pv /tmp/in the /tmp/mylinux directory 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 for the file can be viewed with the stat command.

The touch command can modify the timestamp:

touch [OPTION]… FILE…

-c: The specified file path does not exist when it does not exist;

-a: modify only access time;

-m: modify only modify time;


[[CC]YY]MMDDhhmm[.ss ]

Command alias & command execution result

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

Execution result of the reference command:




Displaying the /var directory All files or directories beginning with l and ending with a lowercase letter with at least one digit in the middle (which can have other characters).

ls -ld /var/l*[0-9]*[az]

Display files or directories starting with any number in the /etc directory and ending with a non-numeric .

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

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

ls -ld /etc/[^[:alpha:]][az]*

Create a file starting with tfile in the /tmp directory, followed by the current date and time, file name Shape: tfile-2016-05-27-09-32-22.

touch /tmp/tfile-`date +%Y-%m-%d-%H-%M-%S`

Copy all /etc directories starting with p to Non-digit ending files or directories to the /tmp/mytest1 directory.

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

Copy all files or directories ending in .d in the /etc directory to /tmp/mytest2 In the catalog.

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

Copy all files starting with l or m or n in the /etc/directory and ending with .conf to /tmp In the /mytest3 directory.

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

Copyright © Windows knowledge All Rights Reserved