Home  >  Article  >  Operation and Maintenance  >  Detailed explanation of commonly used Linux commands (worth collecting)

Detailed explanation of commonly used Linux commands (worth collecting)

Linux中文社区
Linux中文社区forward
2023-08-02 17:32:581123browse

This article will give you a detailed introduction to commonly used Linux commands, demonstrations and some basic knowledge

Detailed explanation of commonly used Linux commands (worth collecting)

Directory

  • ls command
  • file command
  • pwd command
  • whoami command
  • cd command
    • Relative path and absolute path
  • which directive
  • touch command
  • mkdir command
  • Add user trust relationship
  • rmdir command
  • rm command
  • man command
  • cp command
  • mv command
  • edit
  • cat command
  • echo command
  • Redirect
  • more command
  • less command
  • head command
  • tail command
  • Pipeline operation
  • date command
  • cal command
  • find command
  • grep command
  • zip command/unzip command
  • tar command
  • bc command
  • uname command
  • shutdown command
  • stat command
  • Three times under Linux
  • touch command supplement
  • Hotkeys in Linux-
  • List of commands

ls command

Syntax: ls [options] [directory]

Function: ls has multiple options. For a directory, this command lists all subdirectories and files in the directory. For files, the file name and other information will be listed

ls without options defaults to displaying files in the current directory

Detailed explanation of commonly used Linux commands (worth collecting)

Options:

-l : List file details in the form of a list

Detailed explanation of commonly used Linux commands (worth collecting)

In the Linux system, the file type is not distinguished by the file suffix, but the file type is identified by the first character, regardless of whether the file suffix is ​​.c or .txt or other suffixes, as long as it starts with -, it is an ordinary file

  • d: Directory file, simply a folder, we can create a new file under this directory file
  • -: Ordinary file, divided into text Files, dynamic and static libraries, executable programs, etc.
  • l: Soft link (similar to Windows shortcut)
  • b: Block device file (such as hard disk, optical drive, etc.)
  • p: Pipe file
  • c: Character device file (such as screen and other serial devices) -
  • s: Socket file

We focus on the first two types of files today

Ordinary files can be divided into many types. In order to be compatible with windows and make it easier for most of us Linux users to distinguish different files, we are still used to using suffixes to represent different file types. However, some files must be added with a suffix, such as .c files written in C language, which require special processing and use the suffix to distinguish the type

  • -a: Display all files in the directory including hidden files. The files starting with a dot represent hidden files. One dot represents the current path and two dots represent the upper-level path. We Will be explained in the cd command below. and..
Detailed explanation of commonly used Linux commands (worth collecting)
  • -d: Display the directory like a file, while Files in the directory are not displayed. The dot here represents the current path
Detailed explanation of commonly used Linux commands (worth collecting)
  • -R: List all subdirectories files under (recursively), all files in the directory will be listed
Detailed explanation of commonly used Linux commands (worth collecting)
  • -n: Use numeric UID or GID instead of name
Detailed explanation of commonly used Linux commands (worth collecting)

There are some other options that I won’t demonstrate. You can try them if you go down.

  • -1 Output only one file per line
  • -r Sort the directory in reverse order
  • -k to The size of the file in k bytes. ls –alk specifies the file
  • #-i to output the index information of the i node of the file. For example, ls –ai specifies the file-
  • -t and sorts it by time

file command

Function: View file type

Syntax: file [file]

[king@VM-12-11-centos ~]$ file cat.txt
cat.txt: UTF-8 Unicode text             #类型是文本文件
[king@VM-12-11-centos ~]$ file ret      #类型是目录文件
ret: directory

pwd command

Syntax: pwd

Function: Display the current path

Detailed explanation of commonly used Linux commands (worth collecting)

whoami command

Function: Display the current user

Two writing methods

Detailed explanation of commonly used Linux commands (worth collecting)

cd Command

Function: switch path

Usage: cd [the path you want to switch]

Linux manages files in a multi-tree structure. The files and directories on the disk are composed of a directory tree. Each node is a directory or file. Root directory: /

Detailed explanation of commonly used Linux commands (worth collecting)

