目录
Linux基础知识总结(命令行)
实验机器操作系统的发行编号:4.4.0-142-generic
man(手册工具)
man <输入想查询的工具>
uname(查看系统相关信息)
选项
使用上面提到的我们可以看到uname的具体用法,那么让我们来各个学习。
名称
uname - 打印系统信息
用法
uname [选项]...
描述
打印出系统信息
-a, --all
打印出全部信息
-s, --kernel-name
打印出内核的名称
-n, --nodename
打印出网络端点hostname
-r, --kernel-release
打印出操作系统编号
-v, --kernel-version
打印出内核版本
-m, --machine
打印出机器硬件
-p, --processor
打印出处理器名称或者unknown
-i, --hardware-platform
打印出硬件平台名称或"unknown"
-o, --operating-system
打印出操作系统名称
--version
打印出版本信息
例子
xx@xx:~$ uname -a
Linux xx 4.4.0-142-generic #168~14.04.1-Ubuntu SMP Sat Jan 19 11:26:28 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
xx@xx:~$ uname -s
Linux
xx@xx:~$ uname -n
xx
xx@xx:~$ uname -r
4.4.0-142-generic
xx@xx:~$ uname -v
#168~14.04.1-Ubuntu SMP Sat Jan 19 11:26:28 UTC 2019
xx@xx:~$ uname -m
x86_64
xx@xx:~$ uname -p
x86_64
xx@xx:~$ uname -i
x86_64
xx@xx:~$ uname -o
GNU/Linux
pwd(查看当前路径)
选项
名称
pwd - 打印当前地址
用法
pwd [选项]...
描述
打印当前用户所在地址.
-L, --logical
从环境中使用PWD,含有软链接
-P, --physical
物理地址,没有软连接
--version
打印工具版本
例子
xx@xx:~$ pwd -L
/home/xx
xx@xx:~$ pwd -P
/home/xx
cd(改变当前所在位置)
cd可以改变当前用户所在的路径位置。
例子
相对路径:我们可以用pwd查看当前位置,然后ls查看当前路径下的所有文件,然后cd [文件夹名]就可以进入到这个文件夹啦
xx@xx:~/Documents$ pwd
/home/xx/Documents
xx@xx:~/Documents$ ls
folder1
xx@xx:~/Documents$ cd folder1/
xx@xx:~/Documents/folder1$ pwd
/home/xx/Documents/folder1
xx@xx:~/Documents/folder1$
绝对路径:如果想去一个绝对路径,那么可以 cd [绝对路径]
xx@xx:~$ cd /home/xx/Documents/folder1/
xx@xx:~/Documents/folder1$ pwd
/home/xx/Documents/folder1
返回用户根目录:cd ~ 可以带你回到当前用户的根目录
xx@xx:~/Documents/folder1$ pwd
/home/xx/Documents/folder1
xx@xx:~/Documents/folder1$ cd ~
xx@xx:~$ pwd
/home/xx
cat(显示文件内容)
选项
名称
cat - 将文件打印至屏幕
用法
cat [选项]... [文件]...
描述
将文件(们)打印至standard input或者standard output,也就是STDIN,STDOUT
-A, --show-all
显示全部,也可以使用(-vET)
-b, --number-nonblank
显示内容加上行数(忽略空白行)
-e
是-vE的简写
-E, --show-ends
在每一行的末尾加上$,为了让我们更方便看出来
-n, --number
显示内容加上行数(不忽略空白行)
-s, --squeeze-blank
显示除空白行之外的内容
-t
是-vT的简写
-T, --show-tabs
将Tab符号显示成^I
-v, --show-nonprinting
use ^ and M- notation, except for LFD and TAB
--help display this help and exit
--version
output version information and exit
例子
显示内容加上行数(忽略空白行) cat -b fork.c
xx@xx:~/linux$ cat -b fork.c
1 #include <stdio.h>
2 #include <sys/types.h>
3 #include <unistd.h>
4 int main()
5 {
6 printf("Program Start
");
7 fork();
8 fork();
9 printf("hello from: %d, my parent is: %d
", getpid(), getppid());
10 sleep(1);
11 return 0;
12 }
xx@xx:~/linux$
显示内容加上行数(不忽略空白行) cat -n fork.c
xx@xx:~/linux$ cat -n fork.c
1 #include <stdio.h>
2 #include <sys/types.h>
3 #include <unistd.h>
4 int main()
5 {
6 printf("Program Start
");
7 fork();
8 fork();
9 printf("hello from: %d, my parent is: %d
", getpid(), getppid());
10 sleep(1);
11 return 0;
12 }
13
14
15
xx@xx:~/linux$
在每一行的末尾加上$,为了让我们更方便看出来
xx@xx:~/linux$ cat -E fork.c
#include <stdio.h>$
#include <sys/types.h>$
#include <unistd.h>$
int main()$
{$
printf("Program Start
");$
fork(); $
fork();$
printf("hello from: %d, my parent is: %d
", getpid(), getppid());$
sleep(1);$
return 0; $
}$
$
$
$
xx@xx:~/linux$
将Tab符号显示成 ^I
xx@xx:~/linux$ cat -T fork.c
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
^Iprintf("Program Start
");
^Ifork();
^Ifork();
^Iprintf("hello from: %d, my parent is: %d
", getpid(), getppid());
^Isleep(1);
^Ireturn 0;
}
xx@xx:~/linux$
显示全部
xx@xx:~/linux$ cat -A fork.c
#include <stdio.h>$
#include <sys/types.h>$
#include <unistd.h>$
int main()$
{$
^Iprintf("Program Start
");$
^Ifork(); $
^Ifork();$
^Iprintf("hello from: %d, my parent is: %d
", getpid(), getppid());$
^Isleep(1);$
^Ireturn 0; $
}$
$
$
$
xx@xx:~/linux$
ls(查看当前路径下文件)
选项
名称
ls - 显示路径下文件
用法
ls [选项]... [文件]...
描述
显示路径下文件
-a, --all
显示当前路径下所有文件,包括'.', '..'和隐藏文件
-A, --almost-all
显示当前路径下所有文件,只包括隐藏文件
--author
与选项'-l'一起使用可以显示出所有文件和作者名
-b, --escape
print C-style escapes for nongraphic characters
--block-size=SIZE
scale sizes by SIZE before printing them. E.g.,
'--block-size=M' prints sizes in units of 1,048,576 bytes. See
SIZE format below.
-B, --ignore-backups
do not list implied entries ending with ~
-c with -lt: sort by, and show, ctime (time of last modification of
file status information) with -l: show ctime and sort by name
otherwise: sort by ctime, newest first
-C list entries by columns
--color[=WHEN]
colorize the output. WHEN defaults to 'always' or can be
'never' or 'auto'. More info below
-d, --directory
list directory entries instead of contents, and do not derefer‐
ence symbolic links
-D, --dired
generate output designed for Emacs' dired mode
-f do not sort, enable -aU, disable -ls --color
-F, --classify
append indicator (one of */=>@|) to entries
--file-type
likewise, except do not append '*'
--format=WORD
across -x, commas -m, horizontal -x, long -l, single-column -1,
verbose -l, vertical -C
--full-time
like -l --time-style=full-iso
-g like -l, but do not list owner
--group-directories-first
group directories before files.
augment with a --sort option, but any use of --sort=none (-U)
disables grouping
-G, --no-group
in a long listing, don't print group names
-h, --human-readable
与选项'-l'一起使用可以显示适合人类阅读的格式(比如:1K 234M 2G)
--si likewise, but use powers of 1000 not 1024
-H, --dereference-command-line
follow symbolic links listed on the command line
--dereference-command-line-symlink-to-dir
follow each command line symbolic link that points to a direc‐
tory
--hide=PATTERN
do not list implied entries matching shell PATTERN (overridden
by -a or -A)
--indicator-style=WORD
append indicator with style WORD to entry names: none (default),
slash (-p), file-type (--file-type), classify (-F)
-i, --inode
print the index number of each file
-I, --ignore=PATTERN
do not list implied entries matching shell PATTERN
-k, --kibibytes
use 1024-byte blocks
-l
显示当前路径下文件详细信息
-L, --dereference
when showing file information for a symbolic link, show informa‐
tion for the file the link references rather than for the link
itself
-m fill width with a comma separated list of entries
-n, --numeric-uid-gid
like -l, but list numeric user and group IDs
-N, --literal
print raw entry names (don't treat e.g. control characters spe‐
cially)
-o like -l, but do not list group information
-p, --indicator-style=slash
append / indicator to directories
-q, --hide-control-chars
print ? instead of non graphic characters
--show-control-chars
show non graphic characters as-is (default unless program is
'ls' and output is a terminal)
-Q, --quote-name
enclose entry names in double quotes
--quoting-style=WORD
use quoting style WORD for entry names: literal, locale, shell,
shell-always, c, escape
-r, --reverse
reverse order while sorting
-R, --recursive
list subdirectories recursively
-s, --size
print the allocated size of each file, in blocks
-S sort by file size
--sort=WORD
sort by WORD instead of name: none -U, extension -X, size -S,
time -t, version -v
--time=WORD
with -l, show time as WORD instead of modification time: atime
-u, access -u, use -u, ctime -c, or status -c; use specified
time as sort key if --sort=time
--time-style=STYLE
with -l, show times using style STYLE: full-iso, long-iso, iso,
locale, +FORMAT. FORMAT is interpreted like 'date'; if FORMAT
is FORMAT1<newline>FORMAT2, FORMAT1 applies to non-recent files
and FORMAT2 to recent files; if STYLE is prefixed with 'posix-',
STYLE takes effect only outside the POSIX locale
-t sort by modification time, newest first
-T, --tabsize=COLS
assume tab stops at each COLS instead of 8
-u with -lt: sort by, and show, access time with -l: show access
time and sort by name otherwise: sort by access time
-U do not sort; list entries in directory order
-v natural sort of (version) numbers within text
-w, --width=COLS
assume screen width instead of current value
-x list entries by lines instead of by columns
-X sort alphabetically by entry extension
-Z, --context
print any SELinux security context of each file
-1 list one file per line
--help display this help and exit
--version
output version information and exit
例子
显示当前路径下所有文件,包括'.', '..'和隐藏文件
xx@xx:~/linux$ ls -a
. .. fork fork.c .hiddenfile.txt
显示当前路径下所有文件,只包括隐藏文件
xx@xx:~/linux$ ls -A
fork fork.c .hiddenfile.txt
显示当前路径下所有文件详细信息
xx@xx:~/linux$ ls -l
total 16
-rwxrwxr-x 1 xx xx 8816 Jan 28 01:01 fork
-rw-rw-r-- 1 xx xx 218 Jan 28 15:31 fork.c
与选项'-l'一起使用可以显示出所有文件和作者名
xx@xx:~/linux$ ls -l --author
total 16
-rwxrwxr-x 1 xx xx xx 8816 Jan 28 01:01 fork
-rw-rw-r-- 1 xx xx xx 218 Jan 28 15:31 fork.c
与选项'-l'一起使用可以显示适合人类阅读的格式(比如:1K 234M 2G)
xx@xx:~/linux$ ls -lh
total 16K
-rwxrwxr-x 1 xx xx 8.7K Jan 28 01:01 fork
-rw-rw-r-- 1 xx xx 218 Jan 28 15:31 fork.c
df(查看空间使用情况)
选项
名称
df - 显示文件系统空间用量
用法
df [OPTION]... [FILE]...
描述
显示文件系统空间用量和其他数据
-a, --all
显示全部文件系统用量
-B, --block-size=SIZE
调整打印出来的size,用'-BM'显示以1,048,576 bytes为单位
-h, --human-readable
和其他选项一起使用,将格式变成人类方便阅读的格式 (e.g., 1K 234M 2G)
-H, --si
likewise, but use powers of 1000 not 1024
-i, --inodes
list inode information instead of block usage
-k like --block-size=1K
-l, --local
limit listing to local file systems
--no-sync
do not invoke sync before getting usage info (default)
--output[=FIELD_LIST]
use the output format defined by FIELD_LIST, or print all fields
if FIELD_LIST is omitted.
-P, --portability
use the POSIX output format
--sync invoke sync before getting usage info
--total
elide all entries insignificant to available space, and produce
a grand total
-t, --type=TYPE
limit listing to file systems of type TYPE
-T, --print-type
print file system type
-x, --exclude-type=TYPE
limit listing to file systems not of type TYPE
-v (ignored)
--help display this help and exit
--version
output version information and exit
例子
显示全部文件系统用量
xx@xx:~$ df -a
Filesystem 1K-blocks Used Available Use% Mounted on
sysfs 0 0 0 - /sys
proc 0 0 0 - /proc
udev 1010640 4 1010636 1% /dev
devpts 0 0 0 - /dev/pts
tmpfs 204828 840 203988 1% /run
/dev/sda1 8124856 4380336 3308760 57% /
none 4 0 4 0% /sys/fs/cgroup
none 0 0 0 - /sys/fs/fuse/connections
none 0 0 0 - /sys/kernel/debug
none 0 0 0 - /sys/kernel/security
none 5120 0 5120 0% /run/lock
none 1024140 76 1024064 1% /run/shm
none 102400 28 102372 1% /run/user
none 0 0 0 - /sys/fs/pstore
systemd 0 0 0 - /sys/fs/cgroup/systemd
gvfsd-fuse 0 0 0 - /run/user/1000/gvfs
和其他选项一起使用,将格式变成人类方便阅读的格式 (e.g., 1K 234M 2G)
xx@xx:~$ df -ah
Filesystem Size Used Avail Use% Mounted on
sysfs 0 0 0 - /sys
proc 0 0 0 - /proc
udev 987M 4.0K 987M 1% /dev
devpts 0 0 0 - /dev/pts
tmpfs 201M 840K 200M 1% /run
/dev/sda1 7.8G 4.2G 3.2G 57% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
none 0 0 0 - /sys/fs/fuse/connections
none 0 0 0 - /sys/kernel/debug
none 0 0 0 - /sys/kernel/security
none 5.0M 0 5.0M 0% /run/lock
none 1001M 76K 1001M 1% /run/shm
none 100M 28K 100M 1% /run/user
none 0 0 0 - /sys/fs/pstore
systemd 0 0 0 - /sys/fs/cgroup/systemd
gvfsd-fuse 0 0 0 - /run/user/1000/gvfs
top(查看实时系统运行总结信息)
名称
top - 显示Linux进程
用法
top -hv|-bcHiOSs -d secs -n max -u|U user -p pid -o fld -w [cols]
描述
显示Linux进程,和系统实时信息
-h | -v :Help/Version
Show library version and the usage prompt, then quit.
-b :Batch-mode operation
Starts top in 'Batch' mode, which could be useful for sending
output from top to other programs or to a file. In this
mode, top will not accept input and runs until the iterations
limit you've set with the '-n' command-line option or until
killed.
-c :Command-line/Program-name toggle
Starts top with the last remembered 'c' state reversed.
Thus, if top was displaying command lines, now that field
will show program names, and visa versa. See the 'c' inter‐
active command for additional information.
-d :Delay-time interval as: -d ss.t (secs.tenths)
Specifies the delay between screen updates, and overrides the
corresponding value in one's personal configuration file or
the startup default. Later this can be changed with the 'd'
or 's' interactive commands.
Fractional seconds are honored, but a negative number is not
allowed. In all cases, however, such changes are prohibited
if top is running in 'Secure mode', except for root (unless
the 's' command-line option was used). For additional infor‐
mation on 'Secure mode' see topic 6a. SYSTEM Configuration
File.
-H :Threads-mode operation
Instructs top to display individual threads. Without this
command-line option a summation of all threads in each
process is shown. Later this can be changed with the 'H'
interactive command.
-i :Idle-process toggle
Starts top with the last remembered 'i' state reversed. When
this toggle is Off, tasks that have not used any CPU since
the last update will not be displayed. For additional infor‐
mation regarding this toggle see topic 4c. TASK AREA Com‐
mands, SIZE.
-n :Number-of-iterations limit as: -n number
Specifies the maximum number of iterations, or frames, top
should produce before ending.
-o :Override-sort-field as: -o fieldname
Specifies the name of the field on which tasks will be
sorted, independent of what is reflected in the configuration
file. You can prepend a '+' or '-' to the field name to also
override the sort direction. A leading '+' will force sort‐
ing high to low, whereas a '-' will ensure a low to high
ordering.
This option exists primarily to support automated/scripted
batch mode operation.
-O :Output-field-names
This option acts as a form of help for the above -o option.
It will cause top to print each of the available field names
on a separate line, then quit. Such names are subject to nls
translation.
-p :Monitor-PIDs mode as: -pN1 -pN2 ... or -pN1,N2,N3 ...
Monitor only processes with specified process IDs. This
option can be given up to 20 times, or you can provide a
comma delimited list with up to 20 pids. Co-mingling both
approaches is permitted.
A pid value of zero will be treated as the process id of the
top program itself once it is running.
This is a command-line option only and should you wish to
return to normal operation, it is not necessary to quit and
restart top -- just issue any of these interactive com‐
mands: '=', 'u' or 'U'.
The 'p', 'u' and 'U' command-line options are mutually exclu‐
sive.
-s :Secure-mode operation
Starts top with secure mode forced, even for root. This mode
is far better controlled through the system configuration
file (see topic 6. FILES).
-S :Cumulative-time toggle
Starts top with the last remembered 'S' state reversed. When
'Cumulative time' mode is On, each process is listed with the
cpu time that it and its dead children have used. See the
'S' interactive command for additional information regarding
this mode.
-u | -U :User-filter-mode as: -u | -U number or name
Display only processes with a user id or user name matching
that given. The '-u' option matches on effective user
whereas the '-U' option matches on any user (real, effective,
saved, or filesystem).
Prepending an exclamation point ('!') to the user id or name
instructs top to display only processes with users not match‐
ing the one provided.
The 'p', 'u' and 'U' command-line options are mutually exclu‐
sive.
-w :Output-width-override as: -w [ number ]
In 'Batch' mode, when used without an argument top will for‐
mat output using the COLUMNS= and LINES= environment vari‐
ables, if set. Otherwise, width will be fixed at the maximum
512 columns. With an argument, output width can be decreased
or increased (up to 512) but the number of rows is considered
unlimited.
In normal display mode, when used without an argument top
will attempt to format output using the COLUMNS= and LINES=
environment variables, if set. With an argument, output
width can only be decreased, not increased. Whether using
environment variables or an argument with -w, when not in
'Batch' mode actual terminal dimensions can never be
exceeded.
Note: Without the use of this command-line option, output
width is always based on the terminal at which top was
invoked whether or not in 'Batch' mode.
vi(文本编辑器,Unix Visual Editor)
用法
名称
vi - 文本编辑器
用法
vi [-rR] [-c command] [-t tagstring] [-w size] [文件名..]
描述
文本编辑器
vi编辑器打开file.txt文件
xx@xx:~/folder$ vi file.txt
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
"file.txt" [New File] 0,0-1 All
输入i进入编辑模式
~
~
~
~
~
~
~
~
-- INSERT -- 0,1 All
进入输入模式我们就可以开始输入文字啦~
摁esc键进入菜单模式
菜单模式可输入指令 | 作用 |
:q | 退出文件 |
:q! | 强制退出文件 |
:w | 保存文件 |
:wq | 保存并退出文件 |
(尽快更新详细分析)
(未完待续,持续总结中...)