The common Linux operating a command summary

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/Weixiaohuai/article/details/90743052

I. Introduction

In their daily work, generally on the line after the project is running on a Linux server, it is inevitable to solve the problem line, which we need remote login Linux server by looking at the logs, disk usage, etc. to troubleshoot the problem, the maintenance of Linux servers basically operate in the command line window, so we need to grasp the commonly used Linux commands. Because before there has been no systematic study of Linux-related command and knowledge, the next will be divided into several blog are summarized on the author to share some learning.

Second, the common command Detailed

[A] vi and vim: Both commands have a program editing function, vim is a vi enhanced version, more powerful. Here only use vim, usage vi basically the same.

First, use the command: RPM -qa | grep vim to see whether the system is installed vim editor, if not installed, then you can use the command: yum -y install vim installed.

vi / vim has three modes:

  • (1) Normal mode: the default mode, if you use vim into the file are normal mode inside.
  • (2) Edit mode: This mode can be edited file content, generally i press enter edit mode.
  • (3) command line mode: This mode can be set to display line numbers, Exit Vim, read, write and other operations content.

Conversion schematic three modes:

 

By following a simple example to illustrate the use of vim:

Seen at this time has been successfully written to a.txt content.

Introduce several commonly used vim editor shortcuts:

. (1) copy of the current lines / copy a few lines:

yy: Copy the current line

2yy: Copy the following two lines

Paste: p

. (2) delete the current row / delete a few lines:

dd: Delete the current line

2dd: delete the current row following two lines

(3).设置显示、隐藏行号:注意需要在命令行模式下使用: :set nu 即可显示行号、 :set nonu可取消显示行号。

(4).文件中查找内容:需要在命令行模式下使用  :/ + 关键字  进行搜索,

【b】关机、重启、注销命令:

shutdown -h now: 立即关机;

shutdown -h 1 : 一分钟后关机;

shutdown -r now: 立即重启;

halt: 关机;

reboot: 重启系统;

sync: 把内存的数据同步到磁盘上;

logout: 注销用户;

 

【c】帮助指令: 在Linux中,如果我们想了解某个命令的使用方法,可以借助man 和help这两个指令来帮助我们了解。

【d】pwd:返回当前工作目录的绝对路径。

【e】ls:查看目录信息

ls -a:展示所有的目录和文件信息,包括隐藏的

ls -l:以列表的方式展示目录和文件信息 (也可以使用: ll命令 进行查看)

【f】cd: change directory更改目录的意思

cd /home: 进入到home目录

cd /home/wsh:进入到home目录下的wsh目录

cd ..: 返回上一层目录

cd ../.. :返回上一层目录的上一层目录

【g】mkdir:make directory创建目录的意思

mkdir /myshell :在根目录 / 下创建myshell目录

mkdir -p /aaa/bbb : 创建多级目录aaa/bbb,需要指定-p 参数

【h】rmdir : remove directory删除目录的意思,但是需要注意的是,rmdir只能删除空目录,如果目录下有子目录或子文件,那么删除不了。

尝试使用rmdir删除有子目录或者子文件的目录:发现报错Directory not empty。

那么如果我们想删除带有子目录或者子文件的目录,可以使用rm -rf 目录名称进行删除。

【i】touch指令:用于创建空文件。

touch test1.txt: Create an empty file test1.txt

touch test2.txt test3.txt: Create two empty files test2.txt and test3.txt

[J] cp: copy copy files (or directory) to mean the specified directory.

cp test4.txt / test: the test directory to copy test4.txt

cp -r / aaa / ccc: copy all directories and subdirectories under the subfolder of aaa ccc directory to directory

Note that the recursive copy a file or directory, you must specify the parameters -r, otherwise it will error: omitting directory xxx.

[K] rm: delete a file or directory

rm -rf / ccc: forcibly remove the root directory / subdirectory and all subfolders under ccc directory, note the recursive delete.

rm -f test4.txt: force the removal test4.txt, will not alert message.

rm test3.txt: Are you sure you will be prompted to ask to delete the file.

[M] mv: moving files or directories (or rename a file)

 mv test1.txt test111.txt: test1.txt will rename test111.txt

mv test2.txt test2: test2.txt will move to the test2 directory

Third, the summary

This article only summarizes some of the common Linux commands, greater use of the relevant orders will continue to introduce next blog post. This article is the author of some of the study concluded, if there is something wrong with it, but also pointing out the trouble you or supplement, hoping to be helpful to everyone.

Guess you like

Origin blog.csdn.net/Weixiaohuai/article/details/90743052