Linux简单命令行:文件/目录,sudo,包管理

命令行学习笔记: 基本文件/目录命令

2016-12-11  本文已影响18人  z嘉嘉嘉

学习内容

文件/目录相关基本命令: cd, mkdir, cp, rm, mv, pwd, ls, tar, zip, find, grep, less, tail, tree

个人总结

➜  ~ ls
Book       examples.desktop    Music           Public            wince3+1
Desktop    gradle-2.9-bin.zip  newRamlProject  Templates
Documents  IdeaProjects        pdf             Videos
Downloads  logs                Pictures        WebstormProjects
➜  ~ mkdir newDir
➜  ~ ls
Book       examples.desktop    Music           Public            wince3+1
Desktop    gradle-2.9-bin.zip  newRamlProject  Templates           newDir
Documents  IdeaProjects        pdf             Videos
Downloads  logs                Pictures        WebstormProjects

➜  ~ pwd
/home/zhyingjia

➜  ~ cd newDir 
➜  newDir pwd
/home/zhyingjia/newDir

➜  ~ rmdir newDir 
➜  ~ ls
Book       examples.desktop    Music           Public            wince3+1
Desktop    gradle-2.9-bin.zip  newRamlProject  Templates
Documents  IdeaProjects        pdf             Videos
Downloads  logs                Pictures        WebstormProjects
➜  newDir mkdir content
➜  newDir ls
content
➜  newDir cd ../
➜  ~ rmdir newDir 
rmdir: failed to remove 'newDir': Directory not empty
➜  ~ rm newDir 
rm: cannot remove 'newDir': Is a directory
➜  ~ rm -r newDir 
➜  ~ ls
Book       examples.desktop    Music           Public            wince3+1
Desktop    gradle-2.9-bin.zip  newRamlProject  Templates
Documents  IdeaProjects        pdf             Videos
Downloads  logs                Pictures        WebstormProjects

➜  newDir touch file1.txt
➜  newDir ls
content  file1.txt
➜  newDir cp file1.txt file2.txt
➜  newDir ls
content  file1.txt  file2.txt

➜  newDir ls
content  file1.txt  file2.txt
➜  newDir cp file2.txt content 
➜  newDir ls
content  file1.txt  file2.txt
➜  newDir cd content 
➜  content ls
file2.txt
➜  newDir ls
content  file2.txt
➜  newDir cd content 
➜  content ls
➜  content cd ../

//  重命名
➜  newDir mv file2.txt file.txt
➜  newDir ls
content  file.txt

//  移动
➜  newDir mv file.txt content 
➜  newDir ls
content
➜  newDir cd content 
➜  content ls
file.txt
➜  content ls            
file.txt
➜  content cat file.txt 
0 file test data
1 file test data
2 file test data
3 file test data
4 file test data
5 file test data
6 file test data
7 file test data
8 file test data
9 file test data
10 file test data
11 file test data
12 file test data
13 file test data


➜  content tail file.txt 
4 file test data
5 file test data
6 file test data
7 file test data
8 file test data
9 file test data
10 file test data
11 file test data
12 file test data
13 file test data
➜  content tail file.txt -n 3
11 file test data
12 file test data
13 file test data

➜  ~ grep "1 f" newDir/content/file.txt
1 file test data
11 file test data

➜  ~ grep "0 File" newDir/content/file.txt

➜  ~ grep "0 File" -i newDir/content/file.txt
0 file test data
10 file test data
➜  ~ cd newDir 

➜  newDir grep "0 File" -i -r 
content/file.txt:0 file test data
content/file.txt:10 file test data
➜  ~ find newDir -name content
newDir/content
➜  ~ find newDir -iname Content
newDir/content

➜  newDir ls
content
➜  newDir tar -cvf content.tar content 
content/
content/file.txt
➜  newDir ls
content  content.tar

➜  newDir tar -tvf content.tar
drwxrwxr-x zhyingjia/zhyingjia 0 2016-12-09 22:22 content/
-rw-rw-r-- zhyingjia/zhyingjia 242 2016-12-09 22:22 content/file.txt

➜  newDir rm -rf content
➜  newDir ls
content.tar
➜  newDir tar -xvf content.tar 
content/
content/file.txt
➜  newDir ls
content  content.tar
➜  content ls
file.txt
➜  content gzip file.txt 
➜  content ls
file.txt.gz
➜  content gzip -d file.txt.gz 
➜  content ls
file.txt

➜  content zip file.zip file.txt 
  adding: file.txt (deflated 100%)
➜  content ls
file.txt  file.zip
➜  content cd ../
➜  newDir ls
content
➜  newDir zip -r content.zip content 
  adding: content/ (stored 0%)
  adding: content/file.zip (stored 0%)
  adding: content/file.txt (deflated 100%)
➜  newDir ls
content  content.zip
// 因为解压的时候会有命名冲突,因此将content.zip移动到content下进行操作
➜  newDir mv content.zip content/
➜  newDir ls
content
➜  newDir cd content 
➜  content ls
content.zip  file.txt  file.zip
➜  content unzip -l content.zip 
Archive:  content.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  2016-12-10 13:20   content/
      193  2016-12-10 13:20   content/file.zip
    10240  2016-12-10 13:05   content/file.txt
---------                     -------
    10433                     3 files
➜  content unzip content.zip 
Archive:  content.zip
   creating: content/
 extracting: content/file.zip        
  inflating: content/file.txt        
➜  content ls
content  content.zip  file.txt  file.zip

➜  ~ cd newDir 
➜  newDir tree
.
└── content
    ├── content
    │   ├── file.txt
    │   └── file.zip
    ├── content.zip
    ├── file.txt
    └── file.zip

2 directories, 5 files

感受

参数学习需要在实际中学习总结。

上一篇下一篇

猜你喜欢

热点阅读