touch command:
- The touch command is used to create files and modify the time attributes of files or directories, including access time and change time. If the file does not exist, a new file will be created.
- ls -l can display the time record of the file
- User permissions: all users
Syntax:
touch [-acfm][-d<Date time>][-r<Reference documents or directories>] [-t<Date time>][--help][--version][File or directory]
Parameter Description:
a Change the reading time record of the file.
m Change the modification time record of the file.
c If the destination file does not exist, a new file will not be created. And --no-create The effect is the same.
f Do not use it to communicate with others unix System compatibility.
r Time records using reference files, and --file The effect is the same.
d You can set the time and date in a variety of formats.
t Set the time record, format and format of the file date The instructions are the same.
–no-create No new files will be created.
–help Lists the instruction formats.
–version Lists version messages.
# Create a file if it does not exist, and change the time attribute if it exists
touch a.txt
# Create empty files in batch
touch a{1..10}.txt
# View file details
stat a.txt
vi and vim:
- Using vi/vim is actually equivalent to creating files, opening files, editing files and saving files in Windows system
- vi is the abbreviation of visual interface and the most classic text editor in linux.
vi features:
- It can only edit and text content, and cannot typeset font paragraphs
- Mouse operation is not supported
- No menu
- Only command
- vi editor in the system management server to manage and edit files, its function is never comparable to that of the graphical interface editor
vim introduction:
- vim: it is a text editor developed from vi (system built-in command). Code completion, compilation, error jump and other convenient programming functions are particularly rich, which are widely used by programmers.
- In short, vi is an old-fashioned word processor, but it has complete functions, but there is still room for improvement.
- vim can be said to be a good tool for program developers.
vi/vim mode is mainly divided into the following three types:
- Command mode: enter "vim file name" in the Linux terminal to enter the command mode, but no text can be entered.
- Editing mode: in command mode, press i to enter editing mode. At this time, you can write the program. Press Esc to return to command mode.
- Last line mode: in the command mode, press: to enter the last line mode, and a colon will appear in the lower left corner. At this time, you can type in the command and execute it.
Open and new files:
- Using vim can not only open an existing file; You can also generate a file (if the file after vim does not exist); It's a bit similar to entering the notepad command in Windows. After entering notepad, we will open a text document and edit it - save as.
- User permissions: the permissions of the current file
- Enter vim in the terminal, followed by the file name
- If the file already exists, it will be opened directly
- If the file does not exist, open a temporary file, and a new file will be created when saving and exiting
Enter edit mode command:
command | function |
---|
i | Inserts text before the current character |
l | Insert text at the beginning of the line |
a | Add text after current character |
A | Add text at the end of the line |
o | Insert an empty line after the current line |
O | Inserts an empty row before the current row |
Save command:
command | function |
---|
:q | Exit without saving |
:q! | Force exit without saving |
:wq | Normal save exit |
:wq! | Force save exit |
vim creation and positioning:
# If the file already exists, the file will be opened directly. If it does not exist, the temporary file will be opened. After exiting and saving, a new file will be created
vim file name
# Positioning row
vim file name a.txt +5
vim exception:
- If you shut down the virtual machine because you didn't save it, opening it again will remind you whether you want to restore it. Select Restore or delete the exchange file directly
File view:
command | function |
---|
cat file name | View small file contents |
less-N file name | Split screen display of large file content |
head-n file name | View the previous section of the file |
tail-n file name | View the last part of the file |
grep keyword file name | Search text file content by keyword |
cat:
# View the contents of a.txt
cat a.txt
# View the contents of a.txt and add the line number
cat -n a.txt
# Exit the view and press q
less:
# View the contents of a.txt
less a.txt
# Check the contents of a.txt and add the line number
less -N a.txt
tail:
- -C < number > number of bytes displayed.
- -N < number of rows > number of rows displayed.
# Displays the last 3 lines of the file
tail -3 b.txt
# Dynamic display of the last 10 lines (dynamic is always refreshing to get the latest)
tail -f b.txt
# Dynamic display of the last 4 lines
tail -4f b.txt
# Display the contents of file b.txt from line 2 to the end of the file
tail -n +2 b.txt
# Displays the last 45 characters
tail -c 45 b.txt
head:
- -C < number > number of bytes displayed.
- -N < number of rows > number of rows displayed.
# Displays the first 10 lines of the file
head b.txt
# Displays the 5 lines at the beginning of the file
head -n 5 b.txt
# Display the first 10 bytes
head -c 10 b.txts
grep:
- -n: Show the lines that contain keywords
- -i: Display the lines containing keywords, and the search ignores case
- -v: Show the lines without keywords
# Show the lines that contain keywords
grep keyword b.txt
# Display the lines containing keywords and add line numbers
grep -n keyword b.txt
# Display the lines containing keywords, and the search ignores case
grep -i keyword b.txt
# Show the lines without keywords
grep -v keyword b.txt
# Find the specified process information, including grep process
ps -ef | grep keyword
# Find the specified process information, excluding grep process
ps -ef | grep keyword | grep -v "grep"
# Number of search processes
ps -ef grep -c keyword