Relative path and absolute path

When we need to find a file, You must know the path and file name of the file, such as looking for the text.c file, because each node has only one parent node, and the path from the root directory to the text.c file is unique. . The path that completely describes the file location is the absolute path. The absolute path can uniquely identify a file. The pwd command above displays the absolute path

Detailed explanation of commonly used Linux commands (worth collecting)

The relative path is: its own path relative to the target location, which is not unique. We can find the file from different locations

Detailed explanation of commonly used Linux commands (worth collecting)
  • Absolute path: The path from the following directory to the specified file, which can uniquely identify a file

  • Relative path: The path from a certain file to the specified file. It cannot uniquely identify a file.

The cd command can switch paths between relative paths and absolute paths.

You can switch to the specified directory through the absolute path

Detailed explanation of commonly used Linux commands (worth collecting)

也可以通过相对路径切换,点点表示上一级路径,cd ..切换到上一级目录,cd ../../切换到上上级路径

Detailed explanation of commonly used Linux commands (worth collecting)
[king@VM-12-11-centos Linuxclass]$ pwd
/home/king/Linuxclass
[king@VM-12-11-centos Linuxclass]$ cd classcode
[king@VM-12-11-centos classcode]$ ls
a.out  ret.txt  test  test.c
[king@VM-12-11-centos classcode]$ cd test
[king@VM-12-11-centos test]$ cd ../../p1        #切换到上上级目录的p1路径下
[king@VM-12-11-centos p1]$ pwd
/home/king/Linuxclass/p1

有的小伙伴可能就有疑问了,cd ..可以切换到上一级路径,那么cd .有什么用呢?我们本来就在当前目录下,不需要切换啊。

这里我们用vim编写一个hello Linux的代码,通过gcc编译,生成a.out的可执行程序,而我们要运行可执行程序就需要路径和文件名,用点就可以表示它的路径了,相比于下面用绝对路径方便很多

Detailed explanation of commonly used Linux commands (worth collecting)

cd还有两个选项

[king@VM-12-11-centos Linuxclass]$ pwd
/home/king/Linuxclass
[king@VM-12-11-centos Linuxclass]$ cd ~    #cd ~进入工作目录,就是用户的路径下
[king@VM-12-11-centos ~]$ pwd
/home/king
[king@VM-12-11-centos ~]$ cd -             #cd -返回最近一次访问的路径
/home/king/Linuxclass

which指令

语法:which [指令]

功能:查看指令的系统路径和相关信息

[king@VM-12-11-centos Linuxclass]$ which ls
alias ls='ls --color=auto'                     #alias:给指令取别名
 /usr/bin/ls                                #我们的指令都是系统简化过的
[king@VM-12-11-centos Linuxclass]$ which ll        
alias ll='ls -l --color=auto'                  #ll可以代替ls -l
 /usr/bin/ls                                     
[king@VM-12-11-centos Linuxclass]$ which cd    #同时我们发现指令都是在bin目录下的
/usr/bin/cd
Detailed explanation of commonly used Linux commands (worth collecting)

指令本质上就是程序,Linux中,指令、命令、工具都是可执行程序 ,都存放在普通文件中,linux下一切皆文件,我们的指令都在bin目录下

Detailed explanation of commonly used Linux commands (worth collecting)

touch指令

功能:新建文件,更改文档或目录的日期,包括存取时间和更改时间,我们先了解新建文件,关于更改目录日期我们在文章的最后介绍

需要注意的是touch创建的是普通文件,不是目录文件,所以不能cd进入

[king@VM-12-11-centos test]$ touch file1 file2 file3   #touch可以连续创建多个文件
[king@VM-12-11-centos test]$ touch file4               #创建单个文件
[king@VM-12-11-centos test]$ ls
file1  file2  file3  file4

mkdir指令

功能:新建目录文件

mkdir也可以同时创建多个目录文件,cd可以进入,但是不能在一个目录文件下再创建多个子目录,这里就显示无法创建

Detailed explanation of commonly used Linux commands (worth collecting)

选项-p:递归建立多个子目录

