Chuyển đến nội dung chính

CentOS Linux commands

 

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


Nhận xét

Bài đăng phổ biến từ blog này

Xóa nhanh tất cả dữ liệu trong một bảng Microsoft SQL Server bằng TRUNCATE

 Thường chúng ta sẽ  sử dụng câu lệnh DELETE để xóa dữ liệu, và xóa hết dữ liệu trong một bảng bằng câu lệnh có cú pháp "delete from table <tên của bảng>". Cách xóa này thường rất mất thời gian, nếu dữ liệu trong bảng nhiều. Vậy có cách nào xóa nhanh hơn không? Chúng ta có thể sử dụng câu lệnh TRUNCATE để xóa tất cả dữ liệu trong bảng với thời gian nhanh hơn nhiều so với sử dụng câu lệnh xóa thông thường. Nhưng có một số vấn đề cần phải lưu ý khi thực hiện truncate dữ liệu của một bảng, đó là: - Truncate sẽ xóa hết tất cả (lưu ý là "tất cả" nhé) - Không truncate được khi bảng có khóa ngoại (trừ trường hợp khóa ngoại trong chính bảng cần xóa) - Khi đã truncate rồi khi không có cửa để phục hồi lại như sử dụng lệnh delete đâu nha. Cú pháp: TRUNCATE TABLE <TÊN BẢNG> Một số sql script hữu ích sử dụng kèm: 1. Giảm dung lượng theo phần trăm Cách này sẽ giảm kích thước của database (gồm cả file data và file log) xuống duy trì 10% free cho database: DBCC SHRINKDA

Windows Server - Khắc phục lỗi Windows Server 2016/2019/2022 tự shutdown sau khi hết hạn trial

Khắc phục Windows Server tự shutdown sau khi hết hạn trial Sau khi thời gian trial của Windows Server 2016/2019/2022 hết thời gian trial, Windows sẽ tự shutdown. Có thể xem trong Event Viewer > Windows Logs > System: Để tăng thời gian trial, có thể thực hiện theo các bước sau:  Mở Windows PowerShell B1:  > slmgr -dlv B2: > slmgr -rearm B3:  Restart Windows B4:  > slmgr -dli

Một số điều thú vị về môn võ Taekwondo tại Việt Nam

Thú vị và lộn xộn nhất có lẽ là về màu đai cho võ sinh Taekwondo tại Việt Nam Hệ thống đẳng cấp của Taekwondo tại Việt Nam phổ biến nhất là theo Taekwondo WTF. Có 8 cấp và 10 đẳng tương ứng với các màu đai tương ứng như sau: Màu đai Đẳng cấp Danh xưng Thời gian Bài quyền thi cuối Trắng Cấp 8 (geup) Võ sinh Nhập môn 1 Vàng Cấp 7 Võ sinh 3 tháng 2 Xanh lá Cấp 6 Võ sinh 3 tháng 3 Xanh dương Cấp 5 Võ sinh 3 tháng 4 Đỏ Cấp 4 Võ sinh 3 tháng 5 Đỏ Cấp 3 Võ sinh 3 tháng 6 Đỏ Cấp 2 Võ sinh 3 tháng 7 Đỏ Cấp 1 Võ sinh 3 tháng 8 Đen 1 đẳng (dan/poom) Võ sinh huyền đai (Nếu dưới 16 tuổi sẽ mang đai đỏ đen - gọi là poom. Tối đa 4 poom.) 6 tháng 9 Đen 2 đẳng Trợ lý Huấn luyện viên 1 năm 10 Đen 3 đẳng Trợ lý Huấn luyện viên 2 năm 11 Đen 4 đẳng Huấn luyện viên 3 năm 12 Đen 5 đẳng Huấn luyện viên 13 Đen 6 đẳng Võ sư 14 Đen 7 đẳng Võ sư 15 Đen 8 đẳng Võ sư 16 Đen 9 đẳng Võ sư 17 Đen 10 đẳng Võ sư Nhưng cũng có một số biến thể khác nhau, có thể là như sau: Màu đai Đẳng cấp So với màu đai WTF Trắng Cấp 8 T