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

Ubuntu Command Mode Foundation

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

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

Ubuntu is a free, open source, Debian-based Linux distribution. On the basis of ubuntu, other Linux distributions with their own characteristics are derived. The first is an operating system, which is used to manage computer hardware. To play the role of a computer, we have to rely on the installation of a variety of application software. (1) View the directory under the current folder

The ①, ls (abbreviation for list) commands are used to list files and directories. By default, he lists the contents of the current directory. With parameters, it can be displayed in different ways. As shown in the figure:

The ls command lists the contents of the current directory. The dir command is an alias for the ls command and an abbreviation for directory. Usually listed files are displayed in different colors, and different colors represent different file types. The following table lists the corresponding relationship between file types and colors:

② and ll list all the file information under the file, including hidden files, while ls-l lists only explicit files, indicating that the two commands are not the same! As shown in the figure:

The relationship between them can be seen as follows (as can be seen from the alias alias, the two can be equated):

(2) commands for viewing the current path

(3) enter the folder

Enter the folder: cd

Cd # back to the home directory

Cd ~ go back to the home directory

Cd HOME goes back to the home directory cd goes back to the last directory CDC home goes back to the home directory cd goes back to the last directory cd! Take the parameters of the previous command as input

Cd.. Go back to the upper directory

(4) use the editor of Ubuntu's own text to write the file: gedit fileName

(5) use vi to write documents: vi filename

Vi can be divided into three states: command mode (command mode), insert mode (Insert mode) and bottom line mode (last line mode). The functions of each mode are as follows:

① command line mode command mode)

Control the movement of the screen cursor, the deletion of characters, words or lines, move and copy a section and enter the Insert mode, or to the last line mode. (press esc to exit insert mode and enter command mode)

② insertion Mode (Insert mode)

Text input can only be done under Insert mode, and press the "ESC" key to return to command line mode. (press I to exit command mode and enter insert mode)

③ bottom line mode (last line mode)

Save the file or exit vi, or you can set the editing environment, such as looking for strings. Wait.

Under Command Line Mode (command mode), click the colon key to enter Last line mode. The corresponding parameters are as follows:

W filename (enter "w filename" to save the article with the specified file name filename)

: wq (enter "wq", save and exit vi)

: q! (enter qquit, do not save the disk and force to exit vi)

Command line mode (command mode) function key

1), insert mode

Press "I" to switch to insert mode "insert mode". Press "I" to enter the file from the current position of the cursor after entering insert mode

After pressing "a" to enter insert mode, the text is entered from the next position where the current cursor is located.

When you press "o" to enter insert mode, insert a new line and enter text at the beginning of the line.

2), move the cursor

Vi can directly use the cursor on the keyboard to move up and down, but the regular vi uses lowercase letters "h", "j", "k" and "l" to control the cursor to move left, down, up and right respectively.

Press "ctrl" + "b": move the screen one page back.

Press "ctrl" + "f": the screen moves one page forward.

Press "ctrl" + "u": move the screen to "back" half a page.

Press "ctrl" + "d": move the screen half a page to the front.

Press the number "0": move to the beginning of the article.

Press "G": move to the last line of the article.

Press "$": move to the end of the line where the cursor is located.

Press "^": move to the beginning of the line where the cursor is located

Press "w": the cursor jumps to the beginning of the next word

Press "e": the cursor jumps to the suffix of the next word

Press "b": the cursor goes back to the beginning of the previous word

4)。 Delete text

"x": each time you press, delete the "after" character of the cursor location.

"# x": for example, "6x" means to delete "after" 6 characters where the cursor is located.

"X": uppercase X. each time you press it, one character in front of the cursor is deleted.

"# X": for example, "20X" means to delete the "first" 20 characters where the cursor is located.

"dd": delete the line of the cursor.

"# dd": delete # lines from the line where the cursor is located

(6), apt command

Apt, short for Advanced Packaging Tool, is an installation package management tool.

Apt-get-f install repair installation "- f =-fix-missing"

For details and details, please see: summary of the usage of the apt command in the Ubuntu system

(7) sudo commands in ubuntu, the user roles and permissions are divided very carefully and strictly. If you are not a root user, then you are not allowed to execute some commands and do some operations, you can add sudo in front of the command, so your permissions will be greater. Write a C program under ubuntu, whose content is to realize the function of file copy.

Description of open:

1int open (const char * pathname, int flags)

