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

Detailed explanation of common commands in file management

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

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

File creation and refresh time

Command: touch

Options:

File: creating fil

-a file: modify ac time time only

-m file: modify mc time time only

-c file: refresh amc time if the file exists, and do not create the file if it does not exist

-t time file: only modify am time time format: year and day time. Second

Second, create a directory

Command: mkdir

Options:

Dir: create a directory

-p: create a parent directory and its subdirectories

-v: shows the creation process

-m MODE: specify permissions when creating a directory

Delete a directory or file

Command: rm rmdir

Rm option: delete a directory or file

-r: recursive deletion

-f: violent deletion

-I: user interaction

-v: display proc

Rmdir option: delete directory

-p: recursively delete parent and subdirectories

-v: display proc

IV. Move or rename files

Command: mv

Options:

-I: user interaction

-f: front move

If the dest to be moved is a file, rename the original file

Copy files

Command: cp

Note the following when copying files or directories:

If you want to copy a SRC source file

If the destination DEST does not exist, a DEST file is created and the contents of the source file SRC are copied to the DEST file.

If the destination exists and is a file, the contents of the SRC source file are overwritten to the DEST

If the destination exists and is a directory, copy the SRC source file to the DEST directory

If you want to copy multiple SRC source files

If the destination DEST does not exist, the cp reports an error and cannot complete the replication

If the destination DEST exists and is a file, the cp reports an error and cannot complete the copy

If the destination DEST exists and is a directory, copy the SRC source file to the DEST directory

To copy a directory:-r

If the destination DEST does not exist, the specified DEST directory is created and the contents of the SRC source file are copied to the DEST directory

If the destination DEST exists and is a file, the cp reports an error and cannot complete the copy

If the destination DEST exists and is a directory, copy the SRC directory to the DEST directory

Common options:

-I: interactive

-r: recursive replication, equivalent to-R

-a: archive, which is equivalent to dr-- preserv=all saves the original attributes of the file

-d: do not copy the source file, only the linked file

Cp replication the default is to copy the src link file and copy the contents of the original file to the src file

-- preserv: reserved metadata option

Mode,ownership,timestamp,links,xattr,context,all

-p: equivalent to-- preserv=mode,ownership,timestamp

-v: display proc

-f:cp-f file1 file2 both exist, and file2 belongs to the root user and is in the tom user

Means to delete file2 and re-command file1 to file2

The override attribute will not change, but the deletion and re-creation attribute will change.

Exercise:

Use the alias command to back up all files under the / etc/ directory to a new independent directory of / testdir/ every day, and require the new directory format to be backupyyyy-mm-dd. The backup process is visible.

Alias etcbak='cp-av / etc/ / testdir/ back`date +% F``

Easy to make mistakes: 1. / etc/*, cannot be used here because the back`date +% F` file does not exist, so multiple files under the / etc/ directory cannot be copied to the target directory that does not exist. An error will be reported.

2, cannot use-rv, because it belongs to backup, you should save the original attributes of the original file, such as soft link files.

Create the / testdir/rootdir directory first, copy all the files in / root to this directory, and require the original permissions to be retained

Cp-r-preserve=mode / root/ / testdir/rootdir

6. Alias command alias

Command: alias unalias

Format: alias Name='Value'

Unalias Name

Configuration file:

/ etc/bashrc is valid for all users

~ / .bashrc is only valid for the current user

The configuration takes effect immediately after exit and re-login. You can also use (source |.) / file.conf to read the configuration file.

If the definition on the command line is valid only for the current shell process.

If the alias has the same name as the original command, you need to execute the original command as follows:

\ Command

'Command' single quotation marks

Full path

Display the directory tree

-d: show only directories

-L #: specify display # layer

-P pattern: displays only the paths matched by pattern

VIII. Determine the contents of the document

Command: file

Options:

-b: only the results of the execution are displayed, not the name of the file

-f: list the types of files in the file (you can manually organize some files into files for file-f to view)

-F: use the specified delimiter to replace the default ":" after the file name

-L: check the DEST file type corresponding to the soft link file (not adding-L will prompt this file to be a soft link file)

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

Network Security

Wechat

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

12
Report