Linux命令——文件管理命令(部分常用的)

来源:互联网 发布:澳门网络真人博客官网 编辑:程序博客网 时间:2024/06/02 02:27

ls

列出当前位置的所有文件

[xzd@localhost ~]$ lsDesktop      hello.java                Music                                   PublicDocuments    Hello.java                MySQL-client-5.1.73-1.glibc23.i386.rpm  TemplatesDownloads    jdk-8u111-linux-i586.rpm  MySQL-server-5.1.73-1.glibc23.i386.rpm  VideosHello.class  linux                     Pictures                                workspace

常用的参数是-l,列出文件详细信息。也可以简写成ll

[xzd@localhost ~]$ lltotal 186952drwxr-xr-x. 2 xzd xzd      4096 Jan 15 03:14 Desktopdrwxr-xr-x. 2 xzd xzd      4096 Jan 15 03:14 Documentsdrwxr-xr-x. 2 xzd xzd      4096 Jan 15 03:14 Downloads-rw-rw-r--. 1 xzd xzd       549 Jan 16 03:16 Hello.class-rw-rw-r--. 1 xzd xzd       102 Jan 16 02:43 hello.java-rw-rw-r--. 1 xzd xzd       159 Jan 16 03:16 Hello.java

cd

切换目录(change directory)用法:cd + 目录名

[xzd@localhost ~]$ cd Desktop

pwd

查看当前终端所在的目录

[xzd@localhost Desktop]$ pwd/home/xzd/Desktop

mkdir

在当前目录下创建一个文件夹,用法 mkdir + 文件夹名字

[xzd@localhost Desktop]$ mkdir mydir

echo

在控制台输出内容

[xzd@localhost Desktop]$ echo "hello linux"hello linux

也可以将输出的内容写入到某个文件中

[xzd@localhost Desktop]$ echo "hello linux" > 1.txt

cat

查看某个文档的内容,用法:cat + 文件名

[xzd@localhost ~]$ cat Hello.java public class Hello{        public static void main(String[] args)throws Exception{                while(true){                        System.out.println("hello!!!");                        Thread.sleep(1000);                }        }}

touch

创建一个空的文件

[xzd@localhost ~]$ touch info.log

cp

复制文件,用法:cp + 文件名 + 复制到的目录

[xzd@localhost ~]$ cp info.log Documents/

rm

删除文件

[xzd@localhost Documents]$ rm info.log

删除文件夹以及文件夹中的内容 rm -r

[xzd@localhost ~]$ rm -r Documents/

mv

移动文件

[xzd@localhost ~]$ mv info.log Documents/

rmdir

删除文件夹

[xzd@localhost ~]$ rmdir mydir/

查看内容较多的文件

more

跟cat差不多,不过使用more会让文件内容一页一页地显示在终端

[xzd@localhost ~]$ more MySQL-client-5.1.73-1.glibc23.i386.rpm 

less

让文件内容分页显示在终端,并且我们可以通过上下键进行回滚

[xzd@localhost ~]$ less MySQL-client-5.1.73-1.glibc23.i386.rpm 

tail

显示尾部的若干行,使用方法:tail -数字 + 文件名

[xzd@localhost ~]$ tail -5 Hello.java                         System.out.println("hello!!!");                        Thread.sleep(1000);                }        }}

ln

创建链接,就是创建一个快捷方式,指向某一个真实的文件
用法:ln + 文件名 +快捷方式名

[xzd@localhost ~]$ ln hello.java abc

find

查找当前位置下的文件

[xzd@localhost ~]$ find hello.javahello.java

常用的是参数-name,按文件名查找。下面是按照开头为“Hello”的文件名查找。

[xzd@localhost ~]$ find Hello*Hello.classHello.java

grep

搜索文本中的内容

[xzd@localhost ~]$ cat Hello.java | grep publicpublic class Hello{        public static void main(String[] args)throws Exception{

gzip

压缩文件,压缩后以“.gz”结尾

[xzd@localhost ~]$ gzip 1.tar

常用参数有-d解压,-v输出压缩信息

[xzd@localhost ~]$ gzip -dv 1.tar.gz 1.tar.gz:        97.2% -- replaced with 1.tar

tar

可以把多个文件打包成一个tar文件

-c创建一个新的tar文件 -v输出打包信息 -f使用后面的文档名

[xzd@localhost ~]$ tar -cvf  1.tar hello.java Hello.java hello.javaHello.java

常用参数有-z,打包的时候压缩成.gz

[xzd@localhost ~]$ tar -zcvf  1.tar hello.java Hello.java hello.javaHello.java

-x解压一个压缩后的tar文件

[xzd@localhost ~]$ tar -zxvf 1.tar hello.javaHello.java
0 0