The parameter pathname points to the file path string you want to open. The following are flags that can be used by the parameter flags:

O_RDONLY opens the file as read-only

O_WRONLY opens the file in write-only mode

O_RDWR opens the file in a read-write manner. The above three flags are mutually exclusive, that is, they cannot be used at the same time, but can be combined with the following flags using the OR (|) operator.

Return value

If all permissions to be verified pass the check, a value of 0 is returned, indicating success, and-1 is returned as long as one permission is prohibited.

Read (read data from open files) 1read (int fd,void * buf, size_t count)

Read () transfers count bytes of the file referred to by the parameter fd to the memory indicated by the buf pointer. If the parameter count is 0, read () has no effect and returns 0.

Return value

For the number of bytes actually read, if 0 is returned, it indicates that the end of the file or unreadable data has been reached, and the read and write position of the file will move with the bytes read.

Write (write data to an open file) 1write (int fd,const void * buf,size_t count)

Write () writes the memory referred to by the parameter buf into the file referred to by the parameter fd by writing count bytes. Of course, the read and write location of the file will also move with it.

Return value

If it goes well, write () returns the number of bytes actually written. Return-1 when an error occurs, and the error code is stored in errno

For details, see this article.

The file copy process is as follows:

one

two

three

four

five

six

seven

eight

nine

ten

eleven

twelve

thirteen

fourteen

fifteen

sixteen

seventeen

eighteen

nineteen

twenty

twenty-one

twenty-two

twenty-three

twenty-four

twenty-five

twenty-six

twenty-seven

twenty-eight

twenty-nine

thirty

thirty-one

thirty-two

thirty-three

thirty-four

thirty-five

thirty-six

thirty-seven

thirty-eight

thirty-nine

forty

forty-one

forty-two

forty-three

forty-four

forty-five

forty-six

forty-seven

forty-eight

forty-nine

fifty

fifty-one

fifty-two

fifty-three

fifty-four

fifty-five

fifty-six

fifty-seven

fifty-eight

fifty-nine

sixty

sixty-one

sixty-two

sixty-three

sixty-four

sixty-five

sixty-six

sixty-seven

sixty-eight

sixty-nine

# include

# include /-- Standard input / output header file

# include /-- string processing related header file

# include /-- Linux system call header files, such as read and write

# include /-- contains open system calls

# include / /-contains some variables used in debugging errors

Using namespace std

# define BUFFER_SIZE 1024

/ / read from the original document

Int Copy2File (char fileName [], char goalFile [])

{

Int read_bytes, write_bytes

Char buffer[BUFFER _ SIZE]

Char * ptr

Int oFile,gFile

/ / open original document

If ((oFile = open (fileName,O_RDONLY)) =-1) {

Printf ("open% s Error!", fileName)

Exit (1)

}

/ / open destination document

If ((gFile = open (goalFile, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR)) =-1) {

Printf ("Open% s Error!", goalFile)

Exit (1)

}

/ / begin to copy fileName to goalFile

/ / read () transfers BUFFER_SIZE bytes of the file oFile referred to by the parameter to the memory indicated by the buffer pointer

While (read_bytes = read (oFile, buffer, BUFFER_SIZE))

{

/ / the produce of reading is error

If (read_bytes==-1)

Break

/ / begin to write chars to destination file

Else {

Ptr = buffer

/ *

Write () writes the memory referred to by the parameter buf into the file referred to by the parameter fd by writing count bytes.

Of course, the read and write location of the file will also move with it.

Return value: if it goes well, write () returns the number of bytes actually written.

When an error occurs,-1 is returned, and the error code is stored in errno.

, /

While (write_bytes = write (gFile, ptr, read_bytes)) {

/ / the produce of writing is error

If ((write_bytes =-1))

Break

Else if (write_bytes > 0)

{

/ / make the ptr (the index firstly equals the first address)

/ / move behind

Ptr + = write_bytes

/ / the bytes (index) you need to write continuely is gong to reduce

Read_bytes-= write_bytes

}

}

}

}

Close (gFile)

Close (oFile)

Return 1

}

Int main ()

{

Char filePath2 [] = "/ home/gqxing/Desktop/OperatSystem/Textfile/file.txt"

Char filePath3 [] = "/ home/gqxing/Desktop/OperatSystem/Textfile/CopyFile.txt"

Copy2File (filePath2,filePath3)

Return 0

}

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: 298

*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

Wechat

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

12
Report