Linux上常用的基本命令

复制:copy

[keysystem@localhost happydzy]$ cp file1 file2
[keysystem@localhost happydzy]$ ll 
total 8
-rw-rw-r--. 1 keysystem keysystem 12 Dec  3 01:24 file1
-rw-rw-r--. 1 keysystem keysystem 12 Dec  3 01:24 file2
[keysystem@localhost happydzy]$ 

移动:move

[keysystem@localhost happydzy]$ mv file1 ..  
[keysystem@localhost happydzy]$ mv file2 dir/
[keysystem@localhost happydzy]$ 

重命名:rename

[keysystem@localhost happydzy]$ mv file1 file2 #将file1重命名为file2
[keysystem@localhost happydzy]$ mv dir1 dir2 #dir2存在,则为移动操作

移除:remove

[keysystem@localhost happydzy]$ rm file1 #移除file1文件
[keysystem@localhost happydzy]$ rm -r dir #移除dir目录

创建文件:touch 和 >

[keysystem@localhost happydzy]$ touch a.txt    #创建a.txt文件
[keysystem@localhost happydzy]$ >b.txt         #创建b.txt文件 
[keysystem@localhost happydzy]$ ll
total 0
-rw-rw-r--. 1 keysystem keysystem 0 Dec  3 01:41 a.txt
-rw-rw-r--. 1 keysystem keysystem 0 Dec  3 01:41 b.txt
[keysystem@localhost happydzy]$ 

创建目录:mkdir

[keysystem@localhost happydzy]$ mkdir dir
[keysystem@localhost happydzy]$ ll
total 4
drwxrwxr-x. 2 keysystem keysystem 4096 Dec  3 01:43 dir
[keysystem@localhost happydzy]$ 

查看文件:cat

[keysystem@localhost happydzy]$ cat a.txt 
hello world
[keysystem@localhost happydzy]$ 

查看文件类型:file

[keysystem@localhost happydzy]$ file a.txt 
a.txt: ASCII text
[keysystem@localhost happydzy]$ 
[keysystem@localhost happydzy]$ file index.html 
index.html: HTML document text
[keysystem@localhost happydzy]$

 通配符:*  可以匹配0个或多个

[keysystem@localhost happydzy]$ ls a*
a.txt
[keysystem@localhost happydzy]$ 

zip包的解压缩指令:unzip

[keysystem@localhost happydzy]$ unzip master.zip 
Archive:  master.zip
ac4da107fb56c46956d86fc10c7bbe2bb1423a4d
   creating: happygrep-master/
 extracting: happygrep-master/.gitignore  
  inflating: happygrep-master/Makefile  
  inflating: happygrep-master/Makefile.macosx  
  inflating: happygrep-master/README.md  
   creating: happygrep-master/contrib/
  inflating: happygrep-master/contrib/happygrep.sh  
  inflating: happygrep-master/contrib/wiki  
  inflating: happygrep-master/happygrep.c  
[keysystem@localhost happydzy]$ 

zip包的压缩指令:zip

[keysystem@localhost happydzy]$ zip -r happygrep-master.zip happygrep-master/
  adding: happygrep-master/ (stored 0%)
  adding: happygrep-master/Makefile.macosx (deflated 38%)
  adding: happygrep-master/Makefile (deflated 23%)
  adding: happygrep-master/contrib/ (stored 0%)
  adding: happygrep-master/contrib/happygrep.sh (deflated 57%)
  adding: happygrep-master/contrib/wiki (deflated 48%)
  adding: happygrep-master/README.md (deflated 46%)
  adding: happygrep-master/.gitignore (stored 0%)
  adding: happygrep-master/happygrep.c (deflated 71%)
[keysystem@localhost happydzy]$ ll -rlt
total 32
drwxrwxr-x. 3 keysystem keysystem  4096 Sep 25  2015 happygrep-master
-rw-rw-r--. 1 keysystem keysystem  2381 Jan 23  2017 index.html
drwxrwxr-x. 2 keysystem keysystem  4096 Dec  3 01:43 dir
-rw-rw-r--. 1 keysystem keysystem    12 Dec  3 01:44 a.txt
-rw-rw-r--. 1 keysystem keysystem 12418 Dec  3 02:04 happygrep-master.zip
[keysystem@localhost happydzy]$ 

tar.gz包的解压缩指令:tar zxvf xxx.tar.gz

[keysystem@localhost happydzy]$ 
[keysystem@localhost happydzy]$ tar zxvf wget-1.11.2.tar.gz 
wget-1.11.2/
wget-1.11.2/mkinstalldirs
......
[keysystem@localhost happydzy]$ 
[keysystem@localhost happydzy]$ 
[keysystem@localhost happydzy]$ ll -rlt
total 2340
drwxr-xr-x. 11 keysystem keysystem    4096 Apr 30  2008 wget-1.11.2
-rw-rw-r--.  1 keysystem keysystem 1460078 Apr 30  2008 wget-1.11.2.tar.gz
-rw-rw-r--.  1 keysystem keysystem  929549 Dec  3 02:08 wget-1.11.2.tar.bz2

tar.gz包的压缩指令:tar zcvf xxx.tar.gz xxx/

[keysystem@localhost happydzy]$ tar zcvf wget-1.11.2.tar.gz wget-1.11.2/

tar.bz2包的解压缩指令:tar jxvf xxx.tar.bz2

[keysystem@localhost happydzy]$ tar jxvf wget-1.11.2.tar.bz2 

tar.bz2包的压缩指令:tar jcvf xxx.tar.bz2

[keysystem@localhost happydzy]$ tar jcvf wget-1.11.2.tar.bz2 wget-1.11.2/
原文地址:https://www.cnblogs.com/alsodzy/p/7966655.html