Linux常用命令总结——文件管理
Linux中的目录
路径:也就是linux中的目录(文件夹)有绝对路径和相对路径
根目录:/
用户主目录(home directory):位于/home目录下,用户登录时
工作目录(working directory):当前目录
当前目录查看命令:pwd (print working directory)
当前目录:./
当前目录的上一级目录:../或..
返回到上一级目录:cd ..
进入当前目录下的dirfile目录:cd dirfile
cd ~ :进入用户主目录(账号所在目录) 或者直接cd回车
cd - :(回到先前的目录)
创建、删除查看和显示目录
1.创建目录
格式:mkdir [选项] 目录
功能:创建目录
常用选项说明:
-m 创建目录的同时设置访问权限
-p 一次性创建多级目录
【例】:在rootfile文件夹下创建test文件夹,并在test文件夹下创建file文件夹。
[root@localhost rootfile]# mkdir -p test/file
[root@localhost rootfile]# ls
test
[root@localhost rootfile]# cd test
[root@localhost test]# ls
file
[root@localhost test]#
【例】:在rootfile文件夹下创建test2文件夹,并设置test2的权限为766
[root@localhost rootfile]# mkdir -m 766 test2
[root@localhost rootfile]# ls
test test2
[root@localhost rootfile]# ls -l
total 16
drwxr-xr-x 3 root root 4096 Jul 21 21:27 test
drwxrw-rw- 2 root root 4096 Jul 21 21:30 test2
注释:rwxrw-rw-分别对应三种不同用户的权限,分别有三们二进制表示,766对应111 110 110
2.删除目录
格式:rmdir [选项] 目录
功能:删除目录
常用选项说明:
-p 递归删除目录,当子目录删除后其父目录为空时,也一同删除
【例】:删除test下的file目录(文件夹),同时test也一并删除
[root@localhost rootfile]# ls
test test2
[root@localhost rootfile]# rmdir -p test/file
[root@localhost rootfile]# ls
test2
3.查看当前目录
格式:pwd
功能:pwd (print working directory),查看当前目录.
常用选项说明:
【例】:查看当前目录
[root@localhost rootfile]# pwd
/home/rootfile
5.显示目录内容
格式:ls [选项] [文件目录]
功能:显示指定目录中的文件和了目录信息,当不指定目录时,显示当前目录下的文件和子目录信息
常用选项说明:
-a 显示所有文件和子目录,包括隐藏文件和主目录
-l 显示文件和子目录的详细信息,包括文件类型、权限、所有者和所属群组、文件大小、最后修改时间、文件名
-d 如果参数是目录,则只显示目录信息,而不显示其中所包含的文件信息
-t 按时间顺序显示
-R 不仅显示指定目录下的文件和子目录信息,而且还递归地显示子目录下的文件和子目录信息
创建和查看文件
创建文件
格式:touch filename
功能:创建文件
常用选项说明:
【例】:在rootfile下创建文件file.txt和test2/file2.txt
[root@localhost rootfile]# touch file.txt
[root@localhost rootfile]# touch test2/file2.txt
[root@localhost rootfile]# ls
file.txt test2
[root@localhost rootfile]# cd tes*
[root@localhost test2]# ls
file2.txt
cat命令
格式:cat [选项] filename
功能:依次读取filename中的内容
常用选项说明:
【例】:读取rootfile下Test.java和file中的文件内容
[root@localhost rootfile]# ls
file.txt test2 Test.class Test.java
[root@localhost rootfile]# vi test2
[root@localhost rootfile]# vi file*
[root@localhost rootfile]# cat Test.java
public class Test {
public static void main(String args[]) {
System.out.println("Hello Linux!");
}
}
[root@localhost rootfile]# cat Test.java file.txt
public class Test {
public static void main(String args[]) {
System.out.println("Hello Linux!");
}
}
this is a file test.
【例】:把Test.java和file.txt文件合并到combine.txt文件中
[root@localhost rootfile]# cat Test.java file.txt > combine.txt
[root@localhost rootfile]# cat comb*
public class Test {
public static void main(String args[]) {
System.out.println("Hello Linux!");
}
}
this is a file test.
more命令
格式:more [选项] filename
功能:依次读取filename中的内容,该命令与cat的不同是可以逐屏往下翻页显示,按q退出。
常用选项说明:
-p 显示下一屏之前先清屏
-s 文件中连续的空白行压缩成一个空白行显示
【例】:显示file.txt的内容
[root@localhost rootfile]# more file.txt
this is a file test.
【例】:显示Test.java和file.txt的内容
[root@localhost rootfile]# more Test.java file.txt
::::::::::::::
Test.java
::::::::::::::
public class Test {
public static void main(String args[]) {
System.out.println("Hello Linux!");
}
}
::::::::::::::
file.txt
::::::::::::::
this is a file test.
less命令
格式:less [选项] filename
功能:依次读取filename中的内容,该命令与more的不同是不仅可以向下翻页,还可以向上翻页,使用上下键、Enter、空格、pageDown、pageUp可以实现前后翻页,按q退出。
常用选项说明:
【例】:显示Test.java的内容
[root@localhost rootfile]# less Test.java
public class Test {
public static void main(String args[]) {
System.out.println("Hello Linux!");
}
}
head命令
格式:head [选项] filename
功能:显示文件的头几行
常用选项说明:
-n 显示文件的前n行,如果没有n值,默认为10行
【例】:显示Test.java的前3行
[root@localhost rootfile]# head -3 Test.java
public class Test {
public static void main(String args[]) {
System.out.println("Hello Linux!");
tail命令
格式:tail [选项] filename
功能:显示文件的末尾几行
常用选项说明:
+n 从第n行开始显示
-n 显示文件的最后n行,如果没有n值,默认为最后10行
【例】:显示Test.java的最后3行
[root@localhost rootfile]# tail -3 Test.java
System.out.println("Hello Linux!");
}
}
文件查找
格式:find [选项] filename
功能:从指定的目录开始,递归地搜索其子目录,查找满足条件的文件并对之采取相关的操作
常用选项说明:
-name ‘字串’ 要查找的文件名,可以用通配符*、?、[]
-group ‘字串’ 文件所属的用户组名
-user 文件所属的用户名
find命令提供的查询条件可以是一个用逻辑符and、or、not组成的复合条件
-a 逻辑与
-o 逻辑或
-! 逻辑非
【例】:查找当前目录下文件名含有Test的文件
[root@localhost rootfile]# find -name 'Test*'
./Test.class
./Test.java
【例】:在根目录下查找文件名为’temp’或是匹配’install*’的所有文件
[root@localhost rootfile]# find / -name 'temp' -o -name 'instal*'
/etc/rhgb/temp
/etc/yum/pluginconf.d/installonlyn.conf
/etc/vmware-tools/installer.sh
/software/tomcat5/webapps/docs/appdev/installation.html
/software/tomcat5/temp
/sbin/install-info
/sbin/installkernel
/usr/share/aclocal-1.9/install-sh.m4
/usr/share/icons/Bluecurve/96x96/mimetypes/install.png
/usr/share/icons/Bluecurve/24x24/mimetypes/install.png
/usr/share/icons/Bluecurve/16x16/mimetypes/install.png
/usr/share/icons/Bluecurve/48x48/mimetypes/install.png
/usr/share/aclocal-1.7/install-sh.m4
/usr/share/doc/cyrus-sasl-lib-2.1.22/install.html
/usr/share/doc/sgml-common-0.6.3/html/install-catalog.html
/usr/share/doc/m2crypto-0.16/demo/Zope27/install_dir
/usr/share/doc/m2crypto-0.16/demo/ZopeX3/install_dir
/usr/share/doc/libstdc++-devel-4.1.1/html/install.html
……
【例】:在rootfile下查找不含Test*的文件
[root@localhost rootfile]# find ! -name 'Test*'
.
./.Test2.swp
./1q
./.Test.java.swp
./test2
./test2/file2.txt
./combine.txt
./file.txt
文字统计命令
格式:wc [选项] filename
功能:统计文件的字节数、字数、行数
常用选项说明:
-c 统计字节数
-l 统计行数
-w 统计字数
【例】:统计Test.java的字节数、行数、字数
[root@localhost rootfile]# wc Test.java
5 14 105 Test.java
[root@localhost rootfile]# wc -wcl Test.java
5 14 105 Test.java
复制、移动和删除文件或文件夹
cp 命令
格式:cp [选项] 源目录或文件 目标目录或文件
功能:将给出的文件或目录复制到另一个文件或目录中
常用选项说明:
-b 若存在同名文件,则覆盖前备份原来的文件
-f 强制覆盖同名文件
-r或R 按递归方式,保留原目录结构复制文件
【例】:复制file.txt文件到file2,若file2已经存在,则备份file2.
[root@localhost rootfile]# ls
1q combine.txt file.txt test2 Test.class Test.java
[root@localhost rootfile]# cp -b file.txt file2
[root@localhost rootfile]# ls
1q combine.txt file2 file.txt test2 Test.class Test.java
[root@localhost rootfile]# cp -b file.txt file2
cp: overwrite `file2'? n
[root@localhost rootfile]# ls
1q combine.txt file2 file.txt test2 Test.class Test.java
[root@localhost rootfile]# cp -b file.txt file2
cp: overwrite `file2'? y
[root@localhost rootfile]# ls
1q combine.txt file2 file2~ file.txt test2 Test.class Test.java
【例】:把test2文件复制到test3文件夹
[root@localhost rootfile]# ls
1q combine.txt file2 file2~ file.txt test2 Test.class Test.java
[root@localhost rootfile]#
[root@localhost rootfile]# cp -r test2 test3
[root@localhost rootfile]# ls
1q combine.txt file2 file2~ file.txt test2 test3 Test.class Test.java
mv命令
格式:mv [选项] 源目录或文件 目标目录或文件
功能:移动或重命名文件或目录
常用选项说明:
-b 若存在同名文件,则覆盖前备份原来的文件
-f 强制覆盖同名文件
【例】:将/home/rootfile下的Test.java移动到/home/rootfile /test2下
[root@localhost rootfile]# mv Test.java test2/Test
[root@localhost rootfile]# ls -R
.:
1q combine.txt file2 file2~ file.txt test2 test3 Test.class
./test2:
file2.txt Test
./test3:
file2.txt
rm 命令
格式:rm [选项] 文件夹或目录
功能:删除文件夹或目录
常用选项说明:
-f 强制删除文件,不出现确认提示
-r或R 按递归方式删除目录,默认只删除文件
【例】:删除当前目录下的test3文件夹
[root@localhost rootfile]# ls
1q combine.txt file2 file2~ file.txt test2 test3 Test.class
[root@localhost rootfile]# ls test3
file2.txt
[root@localhost rootfile]# rm -r test3
rm: descend into directory `test3'? y
rm: remove regular empty file `test3/file2.txt'? y
rm: remove directory `test3'? y
[root@localhost rootfile]# ls
1q combine.txt file2 file2~ file.txt test2 Test.class
【例】: 强制删除当前目录下的test2文件夹
[root@localhost rootfile]# ls
1q combine.txt file2 file2~ file.txt test2 Test.class
[root@localhost rootfile]# rm -rf test2
[root@localhost rootfile]# ls
1q combine.txt file2 file2~ file.txt Test.class
Linux常用命令总结——文件管理的更多相关文章
- Linux常用命令梳理——文件管理(一)
由于本人目前仍是萌新一枚,所以<Linux常用命令梳理>系列仅依照个人目前掌握的知识,对一部分命令进行梳理,目的是为了对之前学到的知识进行巩固.当然了,如果机缘巧合被大家看到了,也欢迎各位 ...
- Linux学习笔记之四————Linux常用命令之文件管理
Linux命令——文件管理相关命令 <1>查看文件信息:ls ls是英文单词list的简写,其功能为列出目录的内容,是用户最常用的命令之一,它类似于DOS下的dir命令. Linux文件或 ...
- Linux常用命令及文件管理
Linux上的文件管理类命令都有哪些,其常用的使用方法及其相关示例演示. 目录解释: .代表此层目录: .. 代表父目录:-代表前一个目录:~代表是家目录. (1)ls命令(显示) -a:列出所有文 ...
- linux常用命令之文件管理
LS ls:list directory contents 默认情况 默认情况下显示的是mtime 选项 -a 列出全部文件及目录包括隐藏的 -l 列出详细信息,包括文件类型.权限.节点.owner. ...
- Linux 常用命令 , 其他名 , 文件管理
Linux 常用命令 , 其他名 , 文件管理 一丶Linux常用的指令 1. bsystemctl stop firewalld #关闭防火墙 2. iptables -F #清空防火墙规则 3. ...
- linux常用命令的介绍
本文主要介绍Linux常用命令工具,比如用户创建,删除,文件管理,常见的网络命令等 如何创建账号: 1. 创建用户 useradd -m username -m 表示会在/home 路径下添加创建用户 ...
- linux——常用命令与脚本
linux常用命令 --文件管理pwd --查看当前目录cd --切换当前目录ls --列出当前目录下的所有文件touch --创建文件mkdir --建立目录rmdir --删除空目录rm --删除 ...
- linux 常用命令及技巧
linux 常用命令及技巧 linux 常用命令及技巧:linux 常用命令总结: 一. 通用命令: 1. date :print or set the system date and time 2. ...
- Linux常用命令手册
Linux常用命令手册 NO 分类 PS1 命令名 用法及参数 功能注解 对应章节 1 文件管理 # ls ls -a 列出当前目录下的所有文件,包括以.头的隐含文件 文件管理 # ls ls ...
随机推荐
- gulp+browserfy模块化工具环境搭建
1.下载ruby,在ruby环境下安装sass; 2.安装nodejs; 3.进入当前项目所在目录,在cmd命令行中输入npm install; 4.安装browserify和gulp 安装brows ...
- 常用Json
一般Json是页面与页面之间传递使用. Json用途 1 后台与前台数据交互,并且数据较复杂,如果数据单一,直接传递字符串,然后在前台用js分割就行. 2 webservice和html ...
- [LeetCode]题解(python):136-Single Number
题目来源: https://leetcode.com/problems/single-number/ 题意分析: 给定一个数组,每个数都出现了2次,只有一个出现了一次,找出这个数.要求时间复杂度O(n ...
- while 、do...while 、for
1.while 特点:只有条件成立才会执行循环体. while陷阱: while(条件);即直接加分号 2.do while 特点:一定会执行一次循环体 3.for语句 l 初始化等可以是多句(把 ...
- 在PADS LAYOUT中如何隐藏不需要的鼠线?
如下图示,将net GPR_0的鼠线隐藏. 鼠标右键,选择网络----选择你要隐藏的网络------右键选择view nets----点击对话框右边View List里你所选的网络-----在右下角t ...
- 成为 Linux 内核高手的四个方法
(之前我在 CUSEC 网站发表了关于内核并不可怕的一篇文章,本文是后续.) 我曾经问别人如何开始内核编程的学习,他们基本上都说:1. 如果你不需要了解内核是如何为你工作的,你为何要尝试呢?2. 你应 ...
- CCNP路由实验(2) -- OSPF
OSPF作为一种内部网关协议(IGP),用于在同一个AS中的路由器之间交换路由信息.OSPF的特性如下:1.可适应大规模网络2.收敛速度快3.无路由环路4.支持VLSM和CIDR5.支持等价路由6.支 ...
- POJ 2823 Sliding Window 【单调队列】
题目链接:http://poj.org/problem?id=2823 题目大意:给出一组数,一个固定大小的窗体在这个数组上滑动,要求出每次滑动该窗体内的最大值和最小值. 这就是典型的单调队列,单调队 ...
- sql的强大功能(看一条sql解决的复杂业务)
一条sql语句解决的复杂业务,请往下看: 业务介绍:一个单位有多个立项(立项信息表里有单位id),每个立项可能被预警多次(预警信息表里的uuid字段的值里包含有立项id或单位id),每 ...
- bootstrap 智能表单 demo示例
1.基本配置,支持的元素类型 2.自动布局 3.自定义布局 4.自定义表单 5.数据绑定 6.带验证的表单 7.智能搜索 8.级联下拉 9.图片上传 图片有点大了,屏幕不够大的话可能看的不习惯,没事 ...