Detailed explanation of commonly used Linux commands (worth collecting)

添加用户信任关系

这里的tree指令是以树状显示文件,需要用yum下载

yum intsall -y tree

如果我们是普通用户,需要在前面加sudo, sudo可以短暂提升权限,以root的身份执行相应指令

单独su表示切换为root用户,需要输入root用户的密码

Detailed explanation of commonly used Linux commands (worth collecting)
[ret@VM-12-11-centos ~]$ su
Password:                            #输入root用户密码
[root@VM-12-11-centos ret]# whoami   #切换为root用户
root
[root@VM-12-11-centos ret]# su ret  #root用户可以直接切换成指定用户,不需要输入用户密码
[ret@VM-12-11-centos ~]$ whoami     #现在我们就切换到用户ret了
ret

如果我们sudo yum install -y tree显示类似如下的指令,表示当前用户没有添加信任关系

Detailed explanation of commonly used Linux commands (worth collecting)

需要以root的身份帮用户添加信任关系,我们将身份切换为root用户,执行如下指令即可添加信任关系,之后我们就可以sudo 了

echo 'xxx ALL=(ALL) ALL' >> /etc/sudoers  (其中xxx代表用户名)

rmdir指令

功能:删除空目录 ,也就是不存放其他文件的目录

这里p1不为空,所以无法删除,如要借助rm指令

Detailed explanation of commonly used Linux commands (worth collecting)

rm指令

我们删除文件一般都用rm指令,rmdir有点鸡肋

功能:删除目录或文件

选项:

  • -f:强制删除
  • -r:删除目录及目录下的所有文件,以递归的方式。

删除目录要带r选项,此时我们的p1/p2/p3就删除了

Detailed explanation of commonly used Linux commands (worth collecting)

如果我们想删除目录中的所以文件而不想删除目录,直接加通配符*

Detailed explanation of commonly used Linux commands (worth collecting)

切记别把根目录给删除

rm -rf /    #切记不要使用,递归强制删除根目录,可能会把系统干崩

man指令

linux中有很多的指令,如果我们不记得某个指令的使用,可以man一下,问问那个男人

选项:

1 是普通的命令

2 是系统调用,如open,write之类的(通过这个,至少可以很方便的查到调用这个函数,需要加什么头文 件)

3 是库函数,如printf,fread4是特殊文件,也就是/dev下的各种设备文件

5 是指文件的格式,比如passwd, 就会说明这个文件中各个字段的含义

6 是给游戏留的,由各个游戏自己定义

7 是附件还有一些变量,比如向environ这种全局变量在这里就有说明

8 是系统管理用的命令,这些命令只能由root使用,如ifconfig

9 内核例程

我们目前先了解 1 和 3

同样man需要我们下载 ,普通用户加sudo

yum install -y man-pages

man不加选项,默认解释指令

[king@VM-12-11-centos file11]$ man ls

q退出当前界面

Detailed explanation of commonly used Linux commands (worth collecting)
[king@VM-12-11-centos file11]$ man 3 printf   #我们可以查看printf库函数
Detailed explanation of commonly used Linux commands (worth collecting)

cp指令

语法:cp [选项] [源文件] [目标文件] [指定目录]

功能:复制文件或目录

常用选项:

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

  • -r    递归处理,将指定目录下的文件与子目录一并处理。

We copy the file file11 and name it file

Detailed explanation of commonly used Linux commands (worth collecting)

Copied to the current directory by default, you can also specify the directory at the end

mv command

Function: move files or rename files

Usage:mv [options] [source file] [target file]

Options:

  • -f: force means force. If the target file already exists, it will be overwritten directly without asking.

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

Here we move the file file11 to the file directory

Detailed explanation of commonly used Linux commands (worth collecting)

If mv is not followed by a file, but filename, the file will be renamed. In addition, when searching for public accounts, Linux should learn how to reply "monkey" in the background and get a surprise gift package.

For example, rename the file file11 to change

Detailed explanation of commonly used Linux commands (worth collecting)

cat command

Function: View file content

Syntax: cat [options] [file]

