ติดตั้ง tree

# yum install tree	 #RHEL/CentOS 7
# dnf install tree	 #Fedora 22+ and /RHEL/CentOS 8
$ sudo apt install tree	 #Ubuntu/Debian
# sudo zypper in tree 	 #openSUSE


# tree --version
tree v1.6.0 (c) 1996 - 2011 by Steve Baker, Thomas Moore, Francesc Rocher, Kyosuke Tokoro
$ tree --version
tree v1.7.0 (c) 1996 - 2014 by Steve Baker, Thomas Moore, Francesc Rocher, Florian Sesser, Kyosuke Tokoro
$ tree --version
tree v1.8.0 (c) 1996 - 2018 by Steve Baker, Thomas Moore, Francesc Rocher, Florian Sesser, Kyosuke Tokoro

ดู help

$ tree --help
usage: tree [-acdfghilnpqrstuvxACDFJQNSUX] [-H baseHREF] [-T title ]
        [-L level [-R]] [-P pattern] [-I pattern] [-o filename] [--version]
        [--help] [--inodes] [--device] [--noreport] [--nolinks] [--dirsfirst]
        [--charset charset] [--filelimit[=]#] [--si] [--timefmt[=]<f>]
        [--sort[=]<name>] [--matchdirs] [--ignore-case] [--fromfile] [--]
        [<directory list>]
  ------- Listing options -------
  -a            All files are listed.
  -d            List directories only.
  -l            Follow symbolic links like directories.
  -f            Print the full path prefix for each file.
  -x            Stay on current filesystem only.
  -L level      Descend only level directories deep.
  -R            Rerun tree when max dir level reached.
  -P pattern    List only those files that match the pattern given.
  -I pattern    Do not list files that match the given pattern.
  --ignore-case Ignore case when pattern matching.
  --matchdirs   Include directory names in -P pattern matching.
  --noreport    Turn off file/directory count at end of tree listing.
  --charset X   Use charset X for terminal/HTML and indentation line output.
  --filelimit # Do not descend dirs with more than # files in them.
  --timefmt <f> Print and format time according to the format <f>.
  -o filename   Output to file instead of stdout.
  ------- File options -------
  -q            Print non-printable characters as '?'.
  -N            Print non-printable characters as is.
  -Q            Quote filenames with double quotes.
  -p            Print the protections for each file.
  -u            Displays file owner or UID number.
  -g            Displays file group owner or GID number.
  -s            Print the size in bytes of each file.
  -h            Print the size in a more human readable way.
  --si          Like -h, but use in SI units (powers of 1000).
  -D            Print the date of last modification or (-c) status change.
  -F            Appends '/', '=', '*', '@', '|' or '>' as per ls -F.
  --inodes      Print inode number of each file.
  --device      Print device ID number to which each file belongs.
  ------- Sorting options -------
  -v            Sort files alphanumerically by version.
  -t            Sort files by last modification time.
  -c            Sort files by last status change time.
  -U            Leave files unsorted.
  -r            Reverse the order of the sort.
  --dirsfirst   List directories before files (-U disables).
  --sort X      Select sort: name,version,size,mtime,ctime.
  ------- Graphics options -------
  -i            Don't print indentation lines.
  -A            Print ANSI lines graphic indentation lines.
  -S            Print with CP437 (console) graphics indentation lines.
  -n            Turn colorization off always (-C overrides).
  -C            Turn colorization on always.
  ------- XML/HTML/JSON options -------
  -X            Prints out an XML representation of the tree.
  -J            Prints out an JSON representation of the tree.
  -H baseHREF   Prints out HTML format with baseHREF as top directory.
  -T string     Replace the default HTML title and H1 header with string.
  --nolinks     Turn off hyperlinks in HTML output.
  ------- Input options -------
  --fromfile    Reads paths from files (.=stdin)
  ------- Miscellaneous options -------
  --version     Print version and exit.
  --help        Print usage and this help message and exit.
  --            Options processing terminator.


การใช้งาน tree แสดง file และ directory

$ tree
├── Desktop
├── Documents
├── Downloads
├── Music
├── Pictures
├── Public
├── Templates
└── Videos

8 directories, 0 files

แสดงขนาดไฟล์ แบบอ่านง่ายๆ

$ tree -h
├── [4.0K]  Desktop
├── [4.0K]  Documents
├── [4.0K]  Downloads
├── [4.0K]  Music
├── [4.0K]  Pictures
├── [4.0K]  Public
├── [4.0K]  Templates
└── [4.0K]  Videos

8 directories, 0 files

แสดง hidden files 

$ tree -a

To list the directory contents with the full path prefix for each sub-directory and file

$ tree -f

แสดงเฉพาะ directory (ไม่แสดง file)

$ tree -d 

To display only those files that match the wild-card pattern (ใช้ค้นหาไฟล์ได้)

$ tree -P jack*

To prune empty directories from the output

$ tree --prune

To prints the file type and permissions 

$ tree -p

แสดง username และ group name

$ tree -pug
├── [drwxr-xr-x jack     jack    ]  Desktop
├── [drwxr-xr-x jack     jack    ]  Documents
├── [drwxr-xr-x jack     jack    ]  Downloads
├── [drwxr-xr-x jack     jack    ]  Music
├── [drwxr-xr-x jack     jack    ]  Pictures
├── [drwxr-xr-x jack     jack    ]  Public
├── [drwxr-xr-x jack     jack    ]  Templates
└── [drwxr-xr-x jack     jack    ]  Videos

8 directories, 0 files
$ tree -pugh
├── [drwxr-xr-x jack     jack     4.0K]  Desktop
├── [drwxr-xr-x jack     jack     4.0K]  Documents
├── [drwxr-xr-x jack     jack     4.0K]  Downloads
├── [drwxr-xr-x jack     jack     4.0K]  Music
├── [drwxr-xr-x jack     jack     4.0K]  Pictures
├── [drwxr-xr-x jack     jack     4.0K]  Public
├── [drwxr-xr-x jack     jack     4.0K]  Templates
└── [drwxr-xr-x jack     jack     4.0K]  Videos

8 directories, 0 files

To display the date of the last modification time for each sub-directory or file

$ tree -pughD
├── [drwxr-xr-x jack     jack     4.0K Jul  9 10:20]  Desktop
├── [drwxr-xr-x jack     jack     4.0K Jul  9 10:20]  Documents
├── [drwxr-xr-x jack     jack     4.0K Jul  9 10:20]  Downloads
├── [drwxr-xr-x jack     jack     4.0K Jul  9 10:20]  Music
├── [drwxr-xr-x jack     jack     4.0K Jul  9 10:20]  Pictures
├── [drwxr-xr-x jack     jack     4.0K Jul  9 10:20]  Public
├── [drwxr-xr-x jack     jack     4.0K Jul  9 10:20]  Templates
└── [drwxr-xr-x jack     jack     4.0K Jul  9 10:20]  Videos

8 directories, 0 files

To send or redirect the tree’s output to filename for later analysis 

$ sudo tree -o direc_tree.txt

ติดตั้ง vsftpd บน CentOS 7

Step 1: Install FTP Service with VSFTPD

1.Start by updating the package manager:

sudo yum update

2.Install VSFTPD software 

sudo yum install vsftpd

3. Start the service and set it to launch when the system boots with the following:

sudo systemctl start vsftpd
sudo systemctl enable vsftpd

4. Next, create a rule for your firewall to allow FTP traffic on Port 21

sudo firewall-cmd --zone=public --permanent --add-port=21/tcp
sudo firewall-cmd --zone=public --permanent --add-service=ftp
sudo firewall-cmd --reload

Step 2: Configuring VSFTPD

1. Before starting, create a copy of the default configuration file:

sudo cp /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.default

2. Next, edit the configuration file 

sudo nano /etc/vsftpd/vsftpd.conf

3. Set your FTP server to disable anonymous users and allow local users


4. Next, allow a logged-in user to upload files to your FTP server.


5. Limit FTP users to their own home directory. This is often called jail or chroot jail. Find and adjust the entry to match the following:


ติดตั้ง vsftpd บน Ubuntu 18.04

vsftpd – FTP Server Installation
vsftpd is an FTP daemon available in Ubuntu.

$ sudo apt install vsftpd

Anonymous FTP Configuration
By default vsftpd is not configured to allow anonymous download. If you wish to enable anonymous download edit /etc/vsftpd.conf by changing:


During installation a ftp user is created with a home directory of /srv/ftp. This is the default FTP directory.

If you wish to change this location, to /srv/files/ftp for example, simply create a directory in another location and change the ftp user’s home directory:

sudo mkdir /srv/files/ftp
sudo usermod -d /srv/files/ftp ftp

After making the change restart vsftpd:

sudo systemctl restart vsftpd.service

Finally, copy any files and directories you would like to make available through anonymous FTP to /srv/files/ftp, or /srv/ftp if you wish to use the default.

กำหนดให้สามารถ upload ไฟล์เข้ามาได้

แก้ไขไฟล์ /etc/vsftpd.conf


เสร็จแล้ว restart vsftpd:

sudo systemctl restart vsftpd.service


ติดตั้ง Git

  1. ติดตั้ง Git
  2. Getting a Git Repository
  3. Recording Changes to the Repository
  4. Branch
    • Delete branch
    • Rename branch
  5. Tag
  6. Fix

1. ติดตั้ง Git

Install Git with Yum

sudo yum install git

Install Git with apt

sudo apt install git


git --version

Set Up Git

Name and email address

git config --global "Your Name"
git config --global ""

Git can handle this by auto-converting CRLF line endings into LF when you add a file to the index, and vice versa when it checks out code onto your filesystem. You can turn on this functionality with the core.autocrlf setting. If you’re on a Windows machine, set it to true — this converts LF endings into CRLF when you check out code:


git config --global core.autocrlf true

If you’re on a Linux or macOS system that uses LF line endings, then you don’t want Git to automatically convert them when you check out files; however, if a file with CRLF endings accidentally gets introduced, then you may want Git to fix it. You can tell Git to convert CRLF to LF on commit but not the other way around by setting core.autocrlf to input:

git config --global core.autocrlf input

Your default branch name

By default Git will create a branch called master when you create a new repository with git init. From Git version 2.28 onwards, you can set a different name for the initial branch.

git config --global init.defaultBranch main


git config --global core.ignorecase false

Checking Your Settings

ค่าที่แสดงออกมา มีทั้งค่า global และ user

git config --list

You can view all of your settings and where they are coming from using:

ดูว่า config อะไรมาจากไฟล์ไหนใช้ --show-origin

git config --list --show-origin

Git config file locations

2. Getting a Git Repository

Initializing a Repository in an Existing Directory

cd /home/user/my_project
git init
git add *.c
git add LICENSE
git commit -m 'Initial project version'

หรือ add ทุกไฟล์ใน directory ด้วย

git add .

แต่ถ้าจะลบไฟล์ก็ git rm (ลบไฟล์พร้อมกับ stage ให้ด้วย)

git rm <filename>

แต่ถ้าจะ discard (Undoing Uncommitted Changes) – Git Undo Commit: How to Undo Changes in Git (

$ git stash

Cloning an Existing Repository

You clone a repository with git clone <url>. For example, if you want to clone the Git linkable library called libgit2, you can do so like this:

git clone

If you want to clone the repository into a directory named something other than libgit2, you can specify the new directory name as an additional argument:

git clone mylibgit

ถ้า clone แล้วได้ error

fatal: unable to access '': Peer's Certificate issuer is not recognized.

ให้แก้ไขโดยการ ignore CA – git – what does this error message imply: fatal: unable to access ‘https:URL’: Peer’s Certificate issuer is not recognized? – Stack Overflow

env GIT_SSL_NO_VERIFY=true git clone https://github...

หรือ set http.sslverify ให้เป็น false เลย

$ git config --global http.sslverify false

3. Recording Changes to the Repository

Checking the Status of Your Files

git status

ถ้าจะให้แสดง diff (staged) ด้วยก็

git status -v


git status -s
$ echo 'My Project' > README
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
  (use "git add <file>..." to include in what will be committed)


nothing added to commit but untracked files present (use "git add" to track)

Tracking New Files

git add README
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)

    new file:   README

Ignoring Files

$ cat .gitignore

Viewing Your Staged and Unstaged Changes

To see what you’ve changed but not yet staged, type git diff with no other arguments:

git diff

If you want to see what you’ve staged that will go into your next commit, you can use git diff --staged or git diff --cached.

git diff --staged


git status -v

Committing Your Changes

git commit -m "Story 182: fix benchmarks for speed"

ดูประวัติการ commit

git log
git log --oneline
git log --oneline --graph

การ reset (ย้อนกลับ) โดย default จะเป็นแบบ mixed

git reset <เลข commit ที่ได้จาก git log>

ดูประวัติ commit (รวมที่ reset ไปแล้วด้วย)

git reflog

ถ้าอยากย้อนกลับไป commit ที่เคย reset หายไปแล้ว ก็ทำได้ด้วย

git reset <เลข commit ที่ได้จาก git reflog>

git push

git push origin main

git pull

git pull

git fetch

git fetch

4. Branch

Create Branch

git branch <branch_name>

Remove Branch (Local)

git branch -d <branch_name>

Switch Branch

git checkout <branch_name>

Create and Switch Branch

git checkout -b <branch_name> <commit_id (optional)>

List branch

git branch

Git Merge

git merge <branch_name>
git merge <branch_name> --no-ff # merge commit

Delete branch

git branch --delete <branch_name>

ถ้าเป็น branch ที่ยังไม่ได้ fully merged จะ error: The branch ‘<branch_name>‘ is not fully merged.
If you are sure you want to delete it, run ‘git branch -D <branch_name>‘.

git branch -D <branch_name>

Rename branch

There are a few ways to accomplish that:

  1. Change your local branch and then push your changes
  2. Push the branch to remote with the new name while keeping the original name locally

Renaming local and remote

# Rename the local branch to the new name
git branch -m <old_name> <new_name>

# Delete the old branch on remote - where <remote> is, for example, origin
git push <remote> --delete <old_name>

# Or shorter way to delete remote branch [:]
git push <remote> :<old_name>

# Prevent git from using the old name when pushing in the next step.
# Otherwise, git will use the old upstream name instead of <new_name>.
git branch --unset-upstream <new_name>

# Push the new branch to remote
git push <remote> <new_name>

# Reset the upstream branch for the new_name local branch
git push <remote> -u <new_name>

ลองเปลี่ยนชื่อ branch จาก develop เป็น dev

> git branch -m develop dev

> git push origin --delete develop

> git branch --unset-upstream dev

> git push origin dev
> git push origin -u dev

Renaming Only remote branch

# In this option, we will push the branch to the remote with the new name
# While keeping the local name as is
git push <remote> <remote>/<old_name>:refs/heads/<new_name> :<old_name>

5. Tag

Listing Your Tags

Listing the existing tags in Git is straightforward. Just type git tag (with optional -l or --list):

$ git tag

This command lists the tags in alphabetical order; the order in which they are displayed has no real importance.

You can also search for tags that match a particular pattern. The Git source repo, for instance, contains more than 500 tags. If you’re interested only in looking at the 1.8.5 series, you can run this:

$ git tag -l "v1.8.5*"

Creating Tags

Git supports two types of tags: lightweight and annotated.

A lightweight tag is very much like a branch that doesn’t change — it’s just a pointer to a specific commit.

Annotated tags, however, are stored as full objects in the Git database. They’re checksummed; contain the tagger name, email, and date; have a tagging message; and can be signed and verified with GNU Privacy Guard (GPG). It’s generally recommended that you create annotated tags so you can have all this information; but if you want a temporary tag or for some reason don’t want to keep the other information, lightweight tags are available too.

Annotated Tags

Creating an annotated tag in Git is simple. The easiest way is to specify -a when you run the tag command:

$ git tag -a v1.4 -m "my version 1.4"
$ git tag

You can see the tag data along with the commit that was tagged by using the git show command:

$ git show v1.4
tag v1.4
Tagger: Ben Straub <>
Date:   Sat May 3 20:19:12 2014 -0700

my version 1.4

commit ca82a6dff817ec66f44342007202690a93763949
Author: Scott Chacon <>
Date:   Mon Mar 17 21:52:11 2008 -0700

    Change version number

Push a tag to a remote repository

To push a single tag:

git push origin <tag_name>

And the following command should push all tags (not recommended):

# not recommended
git push --tags

6. Fix

ยังไม่ได้เชื่อมต่อด้วย SSH

ดูที่ Generate an SSH key pair

SSL certificate problem: unable to get local issuer certificate

Resolution #1 – Self Signed certificate

Tell git to not perform the validation of the certificate using the global option:

git config --global http.sslVerify false

You must use a personal access token with ‘read_repository’ or ‘write_repository’ scope for Git over HTTP.


สร้าง personal access token ที่มีสิทธิ read_repository or write_repository เป็นอย่างน้อย

สั่งรัน git clone ใหม่ แล้วจะมีไดอะล็อก ให้ใส่ username, password ก็ใส่ตามนี้

username: login
password: <credential ที่ได้จากตอนสร้าง personal access token>

แต่ถ้าไม่มีไดอะล็อก ให้ลองไปลบ ของเดิมที่ Credential Manager

ถ้ารันคำสั่ง git เช่น git fetch แล้วถาม password ทุกครั้ง ให้ set ตามนี้เพื่อจำ password (Make Git store the username and password and it will never ask for them.) – How to fix Git always asking for user credentials (

git config --global credential.helper store

คำสั่งพื้นฐาน Ubuntu 18.04


sudo apt update 
sudo apt install git
sudo apt install curl
sudo apt install tree
sudo apt install build-essential


sudo apt-get remove --auto-remove libcurl4-openssl-dev

ติดตั้ง Java

sudo apt install openjdk-8-jdk
$ java -version
openjdk version "1.8.0_312"
OpenJDK Runtime Environment (build 1.8.0_312-8u312-b07-0ubuntu1~18.04-b07)
OpenJDK 64-Bit Server VM (build 25.312-b07, mixed mode)

ถ้าติดตั้ง Java ไว้หลายตัว แล้วต้องการตั้ง default ใช้คำสั่ง

sudo update-alternatives --config java


$ readlink -f /usr/bin/java | sed "s:bin/java::"

Python จะติดมาอยู่แล้ว (18.04.5)

$ python3 --version
Python 3.6.9

เปิด Terminal กด Ctrl-Alt-T

ดู hostname


ดู current directory (print working directory)


get back to home directory:


whoami command will remind you of your username


ls (list) command:

ls -l
ls -a

Creating folders

mkdir /tmp/tutorial
mkdir dir1 dir2 dir3
$ mkdir --help
Usage: mkdir [OPTION]... DIRECTORY...
Create the DIRECTORY(ies), if they do not already exist.

Mandatory arguments to long options are mandatory for short options too.
  -m, --mode=MODE   set file mode (as in chmod), not a=rwx - umask
  -p, --parents     no error if existing, make parent directories as needed
  -v, --verbose     print a message for each created directory
  -Z                   set SELinux security context of each created directory
                         to the default type
      --context[=CTX]  like -Z, or if CTX is specified then set the SELinux
                         or SMACK security context to CTX
      --help     display this help and exit
      --version  output version information and exit

GNU coreutils online help: <>
Full documentation at: <>
or available locally via: info '(coreutils) mkdir invocation'
mkdir -p -v dir4/dir5/dir6

Creating files using redirection

ls > output1.txt
cat output1.txt

echo "This is a test1" > output2.txt
echo "This is a test2" >> output2.txt

cat output1.txt output2.txt
cat t* > combined.txt

When viewing a file through less you can use the Up Arrow, Down Arrow, Page Up, Page Down, Home and End keys to move through your file

less combined.txt

Moving and manipulating files

mv combined.txt dir1
mv dir1/* .

The mv command also lets us move more than one file at a time. If you pass more than two arguments, the last one is taken to be the destination directory and the others are considered to be files (or directories) to move.

mv combined.txt test_* dir3 dir2
cp dir4/dir5/dir6/combined.txt .
rmdir folder_*
rm -r folder_6

Word count

wc -l combined.txt
$ wc --help
Usage: wc [OPTION]... [FILE]...
  or:  wc [OPTION]... --files0-from=F
Print newline, word, and byte counts for each FILE, and a total line if
more than one FILE is specified.  A word is a non-zero-length sequence of
characters delimited by white space.

With no FILE, or when FILE is -, read standard input.

The options below may be used to select which counts are printed, always in
the following order: newline, word, character, byte, maximum line length.
  -c, --bytes            print the byte counts
  -m, --chars            print the character counts
  -l, --lines            print the newline counts
      --files0-from=F    read input from the files specified by
                           NUL-terminated names in file F;
                           If F is - then read names from standard input
  -L, --max-line-length  print the maximum display width
  -w, --words            print the word counts
      --help     display this help and exit
      --version  output version information and exit

GNU coreutils online help: <>
Full documentation at: <>
or available locally via: info '(coreutils) wc invocation'
ls ~ | wc -l
ls /etc | less
cat combined.txt | uniq | wc -l
man uniq | less
sort combined.txt | less
sort combined.txt | uniq | wc -l


sudo apt install tree
$ tree /home/
└── jack
    ├── Desktop
    ├── Documents
    ├── Downloads
    ├── Music
    ├── Pictures
    ├── Public
    ├── Templates
    └── Videos

9 directories, 0 files
tree -a