7.Big Data_Basic Knowledge of Linux_2_File Directory Operation Commands_1

Previous article 6. Big data_basic knowledge of linux_2_file directory operation commands_0

1.6.2 rm(remove files or directories)

Usage: rm [-fir] file or directory

Option parameters:

-f: Ignore files that do not exist, no warning will appear, f (force)

-i: Interactive mode, the user will be asked whether to delete before deleting.

-r: Recursive deletion, commonly used in deleting directories (this is a very dangerous option). Once deleted, it cannot be retrieved.

Example:

Catalog refer to the picture above

<1>rm -i /tmp/test1/fff.txt

Description: Use the -i command to delete files (files), and the system sends interactive messages.

<2>rm -i /tmp/test1/tt*

Description: Wildcard delete files, * represents 0 ~ any number of characters

<3>rmdir /tmp/test2/test3/

Note: Since there are files under the directory, the system will prompt a message when deleting it (the reason for the prompt message is root

The user has added the -i option by default, which is a protection mechanism to prevent accidental deletion).

Use this time:

rm -r /tmp/test2/test3/

/rm -r /tmp/test2/test3/ (remove system deletion prompt)

-r represents recursive deletion, that is, delete the files under the directory and then delete the test3 directory. Note that the test2 directory will not be deleted. This is recursive downward.

<4>rm ./-aasd

Note: To delete files (files) that start with -, you must use ./ to specify it under the current directory, because - in the Linux system means that it is followed by options, so simply use "rm - aasd 』The system's instructions will be misjudged. Therefore, the only way to avoid the first character being "-" is to add this directory "./". There is another way rm -- -aasd

1.6.3 mvmovechange or change name

Usage: mv [-fiu] file to be moved destination location

mv file to be moved 1 file to be moved 2 file to be moved 3 ... the destination of the move

Option parameters:

-f: If the target file already exists, the system will not ask about overwriting it directly.

-i: The target file has been saved, and the system will ask whether to overwrite it (the root user system will add the -i option by default)

-u: If the target file already exists and the file to be moved is relatively new, it will be updated at this time.

Example:

<1>mv aaa.txt test1

Instructions: Move the aaa.txt file to the test1 folder

<2>mv -i aaa.txt test1 (-i root user will join by default)

Note: When moving, the target folder has a file with the same name, and the system asks whether to overwrite it.

<3>mv -u aaa.txt test1

Description: The -u option causes the system to ask whether to overwrite the original file.

1.6.4 Get the file name and directory name of the path

<1>basename

Usage: basename path

Example: basename /etc/sysconfig/networw

Note: The above command will display the file name

<2>dirname

Usage: dirname path

Example: dirname /etc/sysconfig/network

Note: The above command displays the path

1.6.4 View file content

Just like browsing files in Windows Notepad, there are many common commands for viewing file contents under Linux.

cat: displays the file content from the first line

tac: displays the file contents from the last line

nl: Display the file and output the line number at the same time

more: Display content page by page

less: Display content page by page, you can turn pages forward

head: only read the first few lines

tail: only look at the tail lines

od: Read file contents in binary format

<1>cat

Example: cat [-AbEnTv] file (can be a file path)

Options:

-A: List special characters

-b: List line numbers only for non-blank lines. Line numbers are not displayed for blank lines.

-E: Display the ending line break character $

-n: Print line number, blank lines also display line number

-T: Display the tab key with ^

-v: List some invisible special characters

Example 1: cat -n /etc/issue

Note: View the issue file, -n means to display the line number at the same time

Example 2: cat -nv /etc/xinetd.d/rsync

Note: Use the -nv option in combination to display the line number and special characters.

<2>tac

Usage: tac file (can also be the data path of the file)

Example: tac /etc/issue

Description: Display the file contents starting from the last line of the file, that is, display the file contents in reverse order.

<3>nl

Usage: nl [option parameter] file

Options:

-b a: Display line numbers, and empty lines also display line numbers.

-b t: Display line numbers, blank lines do not display line numbers

-n: List the line number representation method

-n ln: The line number is displayed at the far left of the screen

-n rn: The line number is displayed at the far left of its own field without adding 0

-n rz: The line number is displayed at the far left of its own field, and 0 is added.

-w: Number of digits occupied by the line number field

Examples are as follows:

<4>more

Usage: more file (or absolute path of the file)

Example: more /etc/man.config

Description: Display the file page by page

Operation keys:

Space bar: means turning down one page

Enter: represents scrolling down one line

:f: Immediately display the file name and the number of lines currently displayed

q: means to leave more immediately and no longer display the content of the document.

b (or ctrl b): means turning the page back. This action is only useful for files, not for pipes.

/String: means searching for this [string] in the displayed content.

<5>.less document view

Usage:less option parameter file

parameter:

Space bar: page down

pagedown: page down

pageup: turn page up

/String: The function of searching down [string]

