#init 0 #shutdown -hy -t // Tắt máy sau khoảng thời gian. Đơn vị : giây (s) #halt #poweroff
2) Khởi động hệ thống ( reboot)
#init 6 #reboot #shutdown -ry 10 // Chỉ định 10 phút sau tự khởi động hệ thống
3) Liên kết tập tin
Bạn muốn tập tin testfile trong đường dẫn /usr/testfile sẽ xuất hiện trong thư mục /usr/test
#ln /usr/testfile /user/test #lnChú ý : Nếu có sự thay đổi của nguồn thì đích sẽ thay đổi<đích>
4) Quản lý dung lượng đĩa , ram Dung lượng đĩa :
#df -h //Liệt kê file system #fdisk -l //Liệt kê partitionRam :
#free -m
5) Xác định vị trí thư mục hiện tại
#pwd
6) Truy cập thư mục
#cd {thư mục}
VD: cd /etc
7) Liệt kê nội dung thư mục
#ls [-x / -l -a ] {thư mục}
ls -x // hiển thị thư mục nhiều cột
ls -l // hiển thị chi tiết thông tin tập tin
ls -a // hiển thị tất cả các tập tin, kể cả tập tin ẩn
VD: ls -l /etc
8) Tạo và xóa thư mục
#mkdir {thư mục} // Tạo thư mục
VD:
cd /etc
mkdir testfile
#rmdir {thư mục} // Xóa thư mục
VD:
cd /etc
rmdir testfile
#rm [-r / -l ] { thư mục / tập tin }
rm -r : xóa thư mục và tập tin con bên trong thư mục đó
rm -l : xác nhận lại trước khi xóa
VD :
cd /etc/
rm-rf testfile
9) Xem tập tin văn bản
#cat {tập tin}
VD : cat /etc/test.txt
#more {tập tin} // Xem tập tin theo từng trang màn hình
VD : more /etc/passwd
10 ) Sao chép tập tin
#cpVD: cp /etc/passwd /root/passwd
11 ) Thay đổi tên tập tin hoặc di chuyển
#mvVD : mv /etc/testfile /opt/
12) Tìm kiếm tập tin , chuỗi
#find [đường-dẫn] -name [biểu-thức-tìm-kiếm] // Tìm kiếm tập tin VD: find /etc -name test // Tìm thư mục test có trong /etc nhưng không rõ đường dẫn.
#grep [biểu-thức-tìm-kiếm] [tên-tập-tin] //Tìm kiễm chuỗi kí tự trong 1 tập tin VD : grep “root” /etc/passwd //tìm các dòng có root trong file passwd
13) Chỉnh sửa tập tin
#vi {tập tin}
VD : vi /etc/test.txt
Ấn I : để sửa file
Esc : để thoát câu lệnh nhưng vẫn ở trong file
:wq! : lưu lại file sau khi sửa và quit
/{kí tư} : tìm kiếm file , ấn N để next kết quả
#nano {tập tin}
Để cài nano gõ lệnh : yum install nano -y
14) Chỉnh time trong centos
#date // Kiểm tra thời gian #yum install ntp -y // Cài dịch vụ NTP #ntpdate vn.pool.ntp.org // Chỉnh time theo múi giờ Việt Nam
15) Cài / Gỡ / Cập nhật phần mềm
#yum install {tên-phần-mềm} -y // Cài phần mềm
VD : yum install ntp -y
#yum remove {tên-phần-mềm} -y // Gỡ phần mềm
VD : yum remove ntp -y
#yum update {tên-phần-mềm} -y //cật nhập phần mềm
VD: yum update bind -y
hoặc
#rpm -Uvh {tên-tập-tin.rpm}
VD : rpm -Uvh foo-2.0-1.i386.rpm //Cập nhật phần mềm không xóa cấu hình
#yum update -y // Cập nhật hệ thống bao gồm các phần mềm
16) Nén và giải nén thư mục
Nén thư mục hoặc tập tin :
#gzip {tập tin}
VD : gzip /etc/passwd
#tar -cvf {tập tin}
VD : tar -cvf /etc/passwd
Giải nén thư mục hoặc tập tin :
#gunzip /etc/passwd.gz #tar -zxvf /etc/passwd.tar
17) Tạo và xóa user / group Tạo và xóa user
#useradd {tên-user} //Tạo user
VD: useradd lmc
#userdel {tên user} //Xóa user
Tạo và xóa group
#groupadd {tên-group} //Tạo group
VD: groupadd lmcgroup
#groupdel {tên-group} // Xóa group
Gán user vào group :
#usermod -g {tên-group} {tên-user}
VD: usermod -g lmcgroup lmc
18) Phân quyền tập tin Kiểm tra phần quyền các tập tin trong /etc
#cd /etc #ls -l-Có 3 quyền trong Linux : read (r) , write (r) , execute(x) tương ứng với : đọc-ghi-thực thi -Và 3 dạng đối tượng : sở hữu (owner) , nhóm sở hữu (group owner) , người khác (other owner) -Đối với thư mục khi ls -l sẽ có chữ d ở đầu , c cho thiết bị ngoại vi , b cho block , còn với file thì không có VD: drwxr-xr-x. – Ngoài ra, 3 quyền trong Linux sẽ có giá trị tương ứng : read = 4 , write = 2 , execute = 1 VD: Full quyền = read + write + execute = 4 + 2 + 1 = 7 Phân quyền thao tác tập tin (read – write – execute) :
#chmod {giá-trị-quyền} {tập-tin}
VD: chmod 777 testfile.txt
Phân quyền người dùng tập tin
#chown -R {tên-user:tên-nhóm} {thư-mục hoặc tập tin}
VD:
chown -R vnitnews testfile.txt
Thay đổi nhóm sở hữu tập tin
#chgrp {nhóm-sở-hữu} {thư mục hoặc tập tin }
19) Tải phần mềm
#yum install wget -y
#wget {đường-dẫn}
VD: wget https://manhchuc.com/lmc.logo
20) Cấu hình mạng Centos
#ifconfig // Kiểm tra card mạng hiện thời #ifconfig -a //Kiểm tra tất cả card mạngĐể cấu hình card mạng :
#vi /etc/sysconfig/network-scripts/ifcfg-eth0 //Thư mục chỉnh card mạngReset card mạng :
#service network restart21) Khởi động sang menu boot khác tạm thời
CENTOS
echo "savedefault --default=2 --once" | grub --batch
UBUNTU
grub-reboot 4 reboot*Thứ tự được đánh số từ 0
22) Thay đổi timezone
sudo dpkg-reconfigure tzdata
sudo usermod -a -G jenkins tomcat
chown jenkins:tomcat /opt/tomcat-test/bin/*.*
24) Kết nối wifi với Ubuntu
http://askubuntu.com/questions/412325/automatically-connect-to-a-wireless-network-using-cli
25) Tắt màn hình, tắt screen ubuntu
setpci -s 00:02.0 F4.B=0 setterm -blank 026) Add user vào group (để có quyền của group)
sudo usermod -aG docker $(whoami)27)To remove apache2 simply type:
28) Config services ubuntu 14.04:sudo update-rc.d -f apache2 removeDoing this will cause all runlevel folders that are linked to apache2 to be removed.
nano /etc/init.d/
The usual process is to amend /etc/network/interfaces (you do know vim or emacs, right?) something like this:Proofread, save and close vim. Restart the interface:Code:auto lo iface lo inet loopback auto wlan0 iface wlan0 inet static address 192.168.1.108 netmask 255.255.255.0 gateway 192.168.1.1 wpa-ssid mylilrouter wpa-psk mysecretkey dns-nameservers 8.8.8.8 192.168.1.1https://askubuntu.com/questions/228304/how-do-i-run-a-script-at-start-upCode:sudo ifdown wlan0 && sudo ifup wlan0
29) Ax OpenVPN Linux
Add config:comp-lzo yespush"comp-lzo yes"
30) Centos vs docker
firewall-cmd --zone=trusted --change-interface=docker0 --permanentfirewall-cmd --zone=trusted --add-masquerade --permanentfirewall-cmd --reload
#init 0 #shutdown -hy -t // Shut down after a delay, in seconds (s) #halt #poweroff
2) Restart the system (reboot)
#init 6 #reboot #shutdown -ry 10 // Restart the system automatically after 10 minutes
3) Link files
You want the file testfile at /usr/testfile to also appear in the folder /usr/test
#ln /usr/testfile /user/test #ln <source>Note: if the source changes, the target changes too<target>
4) Disk space and RAM Disk space:
#df -h //List file systems #fdisk -l //List partitionsRAM:
#free -m
5) Show the current folder
#pwd
6) Change folder
#cd {folder}
Example: cd /etc
7) List folder contents
#ls [-x / -l -a ] {folder}
ls -x // show the folder in several columns
ls -l // show file details
ls -a // show all files, including hidden ones
Example: ls -l /etc
8) Create and delete folders
#mkdir {folder} // Create a folder
Example:
cd /etc
mkdir testfile
#rmdir {folder} // Delete a folder
Example:
cd /etc
rmdir testfile
#rm [-r / -l ] { folder / file }
rm -r : delete the folder and everything inside it
rm -l : ask for confirmation before deleting
Example:
cd /etc/
rm-rf testfile
9) View text files
#cat {file}
Example: cat /etc/test.txt
#more {file} // View a file one screen at a time
Example: more /etc/passwd
10 ) Copy files
#cpExample: cp /etc/passwd /root/passwd
11 ) Rename or move files
#mvExample: mv /etc/testfile /opt/
12) Search for files and text
#find [path] -name [pattern] // Search for files Example: find /etc -name test // Find the folder test somewhere under /etc when you do not know its path.
#grep [pattern] [file-name] //Search for text in a file Example: grep “root” /etc/passwd //find the lines that contain root in the passwd file
13) Edit files
#vi {file}
Example: vi /etc/test.txt
Press I : edit the file
Esc : leave the command but stay in the file
:wq! : save the file and quit
/{text} : search in the file, press N for the next match
#nano {file}
To install nano, run: yum install nano -y
14) Set the time on CentOS
#date // Check the time #yum install ntp -y // Install the NTP service #ntpdate vn.pool.ntp.org // Sync the time for the Vietnam time zone
15) Install / remove / update software
#yum install {software-name} -y // Install software
Example: yum install ntp -y
#yum remove {software-name} -y // Remove software
Example: yum remove ntp -y
#yum update {software-name} -y //Update software
Example: yum update bind -y
or
#rpm -Uvh {file-name.rpm}
Example: rpm -Uvh foo-2.0-1.i386.rpm //Update software without deleting its configuration
#yum update -y // Update the system, including all software
16) Compress and extract folders
Compress a folder or file:
#gzip {file}
Example: gzip /etc/passwd
#tar -cvf {file}
Example: tar -cvf /etc/passwd
Extract a folder or file:
#gunzip /etc/passwd.gz #tar -zxvf /etc/passwd.tar
17) Create and delete users / groups Create and delete users
#useradd {user-name} //Create a user
Example: useradd lmc
#userdel {user name} //Delete a user
Create and delete groups
#groupadd {group-name} //Create a group
Example: groupadd lmcgroup
#groupdel {group-name} // Delete a group
Add a user to a group:
#usermod -g {group-name} {user-name}
Example: usermod -g lmcgroup lmc
18) File permissions Check the permissions of the files in /etc
#cd /etc #ls -l-Linux has 3 permissions: read (r), write (w), execute (x) -And 3 kinds of owners: owner, group owner and others (other owner) -With ls -l, folders start with the letter d, devices with c, block devices with b, and files with nothing Example: drwxr-xr-x. -The 3 permissions also have values: read = 4, write = 2, execute = 1 Example: full permissions = read + write + execute = 4 + 2 + 1 = 7 Set what can be done with a file (read, write, execute):
#chmod {permission-value} {file}
Example: chmod 777 testfile.txt
Change the owner of a file
#chown -R {user-name:group-name} {folder or file}
Example:
chown -R vnitnews testfile.txt
Change the group owner of a file
#chgrp {group-owner} {folder or file }
19) Download software
#yum install wget -y
#wget {url}
Example: wget https://manhchuc.com/lmc.logo
20) Network settings on CentOS
#ifconfig // Check the current network card #ifconfig -a //Check all network cardsTo configure a network card:
#vi /etc/sysconfig/network-scripts/ifcfg-eth0 //File with the network card settingsRestart the network card:
#service network restart21) Boot into another boot menu entry once
CENTOS
echo "savedefault --default=2 --once" | grub --batch
UBUNTU
grub-reboot 4 reboot*Entries are numbered from 0
22) Change the time zone
sudo dpkg-reconfigure tzdata
sudo usermod -a -G jenkins tomcat
chown jenkins:tomcat /opt/tomcat-test/bin/*.*
24) Connect to Wi-Fi on Ubuntu
http://askubuntu.com/questions/412325/automatically-connect-to-a-wireless-network-using-cli
25) Turn off the display and screen blanking on Ubuntu
setpci -s 00:02.0 F4.B=0 setterm -blank 026) Add a user to a group (to get the group permissions)
sudo usermod -aG docker $(whoami)27)To remove apache2 simply type:
28) Config services ubuntu 14.04:sudo update-rc.d -f apache2 removeDoing this will cause all runlevel folders that are linked to apache2 to be removed.
nano /etc/init.d/
The usual process is to amend /etc/network/interfaces (you do know vim or emacs, right?) something like this:Proofread, save and close vim. Restart the interface:Code:auto lo iface lo inet loopback auto wlan0 iface wlan0 inet static address 192.168.1.108 netmask 255.255.255.0 gateway 192.168.1.1 wpa-ssid mylilrouter wpa-psk mysecretkey dns-nameservers 8.8.8.8 192.168.1.1https://askubuntu.com/questions/228304/how-do-i-run-a-script-at-start-upCode:sudo ifdown wlan0 && sudo ifup wlan0
29) Ax OpenVPN Linux
30) Centos vs docker
firewall-cmd --zone=trusted --change-interface=docker0 --permanentfirewall-cmd --zone=trusted --add-masquerade --permanentfirewall-cmd --reload
#init 0 #shutdown -hy -t // Nach einer Wartezeit herunterfahren, in Sekunden (s) #halt #poweroff
2) System neu starten (reboot)
#init 6 #reboot #shutdown -ry 10 // System nach 10 Minuten automatisch neu starten
3) Dateien verknüpfen
Die Datei testfile unter /usr/testfile soll auch im Ordner /usr/test erscheinen
#ln /usr/testfile /user/test #ln <Quelle>Hinweis: Ändert sich die Quelle, ändert sich auch das Ziel<Ziel>
4) Speicherplatz und RAM Speicherplatz:
#df -h //Dateisysteme auflisten #fdisk -l //Partitionen auflistenRAM:
#free -m
5) Aktuellen Ordner anzeigen
#pwd
6) Ordner wechseln
#cd {Ordner}
Beispiel: cd /etc
7) Ordnerinhalt auflisten
#ls [-x / -l -a ] {Ordner}
ls -x // Ordner in mehreren Spalten anzeigen
ls -l // Dateidetails anzeigen
ls -a // alle Dateien anzeigen, auch versteckte
Beispiel: ls -l /etc
8) Ordner anlegen und löschen
#mkdir {Ordner} // Ordner anlegen
Beispiel:
cd /etc
mkdir testfile
#rmdir {Ordner} // Ordner löschen
Beispiel:
cd /etc
rmdir testfile
#rm [-r / -l ] { Ordner / Datei }
rm -r : den Ordner samt Inhalt löschen
rm -l : vor dem Löschen nachfragen
Beispiel:
cd /etc/
rm-rf testfile
9) Textdateien ansehen
#cat {Datei}
Beispiel: cat /etc/test.txt
#more {Datei} // Datei seitenweise ansehen
Beispiel: more /etc/passwd
10 ) Dateien kopieren
#cpBeispiel: cp /etc/passwd /root/passwd
11 ) Dateien umbenennen oder verschieben
#mvBeispiel: mv /etc/testfile /opt/
12) Dateien und Text suchen
#find [Pfad] -name [Suchmuster] // Dateien suchen Beispiel: find /etc -name test // Den Ordner test irgendwo unter /etc finden, wenn der Pfad unbekannt ist.
#grep [Suchmuster] [Dateiname] //Text in einer Datei suchen Beispiel: grep “root” /etc/passwd //Zeilen mit root in der Datei passwd finden
13) Dateien bearbeiten
#vi {Datei}
Beispiel: vi /etc/test.txt
Taste I : Datei bearbeiten
Esc : Befehl verlassen, aber in der Datei bleiben
:wq! : Datei speichern und beenden
/{Text} : in der Datei suchen, N für den nächsten Treffer
#nano {Datei}
nano installieren mit: yum install nano -y
14) Uhrzeit unter CentOS einstellen
#date // Uhrzeit prüfen #yum install ntp -y // NTP-Dienst installieren #ntpdate vn.pool.ntp.org // Uhrzeit für die vietnamesische Zeitzone stellen
15) Software installieren / entfernen / aktualisieren
#yum install {Softwarename} -y // Software installieren
Beispiel: yum install ntp -y
#yum remove {Softwarename} -y // Software entfernen
Beispiel: yum remove ntp -y
#yum update {Softwarename} -y //Software aktualisieren
Beispiel: yum update bind -y
oder
#rpm -Uvh {Dateiname.rpm}
Beispiel: rpm -Uvh foo-2.0-1.i386.rpm //Software aktualisieren, ohne die Konfiguration zu löschen
#yum update -y // System samt aller Software aktualisieren
16) Ordner packen und entpacken
Ordner oder Datei packen:
#gzip {Datei}
Beispiel: gzip /etc/passwd
#tar -cvf {Datei}
Beispiel: tar -cvf /etc/passwd
Ordner oder Datei entpacken:
#gunzip /etc/passwd.gz #tar -zxvf /etc/passwd.tar
17) Benutzer / Gruppen anlegen und löschen Benutzer anlegen und löschen
#useradd {Benutzername} //Benutzer anlegen
Beispiel: useradd lmc
#userdel {Benutzername} //Benutzer löschen
Gruppen anlegen und löschen
#groupadd {Gruppenname} //Gruppe anlegen
Beispiel: groupadd lmcgroup
#groupdel {Gruppenname} // Gruppe löschen
Benutzer einer Gruppe zuweisen:
#usermod -g {Gruppenname} {Benutzername}
Beispiel: usermod -g lmcgroup lmc
18) Dateirechte Rechte der Dateien in /etc prüfen
#cd /etc #ls -l-Linux kennt 3 Rechte: read (r), write (w), execute (x), also Lesen, Schreiben, Ausführen -Und 3 Arten von Besitzern: Besitzer (owner), Besitzergruppe (group owner) und andere (other owner) -Bei ls -l beginnen Ordner mit d, Geräte mit c, Blockgeräte mit b, Dateien ohne Buchstaben Beispiel: drwxr-xr-x. -Die 3 Rechte haben außerdem Werte: read = 4, write = 2, execute = 1 Beispiel: volle Rechte = read + write + execute = 4 + 2 + 1 = 7 Festlegen, was mit einer Datei erlaubt ist (read, write, execute):
#chmod {Rechtewert} {Datei}
Beispiel: chmod 777 testfile.txt
Besitzer einer Datei ändern
#chown -R {Benutzername:Gruppenname} {Ordner oder Datei}
Beispiel:
chown -R vnitnews testfile.txt
Besitzergruppe einer Datei ändern
#chgrp {Besitzergruppe} {Ordner oder Datei }
19) Software herunterladen
#yum install wget -y
#wget {URL}
Beispiel: wget https://manhchuc.com/lmc.logo
20) Netzwerk unter CentOS einrichten
#ifconfig // Aktuelle Netzwerkkarte prüfen #ifconfig -a //Alle Netzwerkkarten prüfenNetzwerkkarte einrichten:
#vi /etc/sysconfig/network-scripts/ifcfg-eth0 //Datei mit den Einstellungen der NetzwerkkarteNetzwerkkarte neu starten:
#service network restart21) Einmalig in einen anderen Bootmenü-Eintrag starten
CENTOS
echo "savedefault --default=2 --once" | grub --batch
UBUNTU
grub-reboot 4 reboot*Die Einträge werden ab 0 gezählt
22) Zeitzone ändern
sudo dpkg-reconfigure tzdata
sudo usermod -a -G jenkins tomcat
chown jenkins:tomcat /opt/tomcat-test/bin/*.*
24) WLAN unter Ubuntu verbinden
http://askubuntu.com/questions/412325/automatically-connect-to-a-wireless-network-using-cli
25) Bildschirm und Bildschirmschoner unter Ubuntu ausschalten
setpci -s 00:02.0 F4.B=0 setterm -blank 026) Benutzer einer Gruppe hinzufügen (um die Rechte der Gruppe zu erhalten)
sudo usermod -aG docker $(whoami)27)To remove apache2 simply type:
28) Config services ubuntu 14.04:sudo update-rc.d -f apache2 removeDoing this will cause all runlevel folders that are linked to apache2 to be removed.
nano /etc/init.d/
The usual process is to amend /etc/network/interfaces (you do know vim or emacs, right?) something like this:Proofread, save and close vim. Restart the interface:Code:auto lo iface lo inet loopback auto wlan0 iface wlan0 inet static address 192.168.1.108 netmask 255.255.255.0 gateway 192.168.1.1 wpa-ssid mylilrouter wpa-psk mysecretkey dns-nameservers 8.8.8.8 192.168.1.1https://askubuntu.com/questions/228304/how-do-i-run-a-script-at-start-upCode:sudo ifdown wlan0 && sudo ifup wlan0
29) Ax OpenVPN Linux
30) Centos vs docker
firewall-cmd --zone=trusted --change-interface=docker0 --permanentfirewall-cmd --zone=trusted --add-masquerade --permanentfirewall-cmd --reload

0 nhận xét:
Đăng nhận xét