Directory
1. Historical development
2.Linux Getting Started
3. Use Help
4. File Management
5. Redirection and piping
I. Historical development 1. Development history Process 2. Getting Started Basics ii. Linux introduction 1. User Login
root用户 超级用户,接近完整的系统控制 除非必要不要登录 # 普通用户 权限有限 $
2. Terminal Terminal
tty 显示当前终端
3.shell Introduction
接收用户输入的命令送去内核执行,人机交互的语言 echo $SHELL 显示当前的shell的类型 cat /etc/shells 显示当前系统所使用的所有shell
4. Execution of commands
命令提示符prompt [[email protected]~]# echo $PS1 显示当前的提示符格式
Ps1= ' \[\e[31m\][\[email protected]\h\w]\\$\[\e[0m\] ' change prompt {color 3 1m-38m} Enter command to execute Command shell command internal command enable show all activated internal commands enable command activates the disabled internal command enable |WC-L displays the number of internal commands in the activation enable-a displays all internal commands Enab Le-a |wc-l Show the number of all internal commands enable-n show all the internal commands that are disabled enable-n command disable an internal command external command Whereis; which-a | --Skip-alias Hash cache (execute external command) hash shows all hashed command path-l shows all ha SH command path, which contains the alias-D alias to delete the hash path of the specified alias-R clears all HASH-T Alias displays the hash path for the specified alias-p path alias manually add a hash to execute a command when the find order alias → internal command → external command →hash→path Type difference command type the command type alias alias aliases display all alias information Unalias-a aliases Suppress all aliases NANO/ETC/BASHRC save aliases to all users nano ~/.BASHRC save aliases for the current user ' Command '; "\command" The original command, like an alias, executes the original command/path/command ( external command) command execution syntax-short options such as-p-long options such as--HELP; connector previous command execution ends before execution One command \ command line break multiple options and multiple arguments and commands are separated by whitespace characters directly
5. Simple commands
date时间 date +%Y 年 +%m 月 +%d 日 +%H 小时 +%M 分 +%S 秒 +%w 星期 +%F 年-月-日 +%T 时:分:秒 date 月日时分年[.秒] date -s ‘年-月-日 时:分:秒’ hwclock 硬时间 clock 软时间 clock -s 将软时间写入硬时间 关机是自动进行 -w 将硬时间写入软时间 开机时自动进行 cal -y 日历 nano 编辑内容 poweoff/init0 关机 reboot/init 6 重启 shutdown -r 重启 -h 关机 time 指定时间关机 -c 取消关机计划 whoami 显示当前用户名 who an /are/is 任意字符 显示当前的终端信息 who 显示所有终端信息 w 显示所有终端的详细信息及所做的操作 screen 下载
screen -s 会话名 创建指定名的screen会话 -x 会话名 加入已创建的screen会话 -ls 查看所有已打开的screen会话 echo echo $() 或 `` 引用命令执行的结果
echo {} 重复字符的简化形式
echo $(()) 或 $[] 进行运算
echo ${} 或 "$变量名" 划定变量名的起止范围
6.tab Key completion 7. Command line History
!n 重复某条历史(此处n为数字)
↑ 重复上一条命令 !string 重复前一个以“string”开头的命令 !?string 重复前一个包含“string”的命令 string 字符串
history的命令 history 查询历史记录 history -c 清空当前的所有历史记录 history -dn 删除某条历史(此处n为数字) history -a 将当前终端新执行的命令写入历史记录文件 (默认为~/.bash_history) history -w /path/filename.txt 将历史记录写入指定文件
调用历史参数 要重新调用前一个命令中最后一个参数: !$ Esc, .(点击Esc键后松开,然后点击 . 键)
8.bash shortcut keys
ctrl + l 清屏 + o 执行当前命令 并重新显示本命令 + s 锁定屏幕 仍可以运行 + q 解锁 + c 强制结束 + z 暂停命令(fg可以再切换回来,bg可以查看当前终端后台有多少暂停的程序) + a 光标起到命令行首 + e 光标移到命令行尾 + u 删除光标之前的内容 + k 删除光标之后的内容 ctrl+shift+c 复制选中的文本 ctrl+shift+v 把文本粘帖到当前光标处 Alt +f 向右移动一个单词 +b 向左移动一个单词 +r 删除全部内容 +N 提示输入指定字符[后输入]后,重复显示该字符N次(N表示具体的数字)
Iii. use of help (ability to get help feel the ability to technology) 1.whatis
仅能提供命令基本的介绍。不提具体用法。 whatis command 基于数据库的查找 man -f comman 优点:检索速度快 缺点:缺乏实时性 makewhatis 在CentOS6 mandb 在CentOS7
2.--help3.man Info
man 统称为Linux手册,常用于命令参考 man cmd 查看此cmd的帮助 q 退出man info 适合通用文档参考 info cmd 查看此cmd的帮助
4. Use local Help documentation
/user/sharel/doc
5. Online 6. Other website search Iv. file management 1. File system structure elements
Linux系统文件区分大小写 元数据 metadata
2. Create a View file
pwd 当前目录路径 pwd -P 当前目录为软链接时,显示其源目录 oldpwd 上一次目录路径 cd 改变目录 cd .. 切换到父目录 cd 切换到当前目录
LS View directory ls-a show All files ls-l long list ls-r recursion LS-LD displays details of the specified directory ls-1 vertical display ls-s by file size descending ls-t By modified time from new to old ls-u by access time Ls-u by file order ls-x sorted by file suffix Ls-i Display inode number stat atime read file content access time Three timestamp mtime change the file content modification time CTime meta-data sent Change time Touch Create a file touch filename creates a filen when the file does not exist AME updates the full timestamp when the file already exists touch-t [YY]MMDDHHMM[.SS] filename Touch-a Change atime ctime touch-m change mtime ctim touch-c file exists update all Does not exist, do not create filesFile wildcard * Matches 0 or more characters? Match any single character * [0-9] [A-z] [a-z] ^ hypanthium characters except [: Upper:] Uppercase Female [: Lower:] lowercase letters [: Alpha:] uppercase letters [: Alnum:] Letters and numbers [: space:] Horizontal or vertical white space character [: blank:] Space
3. Copy transfer Delete file
cp复制 cp A B
cp -i 覆盖前提示 cp -n 不覆盖 注意顺 cp -r -R 递归 cp -a 归档 cp -d 不复制原文件只复制链 cp -p 复制所有的 cp -v 显示复制的过程 cp -f 有权限 覆盖在创建 mv -i 覆盖前提示 -f 强制覆盖 rm -i 删除前提示 -f 强制删除 -r 删除目录 rename .txt .doc* .txt
4. Directory Operations
tree 显示目录树 -d 只显示目录 -L n 只列出指定层级的目录(此处n为数字) -P通配符 只列出匹配到的文件和所有的目录 mkdir 创建目录 -p 一次性创建多级目录 -v 创建时显示详细信息 -m 创建时直接设置权限 rmdir 删除空目录 -p 一次性删除多级空目录 -v 显示删除的详细信息
5.inode
128字节 64(类型,权限,链接数,大小,UID,GID,时间,其他信息) 索引节点 cp rm mv
6. Soft Link Hard link
ln filename linkname 不能跨分区 ln -s filename linkname 可以跨分区 源被删除 链接也不可用 file 确定文件内容 -b 查看时不显示文件名 -f 列出文件中文件的文件类型 -f /path/filename 文件中每个文件路径一行。从而可批量查看多个文件的类型 -F 符号 按指定符号做为分隔符输出 默认是 : -L 当查询的对象为软链接时,显示源文件的类型 --help
V. Redirects and Pipelines 1. Three I/O devices
指令+数据 Input 读入数据 Output 输出数据 stdin 标准输入 stdout 标准输出 stderr
2. Redirect I/O to the file
> 正确输出 文件不存在时直接创建新文件 存在时 > 直接覆盖 >> 追加 2>错误输出 &>全部输出 2>&1错误结果转化正确 1>&2 正确的转化错误 ()合并多个程序
3.tr Conversion and deletion
tr -c 选取字符集的补集 -d 删除 -s 连续重复的字符以一个字符表示 << EOF >EOF 终止符
4. Use the Pipe link command
| 管道符 使用前加空格 连接命令 cmd1 | cmd2 | cmd3 将正确的结果传递给管道 错误的结果通过 2>&1 ; |& 传递结果 组合多种工具
less 一页一页查看 ls -l /etc | less mail 通过mail发送输出 echo “test mail” | mail -s “test user”
5.tee Redirect to multiple targets
tee -a 追加 command1 |tee [-a] file |command2
Linux Learning (i)