Basic instructions under Linux

We have introduced the Linux directory before ( https://blog.csdn.net/tangduobutian/article/details/79638121 ), today let's take a look at some basic instructions under Linux:

1.ls command

Syntax: ls[options][directory or file]

Function: For a directory, this command lists all subdirectories and files in the directory. For files, the filename is listed along with other information.

Common options:

    -a: List all files in the directory, including implicit files starting with .

    -d: Display the directory as a file instead of the files under it

    -i: The index information of the i-node of the output file

    -k: the size of the file in k bytes

    -l: list file details

    -n: Use numeric UID, GID instead of name

    -F: Append a character to each file name to indicate the type of the file, "*" for normal executable files; "/" for directories; "@" for symbolic links; "I" for FIFOs; " =" means socket

   -r: Reverse directory sorting

    -t: sort by time

    -s: output the size of the file after the filename

    -R: List files in all subdirectories (recursive)

    -1: output only one file per line

Example:


2. pwd command

Syntax: pwd

Function: Display the current directory of the user

3. cd command

In the Linux system, the files and directories on the disk are organized into a directory tree, and each node is a directory or file.


Syntax: cd directory name

Function: Change directory work. Change the current working directory to the specified directory.

Example:

    cd .. : return to the parent directory

    cd /home/bit/linux/ : absolute path

    cd ../day01/ : relative path

    cd ~ : enter the user's home directory

    cd - : Return to the most recently accessed directory

4.touch command

Syntax: touch [options]... file...

Function: The touch command parameter can change the date and time of the document or directory, including the access time and change time, or create a new file that does not exist.

Common options:

    -a or --time=atime or --time=access or --time=use change access time only

    -c or --no-creat do not create any documentation

    -d : use the specified datetime instead of the current time

    -f : This parameter will be ignored and not processed, it is only responsible for solving the compatibility problem of the touch command of the BSD version

    -m or --time=mtime or --time=modify only change the change time

    -r : Set the date and time of the specified document or directory to be the same as the date and time of the referenced document or directory

    -t : use the specified datetime instead of the current time

5.mkdir command

Syntax: mkdir [options] dirname...

Function: Create a directory named "dirname" in the current directory

Example: Create multiple directories recursively


6. rmdir command && rm command

rmdir is a command corresponding to mkdir, mkdir is to create a directory, and rmdir is to delete a directory.

Syntax: rmdir [-p] [dirname]

Applicable objects: All users with the current directory operation authority

Function: delete empty directory

Common options: -p When the subdirectory is deleted, if the parent directory also becomes an empty directory, delete it together with the parent directory

The rm command can delete files or directories at the same time

Syntax: rm [-f -i -r -v] [dirname/dir]

Applicable object: all users

Function: delete a file or directory

Common options:

    -f : even if the file attribute is read-only, delete it directly

    -i : ask for confirmation one by one before deleting

    -r : delete the directory and all files under it

7.man command

Commands under Linux have many parameters, and we can't remember them all. We can get help by looking at the online manual. The command to access the Linux man page is man.

Syntax: man [options] command

Common options:

    -k: get online help by keyword

    num: find only in chapter num

    -a: show all chapters

8. cp command

Syntax: cp [options] source file or directory target file or directory

Function: Copy files or directories

说明:cp指令用于复制文件或目录,如同时指定两个以上的文件或目录,且最后的目的地是一个已经存在的目录,则它会把前面指定的所有文件或目录复制到此目录中。若同时指定多个文件或目录,而最后的目的地并非一个已存在的目录,则会出现错误信息。

常用选项:

    -f 或 --force :强行复制文件或目录,不论目的文件或目录是否已经存在

    -i 或 --interactive:覆盖文件之前先查询用户

    -r:递归处理,将制定目录下的文件与子目录一并处理。若源文件或目录的形态不属于目录或符号链接,则一律视为普通文件处理

    -R 或 --recursive :递归处理,将指定目录下的文件与子目录一并处理

 9.mv指令
     mv命令是move的缩写,可以用来移动文件或者将文件改名是Linux系统下常用的命令,经常用来备份文件或者目录。
功能:
    1.视mv命令中第二个参数的不同(是目标文件还是目标目录)mv命令将文件重命名或将其移至新的目录中。
    2.当第二个参数类型是文件时,mv命令完成文件重命名,此时,源文件只能有一个(也可以是源目录名),它将所给的源文件或目录重命名为给定的目标文件名。
    当第二个参数是已存在的目录名称时,源文件或目录参数可以有多个,mv命令将各参数指定的源文件均移至目标目录中。
常用选项:
    -f:force  强制的意思,如果目标文件已经存在不会询问而直接覆盖
    _i:若目标文件已经存在时,就会询问是否覆盖
10.cat/tac指令
    语法:cat[选项][文件]
    功能:查看目标文件的内容
    常用选项:
        -b:对非空输出行编号
        -n:对输出的所有行编号
        -s:不输出多行空行
11.more指令
    语法:more[选项][文件]
    功能:more指令,功能类似cat
    常用选项:
        -n:对输出的所有行编号
        q:退出more
    举例:

12.less指令
     1. less工具也是对文件或其他输出进行分页显示的工具,应该说是Linux正统查看文件内容的工具,功能极其强大。
     2.less的用法比起more更加有弹性。在more的时候,我们并没有办法向前翻,只能往后看
     3.但若使用了less时,就可以使用[pageup][pagedown]等按键的功能来往前往后翻看文件,更容易用来查看一个文
件的内容。
     4.除此之外,在less里面可以拥有更多的搜索功能,不止可以向下搜,也可以向上搜。
    语法:less [参数] 文件
    功能:less与more类似,但使用less可以随意浏览文件,而more仅能向前移动,却不能向后移动,而且less在查看之前不会加载整个文件
    常用选项:
        -i:忽略搜索时的大小写
        -N:显示每行的行号
        /字符串:向下搜索“字符串”的功能
        ?字符串:向上搜索“字符串”的功能
        n:重复前一个搜索(与/或?有关)
        N:反向搜索前一个搜索(与/或?有关)
        q:quit
13.head指令
     head与tail就像它的名字一样浅显易懂,它是用来显示开头或结尾某个数量的文字区块,head用来显示档案的开头至标准输出中,而tail就是看档案的结尾
    语法:head [参数]...[文件]...
    功能:head用来显示档案的开头至标准输出中,默认head命令打印其相应文件的开头10行
    常用选项:
        -n <行数> :显示n行
    举例:
 14.tail指令
     tail命令从指定点开始将文件写到标准输出,使用tail命令的-f选项可以方便的查阅正在改变的日志文件,tail -f filename 会把filename里最尾部的内容显示在屏幕上,并且不断刷新,使你看到最新的文件内容。
    语法:tail[必要参数][选择参数][文件]
    功能:用于显示指定文件末尾内容,不指定文件时,作为输入信息处理,常用来查看日志文件
    常用选项:
        -f:循环读取
        -n<行数>:显示行数
15.时间相关的指令
date显示
    date指定格式显示时间:date+%Y:%m:%d
    date用法:date[OPTION]...+[FORMAT]
1.在显示方面,使用者可以设定欲显示的格式,格式设定为一个加号后接数个标记,其中常用的标记列表如下:
    %H:小时(00..23)
    %M:分钟(00..59)
    %S:秒(00..60(考虑闰秒))
    %X:相当于%H:%M:%S
    %d:日(01..31)
    %m:月份(01..12)
    %Y:完整年份(0000..9999)
    %F:相当于%Y-%m-%d
2.在设定时间方面
    date -s:设置当前时间,只有root权限才能设置,其他只能查看
    date -s 20180326:设置成20180326,这样会把具体时间设置成空00:00:00
    date -s 01:01:01:设置具体时间,不会对日期做更改
    date -s “01:01:01 2018-03-26”:这样可以设置全部时间
    date -s “01:01:01 20180326”:这样可以设置全部时间
    date -s “2018-03-26 01:01:01”:这样可以设置全部时间
    date -s “20180326 01:01:01”:这样可以设置全部时间
3.时间戳
    时间-〉时间戳:date+%s
   时间戳-〉时间:Unix时间戳(英文为Unix epoch,Unix time,POSIX time或Unix timestamp)是从1970年1月1日(UTC/GMT的午夜)所经过的秒数,不考虑闰秒
  16.cal指令
    cal命令可以用来显示公历(阳历)日历,公历是现在国际通用的历法,又称格列历,通城阳历。“阳历”又名“太阳历”,是以地球绕行太阳一周为一年,为西方各国所通用,故又名“西历”。
    命令格式:cal [参数][月份][年份]
    功能:用于查看日历等时间信息,如只有一个参数,则表示年份(1-9999),如有两个参数,则表示月份和年份
    常用选项:
        -3:显示系统前一个月,当前月,下一个月的日历
        -j:显示在当年中的第几天
        -y:显示当前年份的日历
举例:
1.显示当前年份的日历:

2.显示系统前一个月,当前月,下一个月的日历


 17.find指令
    Linux下find命令在目录结构中搜索文件,并执行指定的操作
    Linux下find命令提供了相当多的查找条件,功能很强大。由于find具有强大的功能,所以它的选项也很多,其中大部分选项都值得我们花时间来了解一下
    即使系统中含有网络文件系统(NFS),find命令在该文件系统中同样有效,只要具有相应的权限
    在运行一个非常消耗资源的命令时,很多人都倾向于把它放在后台执行,因为遍历一个大的文件系统可能会花费很长的时间
    语法:find pathname -options
    功能:用于在文件树中查找文件,并做出相应的处理
    常用选项:
        -name:按照文件名查找文件
18.grep指令
    语法:gre [选项] 搜索字符串 文件
    功能:在文件中搜索字符串,将找到的行打印出来
    常用选项:
        -i:忽略大小写的不同,所以大小写视为相同
        -n:顺便输出行号
        -v:反向选择,亦即显示出没有搜索字符串内容的那一行
  19.zip/unzip指令
    语法:zip压缩文件.zip目录或文件
    功能:将目录或文件压缩成zip格式
    常用选项:
        -r:递归处理,将指定目录下的所有文件和子目录一并处理
    举例:

 20.tar指令:打包/解包,不打开它,直接看内容
tar [-cxtzjvf] 文件与目录 ... 参数:
    -c:建立一个压缩文件的参数指令
    -x:解开一个压缩文件的参数指令
    -t:查看tarfile里面的文件
    -z:是否同时具有gzip的属性?亦即是否需要用gzip压缩?
    -j:是否同时具有bzip2的属性?亦即是否需要用bzip2压缩?
    -v:压缩的过程中显示文件,这个常用,但不建议用在背景执行过程
    -f:使用档名,请留意 在f之后要立即接档名,不要再加参数!
    -C:解压到指定目录
 21.bc指令
    bc命令可以很方便的进行浮点运算
22.uname -r指令
    语法:uname [选项]
    功能:uname用来获取电脑和操作系统的相关信息
    补充说明:uname可显示Linux主机所用的操作系统的版本、硬件的名称等基本信息
    常用选项:
    -a或-all:详细输出所有信息,依次为内核名称、主机名、内核版本号、内核版本、硬件名、处理器类型、硬件平台类型、操作系统名称
 23.重要的几个热键
    [Tab]
按键:具有命令补全和档案补齐的功能
     [Ctrl]-c按键:让当前的程序停掉
     [Ctrl]-d按键:键盘输入结束的意思;另外,它也可以用来取代exit
24.关机
    语法:shutdown [选项] 
    常用选项:
        -h:将系统的服务停掉后,立即关机
        -r:在讲系统的服务停掉之后就重新启动
        -t sec:-t后面加秒数,即过几秒后关机的意思
 以下命令作为扩展:
    安装和登录命令:login、shutdown、halt、reboot、install、mount、umount、chsh、exit、last;
    文件处理命令:file、mkdir、grep、dd、find、mv、ls、diff、cat、ln;
    系统管理相关命令:df、top、free、quota、at、lp、adduser、groupadd、kill、crontab;
    网络操作命令:ifconfig、ip、ping、netstat、telnet、ftp、route、rlogin、rcp、finger、mail、nslookup;
    系统安全相关命令:passwd、su、umask、chgrp、chmod、chown、chattr、sudo ps、who;
    其他命令:tar、unzip、gunzip、unarj、mtools、man、unendcood、undecode。











Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326804148&siteId=291194637