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

命令行学习笔记(文件相关命令)

2016-12-07  本文已影响18人  TW安洋

效果如下:

➜  ~ ls
anyang         Documents         IdeaProjects  Public     wget-log
configuration  Downloads         Music         Templates
Desktop        examples.desktop  Pictures      Videos
➜  ~ ls -l
total 56
drwxr-xr-x 3 anyang anyang 4096 12月  2 19:50 anyang
drwxr-xr-x 3 anyang anyang 4096 11月 29 22:27 configuration
drwxr-xr-x 2 anyang anyang 4096 11月 29 11:56 Desktop
drwxr-xr-x 2 anyang anyang 4096 11月 29 11:56 Documents
drwxr-xr-x 5 anyang anyang 4096 11月 29 20:45 Downloads
-rw-r--r-- 1 anyang anyang 8980 11月 29 03:47 examples.desktop
drwxr-xr-x 2 anyang anyang 4096 11月 29 22:26 IdeaProjects
drwxr-xr-x 2 anyang anyang 4096 11月 29 11:56 Music
drwxr-xr-x 2 anyang anyang 4096 12月  2 21:44 Pictures
drwxr-xr-x 2 anyang anyang 4096 11月 29 11:56 Public
drwxr-xr-x 2 anyang anyang 4096 11月 29 11:56 Templates
drwxr-xr-x 2 anyang anyang 4096 11月 29 11:56 Videos
-rw-r--r-- 1 anyang anyang    0 11月 28 22:03 wget-log
➜  ~ ls -a
.                 .fonts.conf          Public
..                .gconf               .ssh
.adobe            .gitconfig           .sudo_as_admin_successful
anyang            .gnome               Templates
.bash_history     .gradle              Videos
.bash_logout      .ICEauthority        .viminfo
.bashrc           IdeaProjects         .WebStorm2016.3
.cache            .IntelliJIdea2016.3  wget-log
.compiz           .java                .Xauthority
.config           .local               .xinputrc
configuration     .macromedia          .xsession-errors
Desktop           .mozilla             .xsession-errors.old
.dmrc             Music                .zcompdump
Documents         .oh-my-zsh           .zcompdump-anyang-5.2
Downloads         Pictures             .zsh_history
examples.desktop  .pki                 .zshrc
.fonts            .profile             .zsh-update

效果如下:

➜  ~ cd anyang 
➜  anyang ls
file1  file2  learngit
➜  anyang cd ..
➜  ~ cd -
~/anyang
➜  anyang cd ~
➜  ~ cd anyang 
➜  anyang cd
➜  ~ 

效果如下:

➜  anyang ls   
file1  file2  learngit
➜  anyang mkdir test 
➜  anyang ls
file1  file2  learngit  test
➜  anyang rmdir test
➜  anyang ls
file1  file2  learngit

效果如下:

➜  anyang touch newfile1 newfile2 newfile3
➜  anyang ls
file1  file2  learngit  newfile1  newfile2  newfile3
➜  anyang rm file1 file2
➜  anyang ls
learngit  newfile1  newfile2  newfile3

效果如下:

➜  anyang mkdir test
➜  anyang ls
learngit  newfile1  newfile2  newfile3  test
➜  anyang cd test 
➜  test touch file1 file2 file3
➜  test ls
file1  file2  file3
➜  test cd ..
➜  anyang ls
learngit  newfile1  newfile2  newfile3  test
➜  anyang rmdir test 
rmdir: failed to remove 'test': Directory not empty
➜  anyang rm test                    // 此处如果不加 -r 参数,则会报错,因为该目录为非空目录
rm: cannot remove 'test': Is a directory
➜  anyang rm -r test
➜  anyang ls
learngit  newfile1  newfile2  newfile3

效果如下:

➜  anyang ls
file1  learngit  test
➜  anyang ls test 
➜  anyang mv file1 test 
➜  anyang ls test      
file1
➜  anyang ls
learngit  test
➜  anyang cd test 
➜  test mv file1 test1
➜  test ls
test1

效果如下:

➜  anyang ls
learngit  test
➜  anyang touch file1      
➜  anyang ls
file1  learngit  test
➜  anyang cp file1 test/test1
➜  anyang cd test
➜  test ls
test1
➜  anyang mkdir newtest
➜  anyang ls
file1  learngit  newtest  test
➜  anyang cp test newtest        // 如不加 -r 或 -R 参数则会报错,因为test目录非空
cp: omitting directory 'test'
➜  anyang cp -r test newtest
➜  anyang cd newtest 
➜  newtest ls
test

效果如下:

➜  anyang ls
file1  learngit  test
➜  anyang cat file1 
Hello, anyang!
➜  anyang cat > file2
Add some words!
^C
➜  anyang cat file2  
Add some words!

效果如下:

➜  anyang ls
file1  learngit  test
➜  anyang cat file1 
Hello, anyang!
➜  anyang ls test 
➜  anyang ln -s file1 test/file1
➜  anyang ls test               
file1
➜  anyang cd test 
➜  test ls -l
total 0
lrwxrwxrwx 1 anyang anyang 5 12月  7 10:44 file1 -> file1

效果如下:

➜  anyang stat file1 
  File: 'file1'
  Size: 15          Blocks: 8          IO Block: 4096   regular file
Device: 809h/2057d  Inode: 402603      Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/  anyang)   Gid: ( 1000/  anyang)
Access: 2016-12-07 10:10:58.987863942 +0800
Modify: 2016-12-07 10:10:45.947557464 +0800
Change: 2016-12-07 10:10:45.975558132 +0800
 Birth: -
➜  anyang pwd
/home/anyang/anyang

相关资料:

  1. 29个你必须知道的Linux命令: http://www.imooc.com/article/1285
  2. 常用命令行介绍: https://github.com/iamcoach/console/blob/master/COMMANDS.md
  3. 常用命令行cheet sheet: https://bbs.excellence-girls.org/topic/167
  4. 书籍《鸟哥的Linux私房菜》: https://book.douban.com/subject/4889838/
  5. Ubuntu各种技巧:http://wiki.ubuntu.org.cn/UbuntuSkills
上一篇 下一篇

猜你喜欢

热点阅读