Linux common basic commands ( tree, pwd, cd )

pwd and cd commands

The >pwd command is an acronym for each word in "print working directory" and its function is to display the absolute path to the current working directory. In actual work, when we operate commands on the command line, we often switch between various directory paths. At this time, we can use the pwd command to quickly view the directory path we are currently in.

There is also a $PWD environment variable that shows the absolute path to the current working directory

ghostwu@dev:~$ echo $PWD
/home/ghostwu
ghostwu@dev:~$ cd ./php
ghostwu@dev:~/php$ echo $PWD
/home/ghostwu/php
ghostwu@dev:~/php$ pwd
/home/ghostwu/php
ghostwu@dev:~/php$ 

 

ghostwu@dev:~$ pwd
/home/ghostwu
ghostwu@dev:~$ cd /
ghostwu@dev:/$ pwd
/
ghostwu@dev:/$ ls
bin    dev   initrd.img  lost+found  opt   run   srv  usr
boot   etc   lib         media       proc  sbin  sys  var
cdrom  home  lib64       mnt         root  snap  tmp  vmlinuz
ghostwu@dev:/$ cd /etc/
ghostwu@dev:/etc$ cd
ghostwu@dev:~$ cd -
/etc
ghostwu@dev:/etc$ cd ~
ghostwu@dev:~$ cd -
/etc
ghostwu@dev:/etc$ cd ../home/ghostwu/
ghostwu@dev:~$ 

 

The cd command is an acronym for each word in "change directory", and its function is to switch from the current working directory to the specified working directory.

> Change to the directory one level above the current directory (cd..).

> Change to the current directory ( cd . ).

> switch to the home directory ( cd ~ ), cd without parameters also switches to the home directory

change to the directory just now ( cd - )

 

tree command, view the organizational structure of directories and files, by default ubuntu does not install tree

ghostwu@dev:~$ tree
The program 'tree' is currently not installed. You can install it by typing:
sudo apt install tree
ghostwu@dev:~$ sudo apt install tree
ghostwu@dev:~$ tree
.
├── Desktop
├── Documents
├── Downloads
│   ├── 1.rar
│ ├── 1 - copy.pptx
│   ├── 2.rar
│ ├── 2 - copy.pptx
│   ├── 3.rar
...............

tree -d: only show directories

tree -dL 2: The L parameter specifies the displayed level 2 means 2 levels

tree -df: show the full path

tree -dfi: don't show tree hierarchy

tree -L 1 -F: The F parameter will add a / after the directory, which is used to distinguish it from the file

ghostwu@dev:~$ tree -L 1
.
├── Desktop
├── Documents
├── Downloads
├── examples.desktop
├── git_test
├── info
├── Music
├── php
├── Pictures
├── project
├── Public
├── python
├── software
├── Templates
└── Videos

14 directories, 1 file
ghostwu@dev:~$ tree -L 1 -F
.
├── Desktop/
├── Documents/
├── Downloads/
├── examples.desktop
├── git_test/
├── info/
├── Music/
├── php/
├── Pictures/
├── project/
├── Public/
├── python/
├── software/
├── Templates/
└── Videos/

14 directories, 1 file
ghostwu@dev:~$ 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325040633&siteId=291194637