linux learning basic

Because the computer configuration is low, and for the convenience of learning, CentOs is installed under the vm as a learning

Most basic partition

1./ Root Partition

2. swap swap partition (recommended size is 1~2 times of memory)

3. /home partition

4. /boot boot file (boot loading) partition

5./var 

Wait, there must be at least the first 2 partitions, preferably home partition, because without this, there may be some minor problems when installing the software in the future.

crtl+alt+enter switch whether the virtual machine is full screen or not

shutdown -h now shutdown immediately

reboot=shutdown -r now reboot now

logout

The most basic use of vi editor

1. vi a.txt If there is no a.txt, create a new one, and open it if there is one

2. Enter small i to enter the input mode and start editing the opened file

3. After editing, press esc to enter the command line

4. Enter: (colon) wq (save and exit) the latter q! Exit directly

linux run level [0~6]

0: shutdown

1: Single user mode

2: Multi-user status without network service

3: Multi-user status has network service

4: The system is not used and reserved for users

5: Graphical interface (the graphical interface is entered by default after booting)

6: System restart (restart immediately after booting)

 Commonly used run levels are 3,5

 Modify run level method

 Log in as root user (general users do not have permission to modify)

 Go to /etc/inittab to open and edit with vi to find

id :3:initdefault 

As shown watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

Modify the corresponding number

If you accidentally set it to 6, it will restart immediately after booting up repeatedly.

Ways to modify incorrect configuration

Enter e when entering the grub boot interface

There will be three options. Select the second one as shown in the figure

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

Enter e to enter an interface and enter a space 1 at the last digit (indicating that the boot enters the single-user mode, and the inittab file will not be read when booting in this mode) as shown in the figurewatermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

Press Enter to return to the grub interface as shown in the figure

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

Then type b

When the system starts, it enters the single-user mode. You can also change the password or retrieve the forgotten password in this way.

Because the single user mode does not require a password when entering (directly enter the root directory)

Then go to modify the corresponding position of inittab under the configuration.


Other basic commands

pwd displays the current working directory

cd switch directory

ls list files and directories

ls -l lists files and directories in long list format

ls -a lists files and directories, including files and directories that are hidden, and can also be used in combination with ls -al

mkdir create directory

mkdir abc will create three directories a, b, and c in the current directory. When the directory already exists, it will prompt

If you create a directory recursively, you need to use the parameter p such as mkdir -pa/b/c (the directory to be created does not exist)

rmdir abc will delete the a, b, c directories rmdir delete the directory This directory must be empty

Recursively delete empty directories

rm delete files and directories without parameters can only delete non-empty directories

When rm -r deletes files or directories and files in the directory, it will confirm first when deleting one file. When rm -rf, force recursive deletion without prompt

rmdir -pa/b/c will also delete the empty parent directories of c and c at this time, that is, a/b/c will be deleted

Touch to create an empty file can create multiple files at the same time, such as touch a.txt b.txt

mv command

1. Format

mv[options] source file or directory target file or directory

2. Command function

  Depending on the second parameter (directory file or directory), the mv command renames the file or moves it to a new directory.

  When the second parameter is a file, the mv command completes the file renaming. At this time, there can only be one source file (or the source directory name),

  It renames the given source file or directory to the given directory file name. When the second parameter is the name of an existing directory,

  There can be multiple source files or directory parameters. The mv command moves the source files specified by each parameter to the target directory. When moving files across file systems

  mv first copy, and then delete the original file, and the link to the file will also be lost.

  3. Command parameters

-b: If files need to be overwritten, back them up before overwriting. 

-f: Force means that if the target file already exists, it will be overwritten without asking;

-i: If the destination file already exists, it will ask whether to overwrite it!

-u: If the target file already exists and the source is relatively new, it will be updated (update)

-t: --target-directory=DIRECTORY move all SOURCE arguments into DIRECTORY, that is, specify the target directory of mv,

This option is suitable for moving multiple source files to a directory, where the target directory is first and the source file is behind.

cp copy

cp -r dir1 dir2 recursive copy (copy directory and its subdirectory information)

ln establish a symbolic link (such as a shortcut under windows)

ln -s source target

ln -s /etc/inittab inittab (inittab points to the actual file /etc/inittab)

tab auto-completion

Create user

useradd  user1

passwd user1

password 


more Display directory or file content with pagination (press the space to be the next page, press shift+pageup to the previous page)

For example, the content of a file a.txt is very long. More a.txt can be displayed in pages

less displays file content with paging

grep query content in the file

grep -n'what you are looking for' file name plus n will show the line number of the content you are looking for in the file

Copy and paste of files in vi undo

In the same file

alt+v enter the mode but move the cursor to select the text to be copied

Then press y

Then i enter the insert mode and press alt+p at the place to be inserted to copy the pasted text to the cursor

Copy the entire line

Type i to enter insert mode

Cursor to the line to be copied

Press alt+v to enter the visual mode

Enter yy to copy the line where the cursor is located to the clipboard (buffer area)

Move to the place to be inserted Press alt+p at the place to be inserted to cache (paste the content on the clipboard to the cursor)




Guess you like

Origin blog.51cto.com/huangkui/2677794