Options:

  • -b: Number non-empty output lines

  • -n: Number all output lines

  • -s: Do not output multiple blank lines

Detailed explanation of commonly used Linux commands (worth collecting)

##echo command

Function: Display the string to the standard output, that is, on the screen, echo defaults to newline

Detailed explanation of commonly used Linux commands (worth collecting)

Redirect

Can we write the string to a file?

The answer is yes. By redirecting and adding the > symbol and the file name after the string, you can write the string that should be displayed to the standard output into the file. If the file does not exist, just The file will be automatically created. This is output redirection.

Detailed explanation of commonly used Linux commands (worth collecting)

writes the string that should be displayed on the screen into the target file. At the same time, output redirection will clear the original content of the file. Re-write

When writing this, the previous hello Linux has been almost cleared

Detailed explanation of commonly used Linux commands (worth collecting)

If you want to keep the previous content and write it, It is necessary to append the redirection > symbol to become >> symbol

Detailed explanation of commonly used Linux commands (worth collecting)

No file is added after the cat command. By default, the content is read from the keyboard and echoed to the monitor. That is

on the screen
Detailed explanation of commonly used Linux commands (worth collecting)

之前cat显示文件内容就是通过输入重定向显示的

[king@VM-12-11-centos ~]$ cat < file   #这个 < 符号可以省略
AAAAAAA
BBBBBBB
CCCCCCC

more指令

功能:和cat类似,一般用于查看日志,内容比较长的文件

选项:

  • -n :对行编号

  • q :退出more

比如这里我写一个内容从0-1000行的文件

关注公众号:【Linux就该这样学】,在公众号中回复:Linux

count=0; while [ $count -le 1000 ]; do echo "hello ${count}"; let count++; done > cat.txt
Detailed explanation of commonly used Linux commands (worth collecting)

more会先显示一部分内容,按回车就可以继续读取内容,按q退出,但more有一个弊端,只能往下翻,不能往上翻,所以我们一般不用more指令

less指令

功能:查看文件内容,less用法比more更具有弹性,可以使用 [pageup][pagedown] (前后按键)等按键的功能来往前往后翻看文件,而且less在查看之前不会加载整个文件。

选项:

  • -i   :忽略大小写

  • -N: Display the line number

  • ##/String: Search the content of the string upward

  • ?String: Search down the content of the string

  • n: Before repeating A search (related to / or ?)

  • N: Go back and repeat the previous search (related to / or ?)

  • q:Exit less

[king@VM-12-11-centos ~]$ less cat.txt
Detailed explanation of commonly used Linux commands (worth collecting)

我们输入 /3向上搜索字符3,less就会帮我们标记字符3的内容

Detailed explanation of commonly used Linux commands (worth collecting)

还有其它选项大家可以直接尝试,这里就不在演示了,我们q退出less界面

牛逼啊!接私活必备的 N 个开源项目!赶快收藏吧

head 指令

功能:显示文件内容的开头到标准输出,也就是屏幕上,head不加参数默认显示前10行

选项:

-n1dcc53fc8cc7b2478796660caa67152b

[king@VM-12-11-centos ~]$ head cat.txt    #默认输出前10行
hello 0
hello 1
hello 2
hello 3
hello 4
hello 5
hello 6
hello 7
hello 8
hello 9
[king@VM-12-11-centos ~]$ head -n5 cat.txt   #指定输出前5行
hello 0
hello 1
hello 2
hello 3
hello 4
[king@VM-12-11-centos ~]$ head -5 cat.txt    # n可以省略
hello 0
hello 1
hello 2
hello 3
hello 4

tail指令

功能:用于显示指定文件末尾内容,我们一般查看日志时肯定是查看最新的内容,也就是从尾部开始查看,tail就能很好的帮助我们查看最近的内容

选项:

  • -f :循环读取

  • -nbdaa72d45a486872e32cf8bb600e37b8 :显示行数

tail - f filename会把filename里最尾部的内容显示在屏幕上,并且不但刷新,使你看到最新的文件内容,非常适合查看日志