?String: The function of searching upward for [string]

n: Repeat the previous search (related to/or?)

N: Repeat the previous search in reverse (related to/or?)

q: Exit less command

Example: less /etc/man.config

Instructions: View the man.config file

<6>head/tail takes out the first few lines/takes out the last few lines

Usage:head [-n number] file

Parameters: -n number: indicates the number of lines to be taken out. The first 10 lines are displayed by default (including blank lines)

Example:

head /etc/man.config takes out the first 10 lines

head -n 21 /etc/man.config takes out the first 21 lines

Note: The usage of tail is the same as that of head, except that the last few lines are taken out.

<7>.od View non-plain text files

Usage:od [-t type] file

type:

a: Use default character output

c: Use ASCII character output

d[size]: Use decimal output data, each integer occupies size bytes

f[size]: Use floating point numbers to output data, each number occupies size bytes

o[size]: Use octal to output data, each integer occupies size bytes

x[size]: Use hexadecimal to output data, each whole number occupies size bytes

Example:

od -t c /usr/bin/passwd Use ASCII characters to count files

od -t oCc /use/passwd uses octal and ASCII to compare the output

od -t xCc /use/passwd uses hexadecimal and ASCII to compare the output

<8>.touch Modify the document time or create a new document

Introduction: Each document will record a lot of time parameters under Linux, among which there are three main time parameters.

modification time (mtime):

When the content of the document changes, this time will be updated. The document content does not include the document's permissions and attributes.

status time (ctime):

This time will be updated when the status of the document changes, such as changes in permissions and attributes.

access time (atime):

When the content of the document is read, this time will be changed, such as using cat to read the document.

Usage: touch [-acdmt] file

Option parameters:

-a: only revise access time

-c: Only modify the time of the file. If the file does not exist, no new file will be created.

-d: You can accept the date to be revised instead of the current date, or you can use --date="date or time"

-m: only modify mtime

-t: The time to be revised can be followed instead of the current time. The format is [YYMMDDhhmm]

Example:

a.[root@XXXxxx tmp]# touch ttt

[root@XXXxxx tmp]# ls -l ttt

-rw-r--r--. 1 root root 0 Feb 12 18:25 ttt

Note: Create the file ttt under the tmp folder. If the touch file does not exist, it will be created.

[root@xxxx tmp]# ll ttt; ll --time=atime ttt; ll --time=ctime ttt;

The above command is to check three times

-rw-r--r--. 1 root root 0 Feb 12 18:25 ttt This is mtime

-rw-r--r--. 1 root root 0 Feb 12 18:25 ttt This is atime

-rw-r--r--. 1 root root 0 Feb 12 18:25 ttt This is ctime

ll===ls -l ,';' indicates continuous instructions, that is, entering multiple instructions. These instructions can be executed in sequence.

b.[root@xxxx tmp]# touch -d "2 days ago" ttt The modification time is 2 days ago

[root@xxxxx tmp]# ll ttt; ll --time=atime ttt; ll --time=ctime ttt;

-rw-r--r--. 1 root root 176 Feb 10 18:46 ttt This is mtime

-rw-r--r--. 1 root root 176 Feb 10 18:46 ttt This is atime

-rw-r--r--. 1 root root 176 Feb 12 18:46 ttt This is ctime

c.[root@o-o tmp]# touch -t 0809061325 ttt Modification time is 13:25 on September 6, 2008

[root@o-o tmp]# ll ttt; ll --time=atime ttt; ll --time=ctime ttt;

-rw-r--r--. 1 root root 176 Sep 6 2008 ttt This is mtime

-rw-r--r--. 1 root root 176 Sep 6 2008 ttt This is atime

-rw-r--r--. 1 root root 176 Feb 12 18:50 ttt This is ctime

1.6.5 File default permissions

When creating a default file, the system will set default permissions, which are related to umask (the default permission value when the current user creates a file or directory)

0022 is the numerical permission value of the system umask. The last three groups of 022 represent the file permission values ​​that the system needs to process when creating a file. The first 0 is ignored for the time being.

When creating a file, by default, the file is not executable. Generally, files are used to save data. Therefore, the maximum permission of system files is 666, that is, the default permission is –rw-rw-rw-

When creating a directory, you need x permissions to enter this directory. Therefore, the default permissions are all open, the maximum permission value is 777, and the default permissions are drwxrwxrwx

What umask determines is the permission value that needs to be removed when creating a directory or permission. Therefore, the system default permission value is:

Create file: (-rw-rw-rw-) – (------w--w) ==> (-rw-r--r--) which is 666 – 022 ==> 644 (non-mathematical subtraction)

Create directory: (drwxrwxrwx) – (d-----w--w)=>(drwxr-xr-x) which is 777-022=>755 (non-mathematical subtraction)

verify:

Created file

directory created

 

Guess you like

Origin blog.csdn.net/u010952056/article/details/87160514