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

โปรแกรมน่าติดตั้ง

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

Uninstall

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::"
/usr/lib/jvm/java-8-openjdk-amd64/jre/

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

$ python3 --version
Python 3.6.9

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

ดู hostname

hostnamectl

ดู current directory (print working directory)

pwd

get back to home directory:

cd

whoami command will remind you of your username

whoami

ls (list) command:

ls
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: <http://www.gnu.org/software/coreutils/>
Full documentation at: <http://www.gnu.org/software/coreutils/mkdir>
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: <http://www.gnu.org/software/coreutils/>
Full documentation at: <http://www.gnu.org/software/coreutils/wc>
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

tree

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

9 directories, 0 files
tree
tree -a