Folder command:
mkdir command:
Create a folder make directories abbreviation
-p This parameter is required to create a parent directory as needed to create a multi-level directory
eg:
mkdir abc means to create the abc folder under the current folder.
mkdir -p ./x/y/z Create a "x/y/z" multilevel directory under the current folder
mkdir ./x/{a,b,c}dir creates three x/adir x/bdir x/cdir directories under the current folder
cd command:
switch path change directory abbreviation
eg:
cd - return to the last working directory
cd back to the user's home directory
cd ~ returns the current user's home directory
cd ~zhangsan returns the directory where "zhangsan" is located
pwd command:
Display the current working directory print working directories abbreviation
rmdir command:
Command to delete a folder remove empity directories abbreviation
rm command:
delete file remove abbreviation
parameter:
-r short for recursive recursive
-f Force delete short for force
rm -rf abc means to delete the abc folder and its subfolders and files under the current folder.
Delete file: rm -rf abc.txt
du instruction:
du -lh --max-depth=1 : View the disk capacity occupied by sub-files and sub-directories under the current directory.
File command:
touch command:
Modify the timestamp of the file, understand it by touching it, and create the file when the file does not exist
eg touch abc.txt 创建abc.txt
vi/vim command:
Edit file
Edit a file: vi filename Enter command mode
vi +n filename will locate the beginning of the nth line after opening the file
vi + filename After opening the file, the cursor is positioned at the beginning of the last line
After entering the edit mode, enter G (shift+g) to locate the last line and gg to locate the first line
vi +/keyword filename After opening the file, it will be located at the beginning of the line including the keyword, and the keyword must exist.
Press n to locate a keyword, then n to locate the next keyword, and capital N to locate the previous keyword.
Mode switch:
Edit Mode --> Input Mode
i Input before the character positioned by the cursor, switch to input mode
a Enter after the character positioned by the cursor, and convert to input mode a is the abbreviation of append.
I locate the input at the beginning of the line and switch to input mode
A locates the input at the end of the line and converts it to input mode
o Under the line where the cursor is, create a new line and switch to input mode.
O On the line where the cursor is located, create a new line and switch to input mode.
Input Mode --> Edit Mode
esc
Edit Mode --> Last Line Mode
shift+:
Last line mode --> Edit mode
esc + esc
input mode --> last line mode
can not go
Brotherhood version
Entering set nu in edit mode will mark out the line number of each line of the file to be opened. set nonu cancels the line number. Nu is the abbreviation of number.
gg locates the first line G locates the last line Enter the line number under the colon and press Enter to jump to the specified line number
$ move to the end of the line 0 move to the beginning of the line
b, delete (the following delete commands are executed in command mode)
x deletes the character where the cursor is located
nx deletes the n characters after the
cursor location dd deletes the line where the cursor is located
dw Delete a word
ndd Delete n
lines
3. Copy and cut
yy Copy the current line
nyy Copy the current line following n lines
dd Cut the current line
ndd Cut the current line following n lines
p,P Paste under or on the line where the current cursor is located
4. Replace or cancel
r Replace the character at the cursor position
R Replace the character from the cursor position Press the Esc key to end
u Cancel the previous operation undo abbreviation
5. Find and replace
/sring Search the string string on the currently opened page and press n to find the next one.
If you want to search, it is case-insensitive: set ic is changed to case-sensitive when searching: set noic
:%s/old/new /g Replace %s Indicates that the full text replaces the starting line, and the ending line specifies the range to replace/string to replace/new string to replace g Do not ask c to ask
eg: %s/ftp/FTP/g will all the current file Replace ftp with FTP
6. Save and exit
: w Save changes
: w new_file Save as specified file
ZZ Save changes and exit (equivalent to shift + zz)
:q! Do not save changes and exit
: wq or x Save and exit w means save to disk
: wq! Save Modify and exit (files without permission to modify) Only the file owner or root user can use this command
:q Quits on unmodified files. Note: When you exit the editing state, you need to be in English when you enter ":".
Esc key Exit edit mode and enter command mode
:wq or x to save and exit. w means save to disk
q! Force quit without saving.
sxt version
vi commands in each mode
编辑模式
光标移动
字符:h 左 j 下 k 上 l 右
单词:w 下一个单词的词首, e 当前或下一个单词的词尾, b当前或下一个单词的词首
行内:0 数字0跳到当前行的绝对行首,^行首的第一个非空白字符,$绝对行尾
行间:G 文章末尾,gg文章开头 nG 跳到第n行的行首
翻屏:ctrl+f 向下翻屏,ctrl+b 向上翻屏
删除
单字符删除:x 删除光标位置的单字符 ,nx 删除光标开始的n个字符,r替换光标位置的字符
dw 删单词,dd删除行, ndw 从光标开始处删除n个单词, D 删除光标所在处到行尾内容, ndd 从光标所在行开始删除n行
dG 删除光标所在行到文件末尾的内容
剪切粘贴 拆分成2步
行:
step1:删除 dd
step2:粘贴 p 向下粘贴 P 向上粘贴
单词:
step1:删除 dw
step2:粘贴 p 向下粘贴 P 向上粘贴
复制粘贴 拆分成2步
行:
step1:复制 yy
step2:粘贴 p 向下粘贴 P 向上粘贴
撤销
u 撤销 undo缩写
ctrl+r重做撤销的操作
重做
.重复上一步操作
:r 命令
命令模式下的导入命令
eg: :r /tmp/abc.txt 将文件名导入到当前文件光标的位置。
定义快捷键::map 快捷键 触发命令
连续注释::n1,n2s/^/#/g 从第n1行到n2行之间所有行首字母加上#
替换::ab aaa fff 然后在输入状态的时候输入aaa 放上bbb
cat 命令 :
浏览文件的命令,一次将文件所有内容全部显示,所以当太长的文件不不适合用这个命令
选项:
-n 显示文件的时候显示行号
tac命令:
逆序显示自定文件的内容(cat 倒着写)
more 命令:
分页浏览文件 空格翻页(只能往下一页一页向下浏览,不能往上浏览)
当显示完毕后会退出,按空格会一页翻屏,按回车会往下一行显示。
less命令:
分页浏览命令 可以往上浏览,显示完毕文件内容后不会退出终端,需要按q键退出。太大的文件也不适合用该命令查看,比more 更耗费内存。
pageUp 一页一页往上翻页 上箭头往上一行一样翻
空格键,往下翻一页。
回车键,往下翻一行。
b键往上翻一页
上下箭头往上下翻一行。
head 命令:
从0行开始查看指定文件的命令 (默认显示文件最前10行) 不阻塞显示
eg:head vi.txt 查看vi.txt的内容
eg:head -n 3 vi.txt 查看vi.txt文件的前3行内容。
tail 命令:
从指定行开始查看指定文件到最后一行的命令(默认显示文件最后10行) 默认不阻塞显示
语法:tail [选项] 文件
选项
-n
-f 阻塞显示文件内容,当文件内容有增加显示时,能增加显示新的内容,如日志文件
eg:tail -n 3 vi.txt 查看vi.txt文件最后3行的内容。
eg:tail -f vi.txt 阻塞显示 vi.txt中的内容,当vi.txt中的内容有人在通过流增加内容的时候,退出阻塞是ctrl+c
stat 命令
显示文件或文件系统的状态(元数据信息)
eg:
stat /etc/profile 显示文件元数据信息的命令
ls 命令
参数:
-a 以.开头的文件或者文件夹也显示出来 all的缩写
-l 长列表格式显示文件 long的缩写
-i 显示节点号 inode的缩写。
eg:
ls -lia 以长列表格式显示当前文件夹下的所有文件以及子文件,且显示出对应的节点号(节点号相同表示的是相同的物理位置)
ln命令:
链接命令 link缩写 -s表示是软链接(不加该参数表示是硬链接的意思)
软链接和硬链接的区别:硬链接相当于复制,会同步更新。硬链接用的文件的-i文件号是一样的。
eg:ln abc.txt l1 创建一个硬链接l1,l1和abc.txt文件同步。
eg:ln -s abc.txt l2 创建一个软链l2,l2指向abc.txt文件,像windows里面的快捷方式。
eg:ln -s /home/local /usr 意思是将 /home/local 在/usr下创建一个快捷方式(在/usr下面也能看到local文件夹)。
硬链接和软链接的区别:
硬链接中的两个文件是完全平等的,删除其中任意个之后另外一个还可以正常访问,是相同的inode号。
软连接是不相同的两个inode号,链接文件实际存储的是,原始文件的路径。软连接的原始文件被删除后,链接文件将不能访问。像windows里面的快捷方式。
不允许对目录创建硬链接,而可以对目录创建软连接。
http://www.cnblogs.com/ylan2009/p/4287929.html
cp命令:
文件复制 copy缩写
参数:
-r 递归 recursive的缩写
eg:
cp aaa.txt bbb.txt 将 aaa.txt文件复制(已存在),并命名为 bbb.txt文件
cp -r aaa bbb 将文件夹aaa复制(已存在),并命名为 bbb文件夹 解释:-r 这个参数是递归的意思
cp -r ./d1 ./d2 将当前文件夹下的d1文件夹拷贝到d2中去,如果d1不是文件夹则不需要-r参数
scp命令:
不同电脑之间的文件复制命令
scp mongodb-linux-x86_64-2.6.4.tgz [email protected]:/home/software/
将当前系统下的 scp mongodb-linux-x86_64-2.6.4.tgz 复制到119.255.27.38的/home/software/路径下面
拷贝一个文件
scp [email protected]:/home/software/jdk-7u60-linux-x64.rpm /home/software
将19.255.27.38系统上的/home/software/jdk-7u60-linux-x64.rpm 文件复制到本地的/home/software路径下
scp 断点续传怎么实现?20160310
mv命令:
移动文件/文件夹 move缩写
mv /usr/local/apache-tomcat /usr/tomcat 将 /usr/local/apache-tomcat 移动到 /usr/ 下 且重命名为apache-tomcat
linux下面各色文件文件夹的意思:
linux上红色背景 白色字的 还一闪一闪是什么意思啊? 软链接对应的原始文件已经被删除,类似windows中的原文件已经被删除了,链接文件已经不能被正常访问了。
linux上红色背景 白色字 表示是错误文件或权限过高的文件或者危险文件
eg:/usr/bin/passwd 表示权限过高的文件或者危险文件。
linux下面红色文件的意思是表示已经断开的链接。
文件 白色 没有执行权限
文件 绿色 有执行权限
文件夹 蓝色