[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/dunwu/linux-tutorial/master/docs/linux/cli/linux-cli-dir.md [Back]  [Original]

# Linux 

> `cd`, `ls`, `pwd`, `mkdir`, `rmdir`, `tree`, `touch`, `ln`, `rename`, `stat`, `file`, `chmod`, `chown`, `locate`, `find`, `cp`, `scp`, `mv`, `rm`

## 1. Linux 

### 1.1. Linux 

linux  `/` 

![img](https://raw.githubusercontent.com/dunwu/images/master/cs/os/linux/linux-folders.png)

### 1.2. Linux 

Linux Linux 
 Linux  ll  ls l 

```bash
$ ls -l
total 64
drwxr-xr-x 2 root root 4096 Dec 14 2012 bin
dr-xr-xr-x 4 root root 4096 Apr 19 2012 boot
```

bin  `d` `d`  Linux 
 Linux 

-  `d` 
-  `-` 
-  `l` (link file)
-  `b` ()
-  `c` ()

rwx `r` (read)`w` (write)`x` (execute)  `-` 

 10 

![img](https://raw.githubusercontent.com/dunwu/images/master/snap/20180920180927171909.png)

 0-9 

-  0 
-  1-3 
-  4-6 
-  7-9 
-  147 "r""-"
-  258 "w""-"
-  369 "x""-"

```bash
d rwx r-x r-x
   
   - (x/-)
     (w/-)
     (r/-)
    (x/-)
    (w/-)
    (r/-)
   (x/-)
   (w/-)
   (r/-)
  ()
```

#### 1.2.1. Linux 

```bash
$ ls -l
total 64
drwxr-xr-x   2 root root 4096 Dec 14  2012 bin
dr-xr-xr-x   4 root root 4096 Apr 19  2012 boot
```

- 
-  Linux 
- 
- Linux 
- bin  root

## 2. Linux 

### 2.1. 

-  -  [cd](#cd)
-  -  [ls](#ls)
-  -  [pwd](#pwd)
-  -  [tree](#tree)
-  -  [mkdir](#mkdir)
-  -  [rmdir](#rmdir)

### 2.2. 

-  -  [touch](#touch)
-  -  [ln](#ln)
-  -  [rename](#rename)
-  -  [stat](#stat)
-  -  [file](#file)
-  -  [chmod](#chmod)
-  -  [chown](#chown)
-  -  [locate](#locate)
-  -  [find](#find)
-  -  [which](#which)
-  -  [whereis](#whereis)

### 2.3. 

-  -  [cp](#cp)
-  -  [scp](#scp)
-  -  [mv](#mv)
-  -  [rm](#rm)

## 3. 

### 3.1. cd

> cd 
>
> http://man.linuxde.net/cd



```bash
cd          # 
cd ~        # 
cd -        # 
cd ..       # 
cd ../..    # 
```

### 3.2. ls

> ls 
>
> http://man.linuxde.net/ls



```bash
ls        # 
ls -l     # 
ls -la    # 
ls -lh    # 
ls -lt    # 
ls -ltr   # 
ls --color=auto     # 
```

### 3.3. pwd

> pwd 
>
> http://man.linuxde.net/pwd

### 3.4. mkdir

> mkdir 
>
> http://man.linuxde.net/mkdir



```bash
#  zp  zp  test
mkdir -p zp/test

#  zp  zp  test
mkdir -p -m 750 zp/test
```

### 3.5. rmdir

> rmdir 
>
> http://man.linuxde.net/rmdir



```bash
#  test  zp
rmdir -p zp/test
```

### 3.6. tree

> tree 
>
> http://man.linuxde.net/tree



```bash
#  /private 
tree /private -L 1
/private/
 etc
 tftpboot
 tmp
 var

# 
tree -I node_modules            #  node_modules
tree -P node_modules            #  node_modules 
tree -P node_modules -L 2       #  node_modules 
tree -L 2 > /home/www/tree.txt  #  tree.txt 

# 
tree -I 'node_modules|icon|font' -L 2
```

### 3.7. touch

> touch 
>
> http://man.linuxde.net/touch



```
touch ex2
```

### 3.8. ln

> ln "-s"
>
>  
>
> http://man.linuxde.net/ln



```bash
#  /usr/mengqc/mub1  m2.c  /usr/liu  a2.c
cd /usr/mengqc
ln /mub1/m2.c /usr/liu/a2.c

#  /usr/liu  abc /usr/mengqc/mub1
# /usr/mengqc/mub1  /usr/liu/abc 
ln -s /usr/mengqc/mub1 /usr/liu/abc
```

### 3.9. rename

> rename 
>
> http://man.linuxde.net/rename



```bash
#  main1.c  main.c
rename main1.c main.c main1.c

rename "s/AA/aa/" *             #  AA  aa
rename "s//.html//.php/" *      #  .html  .php 
rename "s/$//.txt/" *           #  txt 
rename "s//.txt//" *            #  .txt .txt 
```

### 3.10. stat

> stat stat  ls 
>
> http://man.linuxde.net/stat



```bash
stat myfile
```

### 3.11. file

> file file  3 
>
> http://man.linuxde.net/file



```bash
file install.log          # 
file -b install.log       # 
file -i install.log       #  MIME 
file -L /var/spool/mail   # 
```

### 3.12. chmod

> chmod  UNIX  3  3  chmod 
>
> http://man.linuxde.net/chmod



Linux  (Group)otherLinux  root   `/etc/passwd``/etc/shadow` `/etc/group`

linux 

```bash
  -rw-r--r--   1 user  staff   651 Oct 12 12:53 .gitmodules
# 
#       0 
#     g 
#   u 
#   `d` `-` 
```

rwx  rw- r--

r=// 4  
w=// 2  
x=// 1



```bash
chmod u+x,g+w f01# f01
chmod u=rwx,g=rw,o=r f01
chmod 764 f01
chmod a+x f01    # f01u,g,o

# /home/wwwroot/755
chmod -R  755 /home/wwwroot/*
```

### 3.13. chown

> chown  D id
>
> 
>
> http://man.linuxde.net/chown



```bash
# /usr/meng liu
chown -R liu /usr/meng
```

### 3.14. locate

> locate  slocate 
>
> locate  find -name /var/lib/locatedbLinux  locate  locate  updatedb 
>
> http://man.linuxde.net/locate_slocate



```bash
locate pwd      #  pwd 
locate /etc/sh  #  etc  sh 
```

### 3.15. find

> find  find 
>
> http://man.linuxde.net/find

```bash
#   140.206.111.111 
find . -type f -name "*" | xargs grep "140.206.111.111"

# 
find .

#  /home  .txt 
find /home -name "*.txt"
# 
find /home -iname "*.txt"

#  .txt  .pdf 
find . -name "*.txt" -o -name "*.pdf"

# 
find /usr/ -path "*local*"

# 
find . -regex ".*\(\.txt\|\.pdf\)$"
# 
find . -iregex ".*\(\.txt\|\.pdf\)$"

#  /home  .txt 
find /home ! -name "*.txt"
```

### 3.16. cp

> cp cp 
>
> http://man.linuxde.net/cp



#### 3.16.1. 

- cp `-R`
- 



```bash
#  file  /usr/men/tmp  file1
cp file /usr/men/tmp/file1

#  /usr/men /usr/zh 
cp -r /usr/men /usr/zh

#  /usr/men /usr/zh 
cp -rf /usr/men/* /usr/zh

#  /usr/men  m  .c  /usr/zh 
cp -i /usr/men m*.c /usr/zh
```

### 3.17. scp

> scp  Linux  cp cp  scp  read only system  scp scp rsync  rsync  scp rsync  I/O  scp 



```bash
# 
scp  @:
scp test.txt root@192.168.0.1:/opt

# 
scp -r  @:
scp -r test root@192.168.0.1:/opt
```

#### 3.17.1. 

1 ssh 

```
ssh-keygen -t rsa
```

2 A  `\~/.ssh/id_rsa.pub`  B  `\~/.ssh/authorized_keys` 

```bash
#  A 
scp ~/.ssh/id_rsa.pub root@192.168.0.2:~/.ssh/id_rsa.pub.tmp

#  B 
cat ~/.ssh/id_rsa.pub.tmp >> ~/.ssh/authorized_keys
rm ~/.ssh/id_rsa.pub.tmp
```

### 3.18. mv

> mv source target 
>
> http://man.linuxde.net/mv



```bash
mv file1.txt /home/office/                      # 
mv file2.txt file3.txt file4.txt /home/office/  # 
mv *.txt /home/office/                          #  txt 
mv dir1/ /home/office/                          # 
mv /usr/men/* .                                 # 

mv file1.txt file2.txt          # 
mv dir1/ dir2/                  # 
mv -v *.txt /home/office        # 
mv -i file1.txt /home/office    # 

mv -uv *.txt /home/office       # 
mv -vn *.txt /home/office       # 
mv -f *.txt /home/office        # 
mv -bv *.txt /home/office       # 
```

### 3.19. rm

> rm 
>
> http://man.linuxde.net/rm

```bash
rm test.txt               # 
rm -i test.txt test2.txt  # 
rm -r *                   # 
rm -r testdir             # 
rm -rf testdir            # 
rm -v testdir             # 
```

Web Proxy Viewer  |  New URL  |  Original Page