[king@VM-12-11-centos ~]$ tail cat.txt   #tail不加行号默认显示尾10行
hello 991
hello 992
hello 993
hello 994
hello 995
hello 996
hello 997
hello 998
hello 999
hello 1000
[king@VM-12-11-centos ~]$ tail -n5 cat.txt  #指定显示尾5行
hello 996
hello 997
hello 998
hello 999
hello 1000
[king@VM-12-11-centos ~]$ tail -5 cat.txt   #n可以省略
hello 996
hello 997
hello 998
hello 999
hello 1000

那我们可以显示文件的头和尾,如果要显示文件中间的内容怎么办呢?

比如我们要显示第100行到110行,有两种方法:

通过重定向将前110行写入一个tmp临时文件,然后在读取尾10行,不过这种方法需要重新创建文件,不进浪费空间效率也低

Detailed explanation of commonly used Linux commands (worth collecting)

答案是有的,第二种方法借助管道操作

管道操作
Detailed explanation of commonly used Linux commands (worth collecting)

使用管道时,默认隐式发生了重定向

# 符号 | 表示管道,通过管道将执行的结果传给下一条指令
[king@VM-12-11-centos ~]$ head -110 cat.txt | tail -10 
hello 100
hello 101
hello 102
hello 103
hello 104
hello 105
hello 106
hello 107
hello 108
hello 109

date指令

格式

  • %H : 小时(00..23)
  • %M : 分钟(00..59)
  • %S : 秒(00..61)
  • %X : 相当于 %H:%M:%S
  • %d : 日 (01..31)
  • %m : 月份 (01..12)
  • %Y : 完整年份 (0000..9999)
  • %F : 相当于 %Y-%m-%d
[king@VM-12-11-centos ~]$ date                 #date默认显示
Fri Jan 28 16:55:54 CST 2022
[king@VM-12-11-centos ~]$ date +%s             #date +%s显示时间戳
1643360162
[king@VM-12-11-centos ~]$ date +%F%X           #按年月日 时分秒的格式显示当前时间
2022-01-2804:56:08 PM
[king@VM-12-11-centos ~]$ date +%F%X@1643360162  # @时间戳,将时间戳转换成标准时间
2022-01-2804:56:27 PM@1643360162

我们可以加_以示区分,但不能是空格,这种写法是错误的

Detailed explanation of commonly used Linux commands (worth collecting)

cal command

Function: View calendar

Options:

  • -3 Display the system’s calendar of the previous month, current month, and next month

  • -y Display the calendar of the current year

  • cal displays the current month’s calendar by default

Detailed explanation of commonly used Linux commands (worth collecting)
[king@VM-12-11-centos ~]$ cal -y 2021  #也可以指定年份显示2021的年历

find指令

功能:在文件数中查找文件,并做出相应的处理(可能会访问磁盘),find指令会帮我们在当前目录以及所有该目录的所以子目录下查找相应的文件,当我们遍历一个大的文件系统时,可能会花费一点时间,然后显示相应的文件信息,但当我们下一次再用find查找时,就会快很多

find的选项非常多,这里列举一个,想了解更多可以man find

选项:-name  :按照文件名查找

我们在根目录下查找文件名为text的文件,不过这里很多都是permission denied,因为普通用户的权限不够,有很多文件都不能读取。另外,搜索公众号后端架构师后台回复“架构整洁”,获取一份惊喜礼包。

Detailed explanation of commonly used Linux commands (worth collecting)

我们在自己的目录下查找文件名为file的文件,就会把该目录下的所以子文件名为file的显示出来

Detailed explanation of commonly used Linux commands (worth collecting)

Specify directory

Syntax: find [starting directory location] [-name][filename]

Detailed explanation of commonly used Linux commands (worth collecting)

grep command

Function: text line filtering, search string

Common options:

  • -i: Ignore upper and lower case, upper and lower cases are treated as the same

  • -n: Output line number

  • ##-v: Reverse selection

Let’s take the file whose content is 0-1000 lines

cat.txtExample

When we display the file content, we will bring '90' All the characters are displayed

Detailed explanation of commonly used Linux commands (worth collecting)
We use output redirection to write two lines into the file, and -i ignores case, so that both lines can be searched out

