Linux常用命令速查表 清除旧文件/dev/null的方法:天天即时看
目录即文件
(资料图)
/dev/null 等价于只写文件.所有写入它的内容都会永远丢失,而尝试从它那儿读取内容则什么也读不到 禁止标准输出. cat $filename >/dev/null # 文件内容丢失,而不会输出到标准输出. 禁止标准错误. 2>/dev/null
/dev/zero 一个永远输出0的设备文件,使用它作输入可以得到全为空的文件.因此可用来创建 新文件和以覆盖的方式清除旧文件 /dev/zero在类UNIX系统中是一个特殊的设备文件 /dev/zero在被读取时会提供无限的空字符(ASCII NUL, 0x00)
换行
windows换行是\r\n(CRLF)-carriage return/line feed linux换行是\n(LF)
配置文件
所有用户的环境变量配置 /etc/profile
linux中各种文件和含义
绿色文件---------- 可执行文件,可执行的程序 红色文件-----------压缩文件或者包文件蓝色文件----------目录 白色文件----------普通,如文本文件,配置文件,源码文件等 浅蓝色文件----------链接文件,主要是使用ln命令建立的文件红色闪烁----------表示链接的文件有问题黄色文件----------表示设备文件灰色文件----------表示其它文件
linux各种信号列表
kill -l
1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP 6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL10) SIGUSR111) SIGSEGV12) SIGUSR213) SIGPIPE14) SIGALRM15) SIGTERM16) SIGSTKFLT17) SIGCHLD18) SIGCONT19) SIGSTOP20) SIGTSTP21) SIGTTIN22) SIGTTOU23) SIGURG24) SIGXCPU25) SIGXFSZ26) SIGVTALRM27) SIGPROF28) SIGWINCH29) SIGIO30) SIGPWR31) SIGSYS34) SIGRTMIN35) SIGRTMIN+136) SIGRTMIN+237) SIGRTMIN+338) SIGRTMIN+439) SIGRTMIN+540) SIGRTMIN+641) SIGRTMIN+742) SIGRTMIN+843) SIGRTMIN+944) SIGRTMIN+1045) SIGRTMIN+1146) SIGRTMIN+1247) SIGRTMIN+1348) SIGRTMIN+1449) SIGRTMIN+1550) SIGRTMAX-1451) SIGRTMAX-1352) SIGRTMAX-1253) SIGRTMAX-1154) SIGRTMAX-1055) SIGRTMAX-956) SIGRTMAX-857) SIGRTMAX-758) SIGRTMAX-659) SIGRTMAX-560) SIGRTMAX-461) SIGRTMAX-362) SIGRTMAX-263) SIGRTMAX-164) SIGRTMAX
ctrl-c 发送 SIGINT 信号给前台进程组中的所有进程 常用于终止正在运行的程序 ctrl-z 发送 SIGTSTP 信号给前台进程组中的所有进程,常用于挂起一个进程 ctrl-d 不是发送信号,而是表示一个特殊的二进制值,表示 EOF ctrl-\ 发送 SIGQUIT 信号给前台进程组中的所有进程,终止前台进程并生成 core 文件
Ctrl+Z强制当前进程转为后台,并使之停止 Ctrl+c前台进程的终止 Ctrl+\表示退出
列出所有资源的限制: ulimit -a
什么是core dump文件
Coredump叫做核心转储,它是进程运行时在突然崩溃的那一刻的一个内存快照 操作系统在程序发生异常而异常在进程内部又没有被捕获的情况下,会把进程此刻内存 、寄存器状态、运行堆栈等信息转储保存在一个文件里
该文件也是二进制文件,可以使用gdb、elfdump、objdump或者windows下的windebug 、solaris下的mdb进行打开分析里面的具体内容
core文件的位置和配置
coredump文件默认存储位置与可执行文件在同一目录下,文件名为core
%p 出Core进程的PID%u 出Core进程的UID%s 造成Core的signal号%t 出Core的时间,从1970-01-0100:00:00开始的秒数%e 出Core进程对应的可执行文件名
可以通过此进行设置
[root@OSSM-1 log]# cat /proc/sys/kernel/core_pattern/export/home/omc/var/logs/core.%e.%p
在每个进程下都有coredump_filter节点/proc//coredump_filter 通过配置coredump_filter可以选择需在coredump的时候,将哪些内容dump到core文件中
- (bit 0) anonymous private memory - (bit 1) anonymous shared memory - (bit 2) file-backed private memory - (bit 3) file-backed shared memory - (bit 4) ELF header pages in file-backed private memory areas (it is effective only if the bit 2 is cleared) - (bit 5) hugetlb private memory - (bit 6) hugetlb shared memory - (bit 7) DAX private memory - (bit 8) DAX shared memory
设置core文件大小
core file size: unlimited:core文件的大小不受限制 0:程序出错时不会产生core文件 1024:代表1024k,core文件超出该大小就不能生成了 设置core文件大小: ulimit -c fileSize 尽量将这个文件大小设置得大一些,程序崩溃时生成Core文件大小即为程序运行时占用的内存大小 可能发生堆栈溢出的时候,占用更大的内存
sysctl
用于运行时配置内核参数, 这些参数位于/proc/sys目录下 用户只需要编辑/etc/sysctl.conf文件,即可手工或自动执行由sysctl控制的功能
sysctl -a显示所有的系统参数 sysctl -p从指定的文件加载系统参数, 如不指定即从/etc/sysctl.conf中加载 sysctl -a | grep core_pattern显示coredump path
常用linux命令
简单命令
在空命令行的情况下退出终端 Ctrl+d重定向子进程的错误输出,让错误输出重定向到标准输出(2>&1) command 2>&1将标准输入stdout和标准输出stderr都重定向到/dev/null command >/dev/null 2>&1id -u 获取指定用户的uid
代表重定向到哪里,例如:echo “123” > /home/123.txt 0 表示stdint标准输入 1 表示stdout标准输出,系统默认值是1,所以">/dev/null"等同于"1>/dev/null" 2 表示stderr标准错误 & 表示等同于的意思,2>&1,表示2的输出重定向等同于1 1>/dev/null 首先表示标准输出重定向到空设备文件,也就是不输出任何信息到终端,说白了就是不显示任何信息。 2>&1 接着,标准错误输出重定向等同于标准输出,因为之前标准输出已经重定向到了空设备文件, 所以标准错误输出也重定向到空设备文件
设置linux系统的空闲等待时间 shell中直接设置TMOUT=0配置/etc/profile文件 export TMOUT=900 # 设置900s内用户无操作就自动断开终端 readonly TMOUT # 将值设置为readonly防止用户更改 查看linux支持的编码 locale -a -a, --all-locales Write names of available locales查看linux系统编码 locale修改linux终端编码
user@kwephis37764:~> export LC_ALL=zh_CN.gbkuser@kwephis37764:~> echo $LC_CTYPEcp936
清空文件内容
逐页阅读 more [options] filename options: -n 定义屏幕大小为n行 +n 从第n行开始显示 常用操作: space键往下一页,b键往回一页显示 / 向下搜索"字符串"的功能 ? 向上搜索"字符串"的功能 =输出当前行的行号 q退出more
显示档案的开头至标准输出中 head [options][filename] -n 行数: 显示的行数 eg: head -n 5 text.txt python.text -c 字节: 显示字节数 eg: head -c 100 /etc/profile
显示指定文件末尾内容,查看日志文件 tail [options] filename options: -f 循环读取 -q 不显示处理信息 -v 显示详细的处理信息 -c 字节 显示的字节数 -n 行数 显示行数
修改文件用户和所有者 chown [-R] 账号名称 文件或目录 chown [-R] 账号名称:用户组名称 文件或目录 eg: chown ossuser:ossgroup install.log 文件拥有者为ossuser,用户组为ossgroup
系统相关命令
linux资源限制配置文件是/etc/security/limits.conf limits.conf文件限制着用户可以使用的最大文件数,最大线程,最大内存等资源使用量
查看系统内存 [root@kwephis37773 6721]# free -g total used free shared buff/cache available Mem: 31 27 0 0 3 3 Swap: 3 3 0 total - This number represents the total amount of memory that can be used by the applications. used - Used memory. It is calculated as: used = total - free - buffers - cache free - Free / Unused memory. shared - This column can be ignored as it has no meaning. It is here only for backward compatibility. buff/cache - The combined memory used by the kernel buffers and page cache and slabs. This memory can be reclaimed at any time if needed by the applications. If you want buffers and cache to be displayed in two separate columns, use the -w option. available - An estimate of the amount of memory that is available for starting new applications, without swapping
查看atime, ctime, mtime
mtime(modify time): 最后一次修改文件或目录的时间ctime(change time) : 最后一次改变文件或目录( 改变的是原数据即: 属性) 的时间 如:记录该文件的inode节点被修改的时间。touch命令除了-d和-t选项外都会改变该时间。而且chmod,chown等命令也能改变该值atime(access time):: 最后一次访问文件或目录的时间 stat filenmae
获取当前内核的名称和信息概要 uname -a
ulimit设置当前shell以及由它启动的进程的资源限制 Provides control over the resources avaliable to the shell and to processes started by it, on systems that allow such control. ulimit命令 -H 使用硬资源控制 -S 使用软资源控制 -a 查看所有的当前限制 -n 能打开的最大文件描述符数 默认是soft limit -t 限制最大的 CPU 占用时间(每秒) -u 限制最大用户进程数 -v 限制虚拟内存大小(kB) eg: ulimit -n默认查看的是soft limit [root@kwephis37773 6721]# ulimit -n 240000 查看hard limit [root@kwephis37773 6721]# ulimit -Hn 240000 [root@kwephis37773 6721]# ulimit -a core file size (blocks, -c) unlimited data seg size (kbytes, -d) unlimited scheduling priority (-e) 0 file size (blocks, -f) unlimited pending signals (-i) 127849 max locked memory (kbytes, -l) 64 max memory size (kbytes, -m) unlimited open files (-n) 240000 pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) 2048 cpu time (seconds, -t) unlimited max user processes (-u) 240000 virtual memory (kbytes, -v) unlimited file locks (-x) unlimited 注意:设置nofile的hard limit还有一点要注意的就是hard limit不能大于/proc/sys/fs/nr_open,假如hard limit大于nr_open,注销后将无法正常登录。 例如,假设用户有 10,000 个块的soft limit和 12,000 个块的hard limit.如果用户的块使用量超过 10,000 个块并且也超过了计时器(超过 7 天),则用户将无法在该文件系统上分配更多磁盘块,直到他或她的使用量降至软限制以下
设置当前shell和shell中创建的进程最大打开文件描述符数 临时设置 #通过ulimit -Sn设置最大打开文件描述符数的soft limit,注意soft limit必须小于hard limit $ ulimit -Sn 160000 #同时设置soft limit和hard limit。对于非root用户只能设置比原来小的hard limit。 $ ulimit -n 180000 永久设置 #root权限下,在/etc/security/limits.conf中添加如下两行,表示所有用户最大打开文件描述符数的soft limit为102400, hard limit为104800。重启生效
单个进程的资源限制 cat /proc//limits Limit Soft Limit Hard Limit Units Max cpu time unlimited unlimited seconds Max file size unlimited unlimited bytes Max data size unlimited unlimited bytes Max stack size 8388608 unlimited bytes Max core file size 0 unlimited bytes Max resident set unlimited unlimited bytes Max processes 29397 29397 processes Max open files 1024 4096 files Max locked memory 65536 65536 bytes Max address space unlimited unlimited bytes Max file locks unlimited unlimited locks Max pending signals 29397 29397 signals Max msgqueue size 819200 819200 bytes Max nice priority 0 0 Max realtime priority 0 0 Max realtime timeout unlimited unlimited us
系统最大打开文件描述符数量 [root@kwephis37773 6721]# cat /proc/sys/fs/file-max 3245657
查看当前系统使用的打开文件描述符数 [root@kwephis37773 6721]# cat /proc/sys/fs/file-nr 39872 0 3245657 其中第一个数表示当前系统已分配使用的打开文件描述符数,第二个数为分配后已释放的(目前已不再使用),第三个数等于file-max
文件校验
计算md5哈希值, echo会默认添加一个换行符 echo -n ‘123456’ | [md5sum, sha1sum, sha256sum] -n可以忽略换行符
进程前后台切换
使进程恢复运行(后台) bg fg将后台中的命令调至前台继续运行 jobs显示当前暂停的进程
查看端口号被哪个进程占用
lsof list open files 需要root权限 lsof -i:8080:查看8080端口占用 lsof abc.txt:显示开启文件abc.txt的进程 lsof -c abc:显示abc进程现在打开的文件 lsof -p 1234:列出进程号为1234的进程所打开的文件 lsof -g gid:显示归属gid的进程情况 lsof +d /usr/local/:显示目录下被进程开启的文件 lsof +D /usr/local/:同上,但是会搜索目录下的目录,时间较长 lsof -d 4:显示使用fd为4的进程 lsof -i -U:显示所有打开的端口和UNIX domain文件
netstat netstat -tunlp 用于显示 tcp,udp 的端口和进程等相关情况 netstat -anp | grep 端口号 netstat -tunlp | grep 端口号 -a Show both listening and non-listening sockets -t (tcp) 仅显示tcp相关选项 -u (udp)仅显示udp相关选项 -n 拒绝显示别名,能显示数字的全部转化为数字 Show numerical addresses instead of trying to determine symbolic host, port or user names. -l 仅列出在Listen(监听)的服务状态 Show only listening sockets. (These are omitted by default.) 默认省略 -p Show the PID and name of the program to which each socket belongs. A hyphen(连字符) is shown if the socket belongs to the kernel (e.g. a kernel service, or the process has exited but the socket hasn’t finished closing yet).
查看进程pid ps -ef | grep 进程名 通过pid查看占用端口 netstat -nap | grep 进程pid
windows:
查端口 netstat -aon|findstr port
查进程 tasklist|findstr pid
查看所有运行中进程的命令行参数: wmic process get caption,commandline /value
根据进程名查询进程信息 wmic process where caption=“notepad.exe” get caption, processid, commandline /value【精确查找】 wmic process where=“caption like ‘notepad%’” get caption,commandline /value【模糊查找】
根据进程id查询进程信息 wmic process where ProcessId=“12696” get processid, commandline netstat -nap | grep
强制杀死进程 taskkill /F /PID 1304
file command
Usage: file [OPTION...] [FILE...]Determine type of FILEs. --help display this help and exit -v, --version output version information and exit -m, --magic-file LIST use LIST as a colon-separated list of magic number files -, --uncompress try to look inside compressed files -Z, --uncompress-noreport only print the contents of compressed files -b, --brief do not prepend filenames to output lines -c, --checking-printout print the parsed form of the magic file, use in conjunction with -m to debug a new magic file before installing it -e, --exclude TEST exclude TEST from the list of test to be performed for file. Valid tests are: apptype, ascii, cdf, compress, csv, elf, encoding, soft, tar, json, text, tokens -f, --files-from FILE read the filenames to be examined from FILE -F, --separator STRING use string as separator instead of `:" -i, --mime output MIME type strings (--mime-type and --mime-encoding) --apple output the Apple CREATOR/TYPE --extension output a slash-separated list of extensions --mime-type output the MIME type --mime-encoding output the MIME encoding -k, --keep-going don"t stop at the first match -l, --list list magic strength -L, --dereference follow symlinks -h, --no-dereference don"t follow symlinks (default) -n, --no-buffer do not buffer output -N, --no-pad do not pad output -0, --print0 terminate filenames with ASCII NUL -p, --preserve-date preserve access times on files -P, --parameter set file engine parameter limits indir 15 recursion limit for indirection name 30 use limit for name/use magic elf_notes 256 max ELF notes processed elf_phnum 128 max ELF prog sections processed elf_shnum 32768 max ELF sections processed -r, --raw don"t translate unprintable chars to \ooo -s, --special-files treat special (block/char devices) files as ordinary ones -S, --no-sandbox disable system call sandboxing -C, --compile compile file specified by -m -d, --debug print debugging messagesReport bugs to https://bugs.astron.com/
查看文件类型 file filename查看文件的mime type file --mime-type filename
ps command
ps: The ps command displays active processes
three style:
unix ps -auxbsdps aux gnu: have two dashses in front of the option instead of just oneps --quick-pid 2925
ps without any options: shows the processes that are running in your current session
[root@kwephisprg01362 ~]# ps PID TTY TIME CMD26748 pts/0 00:00:00 bash28001 pts/0 00:00:00 psThe four columns are labeled PID, TTY, TIME, and CMD.PID - The process ID. Usually, when running the ps command, the most important information the user is looking for is the process PID.Knowing the PID allows you to kill a malfunctioning process .TTY - The name of the controlling terminal for the process.TIME - The cumulative CPU time of the process, shown in minutes and seconds.TIME是CPU真正执行代码的时间,当进程正在等待网络或磁盘或只是休眠时, 此计数器不会增加CMD - The name of the command that was used to start the process.A TTY is a computer terminal. In the context of ps , it is the terminal that executed a particular command.TPGID - refers to the terminal session id with which the process is associatedUID - user id that started that particular process,0 is root
查看进程的关系 ps -axjf
ps命令获取指定进程的执行目录、环境变量、完整的命令行
w Wide output. Use this option twice for unlimited width.e Show the environment after the command.
ps eww -p
查看文件的方式获取信息: 执行目录、环境变量、完整的命令行 ll /proc/cat /proc/1/environ | tr ‘\000’ ‘\n’
cwd 符号链接的是进程运行目录exe 符号连接就是执行程序的绝对路径cmdline 就是程序运行时输入的命令行命令environ 记录了进程运行时的环境变量fd 目录下是进程打开或使用的文件的符号连接cwd 链接的是启动进程的目录(也就是输入命令行所在的目录)environ: 记录该进程当时所有环境变量(常用 tr "\0" "\n" < /proc//environ 命令将环境变量一个属性一行的显示)cmdline: 运行进程当时执行的完整命令
proc command
proc - process information pseudo-filesystem
The proc filesystem is a pseudo-filesystem which provides aninterface to kernel data structures. It is commonly mounted at/proc
/proc/[pid]/environ:
This file contains the initial environment that was setwhen the currently executing program was started viaexecve(2). The entries are separated by null bytes("\0"), and there may be a null byte at the end.cat /proc/1/environ | tr "\000" "\n"
find
find: 在当前目录下查找指定路径的文件, 可以使用正则表达式 find . -ipath */zh_CN/Res.properties 查找目录 find /(查找范围) -name ‘查找关键字’ -type d find / -name DesktopService -type d 若不指定查找类型 find / -name AnmyTest则会将目录和文件一同输出 若指定查找类型 find / -name AnmyTest -type d则只会将目录输出 查看前两行和后两行
ls -al | head -2ls -al | tail -2
scp command
复制目录 从远处复制文件到本地目录 scp root@10.6.159.147:/opt/soft/demo.tar /opt/soft/ 从远处复制到本地 scp -r root@10.6.159.147:/opt/soft/test /opt/soft/ 上传本地文件到远程机器指定目录 scp /opt/soft/demo.tar root@10.6.159.147:/opt/soft/scptest 上传本地目录到远程机器指定目录 scp -r /opt/soft/test root@10.6.159.147:/opt/soft/scptest
grep command(global regular expression print)
$ grep --help Usage: grep [OPTION]… PATTERN [FILE]… Search for PATTERN in each FILE. Example: grep -i ‘hello world’ menu.h main.c
Pattern selection and interpretation: -E, --extended-regexp PATTERN is an extended regular expression -F, --fixed-strings PATTERN is a set of newline-separated strings -G, --basic-regexp PATTERN is a basic regular expression (default) -P, --perl-regexp PATTERN is a Perl regular expression -e, --regexp=PATTERN use PATTERN for matching -f, --file=FILE obtain PATTERN from FILE -i, --ignore-case ignore case distinctions -w, --word-regexp force PATTERN to match only whole words -x, --line-regexp force PATTERN to match only whole lines -z, --null-data a data line ends in 0 byte, not newline
Miscellaneous: -s, --no-messages suppress error messages -v, --invert-match select non-matching lines -V, --version display version information and exit –help display this help text and exit
Output control: -m, --max-count=NUM stop after NUM selected lines -b, --byte-offset print the byte offset with output lines -n, --line-number print line number with output lines –line-buffered flush output on every line -H, --with-filename print file name with output lines -h, --no-filename suppress the file name prefix on output –label=LABEL use LABEL as the standard input file name prefix -o, --only-matching show only the part of a line matching PATTERN -q, --quiet, --silent suppress all normal output –binary-files=TYPE assume that binary files are TYPE; TYPE is ‘binary’, ‘text’, or ‘without-match’ -a, --text equivalent to --binary-files=text -I equivalent to --binary-files=without-match -d, --directories=ACTION how to handle directories; ACTION is ‘read’, ‘recurse’, or ‘skip’ -D, --devices=ACTION how to handle devices, FIFOs and sockets; ACTION is ‘read’ or ‘skip’ -r, --recursive like --directories=recurse -R, --dereference-recursive likewise, but follow all symlinks –include=FILE_PATTERN search only files that match FILE_PATTERN –exclude=FILE_PATTERN skip files and directories matching FILE_PATTERN –exclude-from=FILE skip files matching any file pattern from FILE –exclude-dir=PATTERN directories that match PATTERN will be skipped. -L, --files-without-match print only names of FILEs with no selected lines -l, --files-with-matches print only names of FILEs with selected lines -c, --count print only a count of selected lines per FILE -T, --initial-tab make tabs line up (if needed) -Z, --null print 0 byte after FILE name
Context control: -B, --before-context=NUM print NUM lines of leading context -A, --after-context=NUM print NUM lines of trailing context -C, --context=NUM print NUM lines of output context -NUM same as --context=NUM –color[=WHEN], –colour[=WHEN] use markers to highlight the matching strings; WHEN is ‘always’, ‘never’, or ‘auto’ -U, --binary do not strip CR characters at EOL (MSDOS/Windows)
显示系统上的正则 $ grep -V grep (GNU grep) 3.1 linux是GNU grep/mac是BSD grep
搜索文本在特定的文件中
搜索文件中匹配的文件的行 grep “content” filename
扩展正则表达式 -E, --extended-regexp PATTERN is an extended regular expression 查询一组pid的进程信息 ps -ef | grep -E ‘67227|67413|67415|67416’ 查看testcase.properties文件中有多少个LINUX_SF_AS_CMD grep -o获取到所有匹配的列, wc -l获取有多少行 grep -o ‘LINUX_SF_AS_CMD’ testcase.properties |wc -l
完全匹配单词模式 -w, --word-regexp force PATTERN to match only whole words
忽略大小写区分 默认是case sensitive -i, --ignore-case ignore case distinctions
附加显示匹配的行数 -n, --line-number print line number with output lines eg: $ cat test.txt clarence clarences Clarence
D:\coding\shellpractice $ grep -win “clarence” test.txt 1:clarence 3:Clarence
see the lines behind my match -B, --before-context=NUM print NUM lines of leading context eg: grep -win -B 4 “clarence” test.txt
see the lines after my match -A, --after-context=NUM
查看匹配的上下文(see the context serrounding our match) -C, --context=NUM
show what files contain a match -l, --files-with-matches
显示匹配字符串的文件以及每个文件匹配的个数 -c, --count print only a count of selected lines per FILE
使用正则来匹配 eg: -P 表示使用类似Perl的正则表达式 grep -P “\d{3}-\d{3}-d{4}” names.txt
搜索文本在多个文件中
在当前目录中搜索包含clarence单词的文件 -l只打印匹配的文件 grep -winl "clarence" ./*.txt
递归搜索(recursive search subdirectories) -r, --recursive like --directories=recurse grep -irn "APP_SHARE_DIR"
zgrep command
zgrep [grep options] Expression File name-c: This option is used to display the number of matching lines for each file. 展示每个文件匹配的行的数量zgrep -c "linux" GFG.txt.gz-i: This option is used to ignore case sensitivity.忽略大小写敏感-n: This option is used to display the line number of file if the given expression is present in the line. 展示每个文件匹配的行号-e: This option is used to specify the expression but can be used multiple times. eg: zgrep -e "linux" -e "Linux" GFG.txt.gz-l: This option is used to display the names of the files with the expression present in it. -h: This option is used to display the matched lines but doesn’t display the file names.
sed command
eg: $‘\r‘: command not found的解决方法 出现这样的错误,是因为Shell脚本在Windows系统编写时,每行结尾是\r\n, 而在Linux系统中行每行结尾是\n,所以在Linux系统中运行脚本时, 会认为\r是一个字符,导致运行错误
方法1 去除Shell脚本的\r字符 sed -i ‘s/\r//’ example.sh
方法2 yum install -y dos2unix dos2unix example.sh dos2unix: converting file example.sh to Unix format …
展示进程树display a tree of processe pstree KaTeX parse error: Can"t use function "$" in math mode at position 39: …kwephis37773 ~]$̲ pstree bash───pstree
pstree 用户名(当前用户所有运行的进程) [sopuser@kwephis37773 ~]$ pstree sopuser sshd───bash───pstree
tr command
a command line utility for translating or deleting characters.
多个命令执行
按顺序执行多个命令,无论命令是否执行成功 command1;command2按顺序执行,且如果前一个的命令执行发生错误,后一个命令则不会被执行 command1&&command2按顺序执行,且当前一个命令执行成功时,后一个命令就不会执行 command1||command2
linux source、sh、bash、./区别
source a.sh 当前shell, a.sh不需要有"执行权限" 可简写为: . a.sh
sh/bash 打开一个subshell,a.sh不需要有"执行权限" sh 遵循POSIX规范:“当某行代码出错时,不继续往下解释”bash 就算出错,也会继续向下执行 sh是bash的一种特殊的模式,sh就是开启了POSIX标准的bash, /bin/sh 相当于 /bin/bash --posix
./ 打开一个subshell,a.sh需要有"执行权限",也可以直接运行可执行文件
a.run
#!/usr/bin/pythonprint("This is Python script")
如果我直接运行./a.sh,首先你会查找脚本第一行是否指定了解释器, 如果没指定,那么就用当前系统默认的shell(大多数linux默认是bash),如果指定了解释器,那么就将该脚本交给指定的解释器 那么你如果运行./a.run,结果就是输出一行文字,但是如果你运行sh a.run,会报错 因为这是一个python脚本,sh看不懂(注意,linux下后缀通常不是很严格,.run后缀是我随意命名的,和windows有点区别).
du显示目录或文件的大小, 默认情况下输出结果以KB为单位 du -sh
curl下载文件
使用linux的重定向功能保存
基本用法
curl命令: -o 下载文件并指定文件名保存 -L 跟随重定向请求 -H 设置头信息 -k 允许发起不安全的ssl请求 -b 设置cookie -s 不显示无关信息 -v 显示连接的所有信息
将get请求的内容定向到文件中
saves the downloaded file on the local machine with the name provided in the parameters curl -o output.html www.dataden.techwhich is equivalen to:curl www.dataden.tech > output.html
post请求
passing some json with all the required parameterscurl --data "name=john&username=Doe" http://www.dataden.techor like a regular JSON curl --data ""name":"clarence", "password": "1234"}" https://www.baidu.com--data is equivalent to using -d, -X flag to specify which method we want to involvecurl -X "POST" -d "name=John&surname=Doe" http://www.example.com
获取外网IP
curl -L ip.tool.lu --proxy "http://username:password@proxyhk.huawei.com:8080/" -k
配置代理
username和password需要urlencode编码(如果有特殊字符) curl https://www.python.org/ -v --proxy “http://username:password@host:port/” -k -k表示忽略证书认证, -v表示显示详情
文件校验
windows计算哈希值
certutil -hashfile C:\Windows\SysWOW64\msvcrt.dll sha256
windows environment variables
%USERPROFILE% %HOME% %APPDATA% %SystemRoot%
密码学相关
openssl
openssl genrsa
root@OSSSVR02-1:/tmp/username>openssl genrsa --help Usage: genrsa [options] Valid options are: -help Display this summary -3 Use 3 for the E value -F4 Use F4 (0x10001) for the E value -f4 Use F4 (0x10001) for the E value -out outfile Output the key to specified file -rand val Load the file(s) into the random number generator -writerand outfile Write random data to the specified file -passout val Output file pass phrase source -* Encrypt the output with any supported cipher -engine val Use engine, possibly a hardware device -primes +int Specify number of primes
生成rsa私钥文件 openssl genrsa -out source.pem -f4 2048
查看私钥文件的模数n, -f4表示使用的是65537迭代次数 openssl rsa -text -noout -in source.pem | head -1
pkcs8
root@OSSM-1:/home/sopuser>openssl pkcs8 --help Usage: pkcs8 [options] Valid options are: -help Display this summary -inform PEM|DER Input format (DER or PEM) -outform PEM|DER Output format (DER or PEM) -in infile Input file -out outfile Output file -topk8 Output PKCS8 file -noiter Use 1 as iteration count -nocrypt Use or expect unencrypted private key -rand val Load the file(s) into the random number generator -writerand outfile Write random data to the specified file -v2 val Use PKCS#5 v2.0 and cipher -v1 val Use PKCS#5 v1.5 and cipher -v2prf val Set the PRF algorithm to use with PKCS#5 v2.0 -iter +int Specify the iteration count -passin val Input file pass phrase source -passout val Output file pass phrase source -traditional use traditional format private key -engine val Use engine, possibly a hardware device -scrypt Use scrypt algorithm -scrypt_N val Set scrypt N parameter -scrypt_r val Set scrypt r parameter -scrypt_p val Set scrypt p parameter
使用pcks#8格式来转换私钥 openssl pkcs8 -topk8 -v2 aes-256-cbc -in source.pem -passout pass:%s -out output.pem >/dev/null 2>&1 -topk8读取private key然后生成pkcs#8形式的key -v2设置pkcs#5 v2.0算法(ase128/aes256/des3) 默认aes256 -in 指定要读取key的文件 -passout 输出文件密码源 -out 指定输出文件
标签:
相关推荐:
最新新闻:
- 如何利用大数据实现精准营销?会员管理中用户数据的流转及应用解释 世界速讯
- 全球热门:《口袋妖怪》精灵宝可梦let'sgo皮卡丘伊布存档修改器教程
- 观天下!vim的智能补全方式——CTRL-N和CTRL
- 世界要闻:电脑启动怎么选择启动模式?解决方法在这里
- 鸿蒙os2.0系统支持机型有哪些?适配机型介绍
- 焦点滚动:梦三国服务器每天维护几次?玩家数量逐渐减少的原因是什么?
- 【人脸表情识别】pytorch处理CK+数据集:每日简讯
- 电脑安装xp和windows7双系统有什么区别?Xp和Win7双系统怎么安装?_全球通讯
- 世界简讯:javascript查找并且倒排序的方法 mongodb常用操作命令大全
- 信息:【干货】Python与STAT时间日期转换问题
- 今日热门!如何解决IE主页被劫持的问题?解决方法介绍
- 小米13 Ultra外观曝光:爆料全中!
- 什么是WAP?WML与HTML有什么区别?
- Linux常用命令速查表 清除旧文件/dev/null的方法:天天即时看
- 跨境电商营销推广的方法有哪些?跨境电商8大推广引流方式
- Ajax:异步的JavaScript和XML的同源策略
- 什么是MultiGroups?JGroups详解
- 加油站都需要什么手续?如何办理工商登记?_当前快看
- RTX3060Ti游戏神卡2169元封神!
- IBM发布全新z16和LinuxONE 4的单机柜版本_观察
- 天天速看:iPhone 8以上都能用!中国广电5G已全面支持iPhone
- 森歌集成灶怎么样?三方面出发谈谈它的那些事儿 独家
- 小岛秀夫转发自己的《芭比》海报:谁不喜欢粉粉嫩嫩呢:天天简讯
- 谷歌Stadia服务关闭 项目负责人现已离开公司
- 全球观热点:XGP 5月首发游戏阵容 《红霞岛》领衔
- 【世界播资讯】《刺客信条:幻景》菜单栏截图 有令人兴奋的新功能
- 高华科技上交所公开招股
- 今日热讯:《守望先锋2》第四赛季预告 新英雄新皮肤新活动等
- 3D-Roguelite横版动作游戏《霓虹序列》Steam页面上线 4月21日发售
- 《RE4RE》佣兵模式已上线 未来或加入艾达王\威斯克
- 首届香港高等教育展4月15日举行 今日观点
- 索尼:CMA对微软收购暴雪一案态度转变令人惊讶 太不合理!
- 全球看点:美国男子承认掰断偷走兵马俑手指 检方或只进行轻判
- 天天观焦点:汾河二库开放吗(山西汾河二库是开放的吗)
- 雷蛇推出透明RGB滚轮游戏鼠标:搭载5G光学传感器 售价499元
- 环球观焦点:太极股份:拟提前赎回“太极转债”
- 天天快消息!超大外屏亮眼!摩托罗拉razr 40 Ultra获认证
- 百变星曜由你来定!星曜娘二创活动进入最终投票阶段
- 榨干《甄嬛传》价值?乐视将推85英寸甄嬛传限量电视
- 环球微资讯!首次进军海外!小米13 Ultra将全球上市
- 世界观天下!13888元起!大疆Mavic 3 Pro无人机曝光:升级三摄镜头、增加超广角
- 离谱!《最后生还者》泰丝与感染者之吻被提名:玩家很愤怒
- 《夏洛克·福尔摩斯:觉醒》发售宣传片公开
- 过半玩家从《生化危机123》开玩:你是从哪一代入坑的?
- 继《北欧女神》之后 SE移除《三角战略》D加密 环球微资讯
- 阴线阳线_史蒂夫尼森_阴线阳线
- 清蒸鲑鱼做法视频_清蒸鲑鱼做法|焦点消息
- 世界聚焦:Epic喜加一:《消逝的光芒:增强版》《异形工厂》免费领
- IU新剧片酬超宋慧乔、全智贤 获韩国女演员最高片酬
- 《最后生还者》获MTV电影电视奖5项提名:最佳男主、最佳吻戏等|每日视点
- 《泰坦尼克号》女主参演《阿凡达2》上热搜:她对大海有执念:今日讯
- 《原子之心》更新上线 为PS5和XS加入120Hz模式
- 女子突然呼吸困难地铁工作人员为她戴严口罩:网友竟然齐声叫好!
- 当前视讯!小米发布89元电动牙刷:Type-C充电 续航25天
- 小米正式开启2023米粉节,Redmi K60 Pro闪降300_天天快讯
- 肉夹馍店门口贴“雇托排队可耻”被指讽刺同行,律师:极有可能侵权:焦点快播
- 头条焦点:港任马里奥游戏促销中!《马车8》《马造2》等打折
- 《守望先锋2》新英雄背景介绍:故事很赞、没那么多buff
- 全球今亮点!特斯拉低价小型车曝光 目标销量4200万辆
- AI绘图二次元!iGame RTX 4090竟如此之快-世界即时看
- 展会回顾丨2023CCE亿嘉和智能清洁展位精彩大盘点
- 【世界新视野】腾讯QQ入选首批互联网应用适老化及无障碍改造优秀案例
- 原料价格腰斩,产业大洗牌,为啥锂企纷纷被调高目标价?
- 世界看热讯:增速双第一!中兴通讯交换机、路由器产品Q4国内份额跃升第二
- 艺术电影凭什么这么“硬气”-全球热点评
- 当前观察:坂本龙一女儿发旧照哀悼父亲:我想再回到小时候做他的小女孩
- 《堕落之主》重启将有额外设计 减少玩家的挫败感 世界热闻
- 无事发生!T2与《GTA》逆向工程模组团队和解:焦点速看
- 传《生化危机》新真人电影开发中 讲述生化0故事 天天快播报
- 《熔铁少女》公布全新宣传片 主机版今日发售:当前快报
- 每日热点:小米成立13周年 雷军晒高管合照:齐竖大拇指、清一色牛仔裤
- 天天滚动:类魂单机《深沉之火》正式版4月20日定档发售
- 当前关注:《小美人鱼》真人电影新剧照曝光 黑美人鱼救王子
- 环球微资讯!小米13 Ultra官宣本月发布、号称“移动影像的成人礼”
- 【新视野】元太科技推出取代纸质广告牌的革命性全新色彩电子纸E Ink Spectra (TM) 6