Basic commands

Shutdown/restart

> reboot

> shutdown

Clear screen

Ctrl + L

To clear the terminal screen, following is the command that you need to run: 

clear



CD

$ cd ..

$ cd /


List 

Lists directory contents of files and directories

https://www.rapidtables.com/code/linux/ls.html

https://superuser.com/questions/198529/how-to-scroll-one-page-at-a-time-in-linux-at-the-command-line/198531

https://superuser.com/questions/682128/list-files-of-folder-page-by-page-with-ls-command


$ ls | more

$ ls | less

Kết  hợp với các phím để cuộn lên xuống: shift + page up/down


Get command helps

$ df --help


Get size of directories - du

disk usage

//display amount space used của thư mục hiện tại

$ du -sh


//xem size của các thư mục, files trong thư mục hiện tại

$ du -sh *


Check disk space usage - df

disk filesystem

https://linuxhint.com/check_disk_space_centos/

$ df -h


Computer memory and swap - free

free command is used to get the detail used and unused information of the computer memory and swap.   You can also apply –help, -h and -m option with free command like previous commands.

free -h


Monitoring disks 

fdisk

https://linuxhint.com/check_disk_space_centos/


$ fdisk --help

Compress

Zip/unzip files

https://www.lifewire.com/practical-examples-of-the-zip-command-2201158

zip archivefile1 *

unzip archivefile1.zip

zip -r abc.zip *

 --nén tất cả các file, thư mục trong thư mục hiện tại vào file abc.zip


Tar


Rename files

> mv tenfilecu tenfilemoi

Vd: mv register.php register_.php


Remove file

https://www.geeksforgeeks.org/rm-command-linux-examples/

https://linuxize.com/post/rm-command-in-linux/


Force rm command on CentOS Linux to explain what is being done with file

Pass the -v option as follows to get verbose output on CentOS Linux box:

rm -v filename

rm -v cake-day.jpg


Centos Linux delete all files in folder or directory + The -f option tells rm never to prompt the user and to ignore nonexistent files and arguments:

rm -rf dir1

rm -rf /path/to/dir/

rm -rf /home/vivek/oldschoolpics/


-i (interactive - is used to prompt the user for confirmation before deleting each file)
-f  (force particularly dangerous, is used to force the removal of files or directories without prompting the user for confirmation, even if the files or directories are write-protected.)

-r (recursive -  remove directories and their contents)
-v (more verbose by showing a message for each file that is deleted)


View file content

more <tên file> 

hiển thị file theo từng trang.

cat < tên file>: hiển thị tất cả file.

head < tên file>: hiển thị các dòng đầu tiên.

tail < tên file>: hiển thị các dòng cuối cùng (có thể hữu ích trong những trường hợp như khi bạn muốn xem thông tin cuối cùng của một file hệ thống).


vi <tenfile>

Vim (Vi improved) is a popular text editor that is available on many Linux systems. It is an improved version of the older Vi text editor, with additional features and functionality that make it a popular choice for developers, system administrators, and other Linux users.


>> thoát bằng cách nhấn ESC sau đó gõ

> :q (thoát không lưu) hoặc 

> :w (lưu lại) hoặc 

> :wq (lưu, sau đó thoát)


https://quantrimang.com/tim-hieu-ve-ung-dung-vi-trong-linux-84778

https://vinasupport.com/huong-dan-su-dung-co-ban-lenh-vi-editor-tren-linux/




List running services 

using service command on a CentOS/RHEL 6.x or older

The syntax is as follows for CentOS/RHEL 6.x and older (pre systemd systems):

service --status-all

service --status-all | more

service --status-all | grep ntpd

service --status-all | less


Print the status of any service

To print the status of apache (httpd) service:

service httpd status


Mysql port: 3306

mysql -u root -p


Display status of sshd service:

service sshd status


# service httpd restart

> service httpd start

> service dovecot stop

> service postfix stop


service mariadb restart

Install Epel Repo CentOS 7

We can Install Epel Repository with yum command, Open Linux Terminal and type

yum -y install epel-release


Install Filezilla FTP Client

Now Lets Install FileZilla for Centos 7

yum -y install filezilla


systemctl enable vsftpd

systemctl start vsftpd



Network command

IP address

https://linuxize.com/post/linux-ip-command/

https://www.tecmint.com/ip-command-examples/


> ip a


Add ip

> ip address add 192.168.121.45/24 dev eth0

> ip address add 192.168.0.137 dev eth0    --mặc định sẽ là /32

> ip address add 192.168.0.137/24 dev eth0

>ip a del 192.168.0.137 dev eth0


Route

> ip route add 192.168.0.255/24 dev eth0