Detailed explanation of commonly used Linux commands (worth collecting)

同时grep指令也支持正则表达式,可以搜索 任意我们想要搜索的字符,大家下去可以自行尝试

我们先追加两行到cat.txt中,用正则表达式就可以将这两行搜索出来

[king@VM-12-11-centos ~]$ echo "he9999" >> cat.txt
[king@VM-12-11-centos ~]$ echo "he9290" >> cat.txt
[king@VM-12-11-centos ~]$ cat cat.txt | grep &#39;he[0-9]*$&#39;   
he9290
he9999

zip指令/unzip指令

zip语法:zip [压缩后的文件名.zip] [目标文件]

功能:将文件压缩成.zip格式

常用选项:

  • -r: Process all files and subdirectories in the specified directory together, recursively

  • unzip Syntax: unzip [compressed file.zip]

  • -d: Compress to the specified path

If we do not add the -r option, compress the file directly

We take the compressed test file as an example, in which test also has 3 subdirectories file, file22 and file33, the compressed file.zip The size is only 160

Detailed explanation of commonly used Linux commands (worth collecting)

After decompression, I found that the test file was an empty directory and did not help us compress all the files

Detailed explanation of commonly used Linux commands (worth collecting)

So we need to bring the option -r. After decompression, we found that the size of cur.zip is 774, which is significantly larger than the previous 160

Detailed explanation of commonly used Linux commands (worth collecting)

Add option -d to extract cur.zip to the ret file at the specified path

Detailed explanation of commonly used Linux commands (worth collecting)

tar command

andzip/unzip is similar, but the decompressed file suffix is ​​.tgz

Function: Complete packaging, compression, and decompression

