Introduction to Linux Basics 3 Common Commands

1. Introduction to common Linux commands

1. Basic commands

1.pwd

Display the absolute path of the current location, examples are as follows:
Please add a picture description

2.cd

To switch directories, the parameter added after cd is the destination, which can be a relative path or an absolute path;

  • The abc here is a folder located on the desktop.
  • old is a folder in abc.

Relative path:
Please add a picture description
Absolute path:
insert image description here

  • cd ’ -' Return to the last directory location
    Please add a picture description

  • cd ’~'Directly return to the user's home directory
    insert image description here

  • cd’'Go back to the previous level
    insert image description here

  • cd’.'nothing happened
    insert image description here

3.ls

Display all files in the directory, examples are as follows:
Please add a picture description

  • -a show hidden files
    Please add a picture description

  • -l Display detailed information of all files in a listPlease add a picture description

4.man

View the help manual to view detailed information on specific commands, system calls, and library functions. Examples are as follows:
insert image description here
insert image description here

5.touch

Create an ordinary file, the example is as follows:
insert image description here
before creation: Please add a picture description
after creation:
Please add a picture description

6.mkdir

Create a directory file (folder), the example is as follows: it
insert image description here
will also be added on the desktop:
insert image description here

7.rm

Delete files or folders, note:When deleting a folder, you need to add the parameter "-r", the example is as follows:
Delete ordinary files:
insert image description here
delete folders are divided into, delete empty directories in folders and delete non-empty directories in folders;
delete empty directories:
insert image description here
delete non-empty directories:
insert image description here

8.cp

Copy the file, note: When copying directory files, you need to add the parameter "-r", the example is as follows:
copy of ordinary files:
insert image description here
copy of directory files:
insert image description here

Note: cp -r dir2 dir1 appears twice here:
1. The first execution: dir1 does not exist, and dir1 is successfully created at this time;
2. The second execution: dir1 already exists, and the system treats dir1 as a path.

9.mv (cut, move, rename)

1. Cutting movement, examples are as follows:
insert image description here

2. The example of renaming is as follows:
insert image description here
renaming has the risk of overwriting, use mv carefully.

10.find

Traversing through the directory, you can also specify the starting position of the traversal, examples are as follows:
insert image description here

11. grep filter

insert image description here

  • c only shows the number of lines
  • v Negate, print all the data other than the search itself
    insert image description here

12. pipe '|'

Use the output information of the previous command as the input information of the next command, the example is as follows:
insert image description here

13.wc

Statistical file information, such as (-w) shows how many words (-l) counts the number of lines (-c) Examples are as follows:
insert image description here

14.su

Switch user su+username, if no user name is added, the root user will be switched by default.
The example is as follows:
insert image description here
sudo su switch root user:
insert image description here
exit Exit:
insert image description here

15. Shutdown and restart

  • shutdown -h now shutdown immediately
  • shutdown -r now restart immediately
  • init 0 shutdown
  • init 6 reboot
  • shut down
  • reboot reboot

init level: 0~6 7 levels:

  • 0 shutdown
  • 1 single user mode
  • 2 multi-user without network mode
  • 3 Full multi-user text interface
  • 4 undefined or custom
  • 5 Graphical interface
  • reboot

For example, init 3 is a text interface, which is the interface we use most in our work.

16. Modify user password

passwd stu modify
sudo passwd stu force modification

2. Packing, unpacking, compression, and decompression commands

1. tar packs or unpacks files

  • c create package file
  • f specifies that the target is a file rather than a device
  • v show detailed process
  • t display the contents of the package without releasing
  • x releases the contents of the package
  • Z GNU version is newly added, allowing tar to have compression and decompression functions

1.1tar packaging process

insert image description here

1.2tar unpacking process

insert image description here

2.gzip compresses and decompresses files

2.1gzip compresses the file

insert image description here

2.2gzip decompresses the compressed package

  • d unzip
    insert image description here

2.3 Further decompress the heap xxx.tar.gz through the tar command

insert image description here

2.4 Compress multiple files in one step through the tar command

insert image description here

Guess you like

Origin blog.csdn.net/weixin_56935264/article/details/123901118