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

SQL Script dành cho người lười - Some simple SQL scripts

Người lười biếng thường hay chả muốn làm nhiều, sau đây là một số script sql dành cho copy/paste: (thay phần bôi đậm bằng nội dung thực tế) > Ghi chú trong SQL script  1. Ghi chú 1 dòng, sử dụng --  VD: select * from users -- tất cả các dòng trong bảng users 2. Ghi chú khối, sử dụng /* */ VD: /* Ghi chú hàng 1 Ghi chú hàng 2 */ > Wildcard character %: thay thế cho nhiều ký tự hoặc không ký tự nào. _ : thay thế cho 1 ký tự VD:  SELECT * FROM USERS WHERE USERNAME LIKE 'M%' --M% có thể là: Minh, Mạnh, M, Mai... SELECT * FROM USERS WHERE USERNAME LIKE 'N_M' -- N_M có thể là: NAM, NẤM, NEM... > Tạo database, tạo user, cấp quyền owner a. Tạo database USE [MASTER] CREATE DATABASE [ TENDB] CREATE LOGIN TENUSER WITH PASSWORD=N' MATKHAU ', DEFAULT_DATABASE=[ TENDB ] //mật khẩu sẽ phải tuân theo password rule của windows, trường hợp không muốn theo rule của windows + password không hết hạn sử dụng sau 1 thời gian thì có thể thêm một số tùy chọn vào CREATE LOGIN  T

Chứng chỉ SSL - các dạng khác nhau - different ssl certificate format

 Tùy theo cấu hình server, chứng chỉ ssl có thể phải chuyển đổi sang các dạng khác nhau cho tương thích: - Windows server sử dụng file .pfx (X509) - Apache server sử dụng file .crt, .cer (PKCS7) Thông tin chứng chỉ SSL có thể thường được cung cấp dưới dạng sau (Dạng PEM): Phần này là private key: -----BEGIN PRIVATE KEY----- MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDZgq+0hUok18fb PRPNlJM4+/ANA9c329wUGGUyJwWvHNiqNgluuqp1VjtFQfoaraXaPK1g16M8HRlH NPckoFKZaTfCh9u+Xm3wiarj4i ...  CUCgYAn55Na3tvRisIUEVc2 K36njpoNhQ9kxjoPzFUIjccsAO9/Mt8eXL1xBdX38ox/0g+fTkLqotT6+ERWhRti fz/xoHov8rii6yDaSMMumw/DuQ8s/v6eZqN/jlqoRToEziFR5UAb4HmSQ94uki8+ 3P0hk68HHT45bb9NnnDcIZki/A== -----END PRIVATE KEY----- Phần này là certificate: -----BEGIN CERTIFICATE----- MIIGpDCCBYygAwIBAgIQCrWg6/cP1Y1qYOPaOxJk0DANBgkqhkiG9w0BAQsFADBZ MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMTMwMQYDVQQDEypS PB0ZRzT3JKBSmWk3w ...  dxxkfW97d5XtEixwNTce/3aCHJ1ivc f0u163DjYO3CmebXHAyd5FpszqaFrX29vQFF/1mrw7/pd77JffmP6o8BIo2xrq0f h

Trỏ tên miền vào website tạo tại blogspot.com

 blogspot.com hay blogger.com cung cấp website miễn phí dạng coidat.blogspot.com , dinhnhusam.blogspot.com Thay vì sử dụng 1 tên miền theo đuôi .blogspot.com, bạn có thể dùng 1 tên miền được đăng ký bên ngoài sau đó trỏ tên miền này vào website được tạo trên blogspot của bạn. Thực hiện trỏ tên miền vào website tạo tại blogspot theo các bước sau: Bước 1: Vào blogspot khai báo tên miền cần thêm vào Bước 2: Nhập tên miền theo đúng định dạng Bước 3: Đăng nhập vào tài khoản quản trị tên miền của bạn (Không cần thực hiện bước này nếu tên miền được đăng ký tại google) Bước 4:  Tạo các record theo yêu cầu của Google  (Không cần thực hiện bước này nếu tên miền được đăng ký tại google) Bước 5: Cấu hình SSL cho website Chi tiết các bước thực hiện: Bước 1 : Vào blogspot khai báo tên miền cần thêm vào Đăng nhập vào blogspot.com, vào đến mục Cài đặt (Settings) > Miền tùy chỉnh (Custom domain) như hình Bước 2 : Nhập tên miền theo đúng định dạng Nhập tên miền có dạng www. .Khi trỏ tên miền sẽ có lư