Options:

  • -c: Parameter command to create a compressed file (meaning create)
  • ##-x: Parameter command to unzip a compressed file
  • -t: View the files in tarfile!
  • -z: Does it also have the attributes of gzip? That is, do I need to use gzip compression?
  • -j: Does it also have the attributes of bzip2? That is, do I need to use bzip2 compression?
  • -v: Display files during compression! This is commonly used, but it is not recommended to be used in background execution processes!
  • -f: Use the file name. Please note that the file name must be followed immediately after f! Don't add any more parameters!
  • -C: Extract to the specified directory
  • Usually -czf and -xzf Used in conjunction with compression and decompression, here we also move the compressed file cur.tgz to the test directory for decompression

    Detailed explanation of commonly used Linux commands (worth collecting)

    Here we Specify the path of the compressed file cur.tgz through the -C option, and extract the file to the ret directory

    Detailed explanation of commonly used Linux commands (worth collecting)

    The previous operations are all decompression and compression, while packaging is to package all the files that need to be compressed together. It can be understood that the size of the files does not change after all the files are organized

    bc command

    Function: It can be understood as a calculator

    Display the calculation results directly on the screen,Ctrl cExit

    Detailed explanation of commonly used Linux commands (worth collecting)

    uname command

    Function: Get computer and operating system related information

    Options:

    • -a: Output detailed information, in order: kernel name, host name, kernel version number, kernel version, hardware name, processor type, hardware platform type, operating system name

    • -r: Output the kernel version number

    ##uname outputs the kernel name by default, and hostname outputs the host name by default. In fact, we only need the -a option

    Kernel version number: 3 represents the major version number, 10 represents the minor version number, where the minor version number is an even number: the stable version kernel is an odd number: test Version kernel, the kernel version used by our servers is generally not the latest, but some classic versions that have been used for many years. Brand-new versions need to pass the test of time to prove that the kernel is stable, safe, and efficient before they can be used.

    Detailed explanation of commonly used Linux commands (worth collecting)

    shutdown command

    Options:

    • -h: Stop the system service and shut down immediately

    • -r: Stop the system service Restart after

    - -t second:-t [number of seconds], that is, shut down after a few seconds

    ForServerWe don’t need to shut down the computer

    Here we add the change time of the touch command

    Before introducing the touch modification file time, we first introduce a command

    stat command

    Function: View file details

    Usage:stat [file]

    stat View test File details

    Detailed explanation of commonly used Linux commands (worth collecting)

    Related information about the file:

    • File: Display the file name
    • Size: Display the file size
    • Blocks: Total number of data blocks used by the file
    • IO Block: IO block size
    • regular file: File type (regular file)
    • Device: Device number
    • Inode: Inode number
    • Links: Number of links
    • Access: File permissions
    • Gid, Uid: File ownership Gid and Uid

    Three times under Linux

    1. Access Time: abbreviated as atime, indicating the last time the file was accessed.
    2. Modify Time: abbreviated as mtime, indicating the time when the file content was last modified
    3. ##Change Time : The abbreviation is ctime, which indicates the time when the file attributes were last modified.
    atime: When we view the file with cat after a while, stat will send the atime time when we view it again. Changes have occurred. Of course, for kernels after 2.6, the rules for the refresh time of atime have been reset. Atime will not be updated immediately, but the OS will automatically update the time after a certain interval. Because compared to modifying file content and attributes, viewing files is the most frequent. If atime is refreshed frequently, the efficiency will be reduced

    Detailed explanation of commonly used Linux commands (worth collecting)

    For mtime: After we write hell, its three times have changed. The change of mtime will not necessarily affect atime, but ctime may change accordingly because the file is modified. When writing content, it is possible to modify the attributes of the file. For example, the size attribute of the file will be modified when writing data.

    Detailed explanation of commonly used Linux commands (worth collecting)

    ctime: The most recent time when the file attributes were changed, this line indicates The most important thing is the file attributes

    Detailed explanation of commonly used Linux commands (worth collecting)
    Detailed explanation of commonly used Linux commands (worth collecting)
    ## The chgmod command can change the access permissions of the file, which also changes the file attributes

    touch command supplement

    options:

    • -a Change atime and ctime
    • -c or --no-create Do not create any documents.
    • -d Use the specified date and time instead of the current time to change atime and mtime
    • -f This parameter will be ignored Processing, only responsible for solving the compatibility issues of the BSD version of the touch command.
    • -m Change ctime and mtime
    • -r Set the date and time of the specified document or directory to the same as the reference document or directory The date and time are the same.
    • -t Use the specified date and time instead of the current time

    Commonly used are -d, -a -m, and touch The command modifies all times by default. The touch here is to operate on the created file

    Detailed explanation of commonly used Linux commands (worth collecting)

    Hotkeys in Linux

    [Tab]: Command completion, press once or twice, the command starting with wh will be displayed on the screen

    Detailed explanation of commonly used Linux commands (worth collecting)

    [c] : Terminate the current program. For example, if characters are continuously output on the screen and an infinite loop code is written, you can Ctrl cterminate

    [Ctrl d]: Switch identities instead of exit, multiple timesCtrl dExit directly

    Detailed explanation of commonly used Linux commands (worth collecting)

    [Ctrl r]: Search historical commands based on keywords. We enter r and it will be automatically converted into historical commands

    Detailed explanation of commonly used Linux commands (worth collecting)

    [page up page down]: Up and down, you can browse historical commands, we can It is very convenient to directly browse the recently entered commands

    List of commands

    • Installation and login commands: login, shutdown, halt, reboot, install, mount, umount, chsh, exit, last

    • ##File processing commands:

      file, mkdir, grep, dd, find, mv, ls, diff, cat, ln

    • System management related commands:

      df, top, free, quota, at, lp, adduser, groupadd, kill, crontab

    • Network operation commands: ifconfig, ip, ping, netstat, telnet, ftp, route, rlogin, rcp, finger, mail, nslookup

    • System security related commands: passwd, su, umask, chgrp, chmod, chown, chattr, sudo ps, who

    • Other commands: tar, unzip, gunzip, unarj, mtools, man, unendcode, uudecode

    The above is the detailed content of Detailed explanation of commonly used Linux commands (worth collecting). For more information, please follow other related articles on the PHP Chinese website!

    Statement:
    This article is reproduced at:Linux中文社区. If there is any infringement, please contact admin@php.cn delete