gnu/linux - rip tutorial · 2019-01-18 · 26 examples 26 26 26 chroot 27 12: 28 examples 28 ubuntu...
TRANSCRIPT
GNU/Linux
#linux
1
1: GNU / Linux 2
Examples 2
2
2
/ 3
Linux 4
6
6
6
/ 6
/ 7
7
7
7
8
8
8
8
8
9
/ 9
9
9
2: GnuPGGPG 11
11
Examples 11
GnuPG 11
11
3: ls 12
Examples 12
ls 12
ls 13
4: SCP 14
14
Examples 14
14
14
CWD 14
14
14
'-r'scp 14
5: 15
15
15
15
15
Examples 15
stdout 15
15
15
tee 16
6: 'tar' 17
17
Examples 17
17
17
18
18
18
18
7: 19
19
19
Examples 19
19
19
19
19
19
19
19
8: 20
Examples 20
apt 20
pacman 20
pacman 20
yum 20
9: 22
22
Examples 22
Midnight Commander 22
Midnight Commander 22
10: SSH 24
24
Examples 24
24
OpenSSH 24
24
SSH 25
ssh 25
25
11: chroot 26
26
26
Examples 26
26
26
chroot 27
12: 28
Examples 28
Ubuntu 28
28
28
SysV 28
28
28
28
systemd 28
13: 29
Examples 29
29
29
14: Linux 32
32
Examples 32
debian 32
RHEL / CentOS / Fedora 32
systemd 33
Uname - 34
34
34
linuxdebianrpm 34
cat / etc / * 35
GNU coreutils 35
15: 36
36
Examples 36
Arch LinuxLAMP 36
HTTP 36
PHP 37
MySQL 37
UbuntuLAMP 37
CentoOSLAMP 38
Apache Web Server 38
MariaDB Server 38
PHP 38
16: 40
40
Examples 40
40
40
40
17: Linux 42
Examples 42
UbuntuLinux 42
Ubuntu> = 13.04 42
18: 44
44
Examples 44
44
IP 45
DNS 46
DNS 46
46
routeIP 46
ipIP 47
47
19: Linux 48
Examples 48
48
Linux 48
20: 49
49
Examples 49
49
CPU/ 49
50
50
51
CPUI / O 51
51
52
52
52
52
lscpulshw 52
21: 54
54
Examples 54
shell 54
chsh 55
Shell 55
Shell 55
shell 55
56
56
58
You can share this PDF with anyone you feel could benefit from it, downloaded the latest version from: gnu-linux
It is an unofficial and free GNU/Linux ebook created for educational purposes. All the content is extracted from Stack Overflow Documentation, which is written by many hardworking individuals at Stack Overflow. It is neither affiliated with Stack Overflow nor official GNU/Linux.
The content is released under Creative Commons BY-SA, and the list of contributors to each chapter are provided in the credits section at the end of this book. Images may be copyright of their respective owners unless otherwise specified. All trademarks and registered trademarks are the property of their respective company owners.
Use the content presented in this book at your own risk; it is not guaranteed to be correct nor accurate, please send your feedback and corrections to [email protected]
https://riptutorial.com/zh-CN/home 1
1: GNU / Linux
Examples
Enter
echo "Hello World"
Hello World
Linux。。
myFile
touch myFile
myFilemyFirstFile
mv myFile myFirstFile
cat myFirstFile
less myFirstFile
head myFirstFile
tail myFirstFile
vi myFirstFile
ls
myFirstDirectory
mkdir myFirstDirectory
:(srcmyFirstDirectory
mkdir -p src/myFirstDirectory
mv myFirstFile myFirstDirectory/
user@linux-computer:~$ mv myFirstFile secondFileName
https://riptutorial.com/zh-CN/home 2
myFirstDirectory
cd myFirstDirectory
rm myFirstFile
..
cd ..
rmdir myFirstDirectory
/
rm -rf myFirstDirectory
./ not /。
/
ls。
/
l。testsomeFile
user@linux-computer:~$ ls -l
-rw-r--r-- 1 user users 70 Jul 22 13:36 someFile.txt drwxrwxrwx 2 user users 4096 Jul 21 07:18 test
drwxrwxrwx 。d-。rwx。
rwxr w x。-r wx 。
usersomeFile.txt。
sudochmod ### fileName。 r4 w2 x1。test
Owner rwx = 4+2+1 = 7 Group r-x = 4+0+1 = 5 Other r-x = 4+0+1 = 5
chmod 755 test
ls -l
https://riptutorial.com/zh-CN/home 3
drwxr-xr-x 2 user users 4096 Jul 21 07:20 test
l h。
user@linux-computer:~$ ls -lh
total 4166 -rw-r--r-- 1 user users 70 Jul 22 13:36 someFile.txt drwxrwxrwx 2 user users 4.0K Jul 21 07:18 test
a。
user@linux-computer:~$ ls -a
.profile someFile.txt test
s h。
user@linux-computer:~$ ls -s
total 4166 someFile.txt test
testanotherFile R。
user@linux-computer:~$ ls -R
.: someFile.txt test ./test: anotherFile
Linux
Linux。
Linux
man <name> <name>。
man <section> <name> <name>。
man -k <editor> <editor>。
https://riptutorial.com/zh-CN/home 4
man -K <keyword> <keyword>。
apropos <editor> 。。
help Bash shellbash。
help <name> Bash shell<name> bash。
info <name> <name>。
dpkg -l Debian。
dpkg -L packageName Debian。
dpkg -l | grep -i <edit> <edit>.deb。
less /var/lib/dpkg/available 。
whatis vim vim。
<command-name> --help <tool-name>。command -h。
Linux
hostname 。
hostname -f FQDN。
passwd 。
whoami 。
who 。
w 。
last 。
last root root。
lastb 。
chmod - 。
top 。3。q。
https://riptutorial.com/zh-CN/home 5
ps shell
ps -u root root
ps aux
Linuxpresentparent。。
Linux 。。
user@host ~/somedir $ user@host somedir $ user@host /home/user/somedir $
/home/user/somedir 。
Linux ...。
/home/user/somedir cd ../somedir。
pwd 。
cd - 。
cd ~cd 。
cd .. cd..
ls -l long-lls。
ls -ld dir-name dir-name。
ls -a .Linux。
ls -F * / @ =| >。
ls -lt -l。
ls -lh 。
ls -lR 。
tree 。
/
https://riptutorial.com/zh-CN/home 6
cp -p source destination source 。 -p。。
cp -R source_dir destination_dir 。
mv file1 file2 Linux。mvfile1/file2。
rm -i filename 。 LINUXrm -i 。。
rm -R dir-name dir-name 。
rm -rf dir-name dir 。 。
rmdir dir-name dir-name 。。
mkdir dir-name dir-name 。
mkdir -p dir-name/dir-name 。。。
touch filename filename 。
/
chmod <specification> filename
。= u user g group o other + add permission - remove r read w
write x execute。
chmod -R <specification> dir-name 。。
chmod go=+r myfile 。
chmod a +rwx myfile myfile 。
chmod go -r myfile 。
chown owner1 filename owner1 。
chgrp grp_owner filename filenamegroup grp_owner 。
chgrp -R grp_owner dir-name dir-namegrp_owner 。。
POSIXbash sh zsh ksh shell。
GNU / Linux。Linuxshell。 shell。 Bash Bourne Again SHellLinuxshellmacOSshell。
emacsBash
https://riptutorial.com/zh-CN/home 7
Ctrl + Alt + TSuper + T.•
Ctrl + A。•Ctrl + E。•Ctrl + XX。•Alt + F。•Alt + B。•Ctrl + F。•Ctrl + B。•
Ctrl + U。。•Ctrl + K。。•Ctrl + W。•Ctrl + Y。•Alt + T。•Alt + L。•Alt + U。•Alt + C 。•Alt + D。•Alt +。。•Ctrl + T。•
Ctrl + R。•Ctrl + G。•Ctrl + J。•Alt + R。•Ctrl + P。•Ctrl + N。•
Ctrl + Lclear。•
Ctrl + S。。。•Ctrl + QCtrl + S。•
Ctrl + C。•Ctrl + Dshellexitlogout。。•
Ctrl + Zshell。bg。fg。jobs。•
。• 。•
Ctrl + HBackspace。•
Ctrl + JReturn。•
Ctrl + MReturn。•
Ctrl + ITab。•
Ctrl + G。•Ctrl + @Null Character。•
https://riptutorial.com/zh-CN/home 8
Esc DeadkeyAlt。•
Ctrl + Shift + W。•Ctrl + Shift + Q。•
set -o vibashvi。set -o emacsemacs。
/
Linuxshell/。2
find /var/www -name '*.css'
/var/www.css/。
/var/www/html/text-cursor.css /var/www/html/style.css
man find
grep font /var/www/html/style.css
font。
font-weight: bold; font-family: monospace;
grep font /var/www/html/
。
grep: /var/www/html/: Is a directory
-Rgrep
grep -R font /var/www/html/
/var/www/html/admin/index.php: echo '<font color=red><b>Error: no dice</b></font><br/>'; /var/www/html/admin/index.php: echo '<font color=red><b>Error: try again</b></font><br/>'; /var/www/html/style.css: font-weight: bold; /var/www/html/style.css: font-family: monospace;
grep。-h。
https://riptutorial.com/zh-CN/home 9
man grep
GNU / Linux https://riptutorial.com/zh-CN/linux/topic/345/gnu---linux
https://riptutorial.com/zh-CN/home 10
2: GnuPGGPG
GnuPG。 GPGGnuPG。
GnuPGSSHShell。
GnuPG。
Examples
GnuPG
hasgedsudo apt-get install haveged 。
gpg --gen-key gpg --list-keys
pub 2048R/NNNNNNNN 2016-01-01 uid Name <[email protected]> sub 2048R/xxxxxxxx 2016-01-01
gpg --keyserver pgp.mit.edu --send-keys NNNNNNNN
https //www.hackdiary.com/2004/01/18/revoking-a-gpg-key/
。。
gpg —armor —export EMAIL_ADDRESS > public_key.asc
EMAIL_ADDRESS
keys.gnupg.net。
gpg —list-keys
8ID。
gpg —send-keys PRIMARY_ID
PRIMARY_IDID。
。
GnuPGGPG https://riptutorial.com/zh-CN/linux/topic/2533/gnupg-gpg-
https://riptutorial.com/zh-CN/home 11
3: ls
Examples
ls。
ls。 。。。
user@ubuntu14:/usr$ ls bin games include lib lib32 local sbin share src
/。ls -a OR ls -all
user@ubuntu14:/usr$ ls -a . .. bin games include lib lib32 local sbin share src
ls -F OR ls --classify
user@ubuntu14:~$ ls -F bash_profile_course chat_apps/ Desktop/ Downloads/ foxitsoftware/ Public/ test/ bin/ ClionProjects/ Documents/ IDE/ Music/ Pictures/ Templates/ Videos/
。
“/”。
“*”。
“@”。
ls -l
user@ubuntu14:~/example$ ls -l total 6464 -rw-r--r-- 1 dave dave 41 Dec 24 12:19 Z.txt drwxr-xr-x 2 user group 4096 Dec 24 12:00 a_directory -rw-r--r-- 1 user group 6 Dec 24 12:01 a_file lrwxrwxrwx 1 user group 6 Dec 24 12:04 a_link -> a_file -rw-r--r-- 1 user group 6 Dec 24 12:03 a_newer_file -rw-r----- 1 user group 6586816 Dec 24 12:07 big.zip
6460KB。
/。
d - l - 。
https://riptutorial.com/zh-CN/home 12
9。
。
。-h65868166.3M
。
。。
ls
ls -a'。'
ls --color colored list [= always / never / auto]
ls -d list - '* /'
ls -F* / => @ |
ls -i list fileinode
ls -l list with long format -
ls -la list
ls -lh
ls -ls
ls -r
ls -R list
ls -s
ls -S
ls -t
ls -X
ls https://riptutorial.com/zh-CN/linux/topic/5956/ls
https://riptutorial.com/zh-CN/home 13
4: SCPscp [-rv] [-i identity_file] [[user @] host1] file1 ... [[user @] host2] file2•
Examples
# Copy remote file to local dir scp [email protected]:/remote/path/to/foobar.md /local/dest # Copy local file to remote dir scp foobar.md [email protected]:/remote/dest # Key files can be used (just like ssh) scp -i my_key.pem foobar.md [email protected]:/remote/dest
scp。remote_user@some_server.org:/ path / to / file
CWD
scp localfile.txt /home/friend/share/
scp [email protected]:/home/rocky/game/data.txt ./
scp [email protected]:/beacon/light/bitmap.conf [email protected]:/beacon/night/
'-r'scp
scp -r [email protected]:~/project/* ./workspace/
SCP https://riptutorial.com/zh-CN/linux/topic/5960/scp
https://riptutorial.com/zh-CN/home 14
5:
tee - 。
teeTT.
teeFILE。tee。
[] ... [] ......•
-a - 。。
-i - signore-interrupts 。
- 。
- 。
FILE“ - ”tee。
Examples
stdout
stdout。
$ ls
。
$ ls > file
tee。
$ ls | tee file
tee。
crontabcrontab-backup.txt crontabsed。cron。
$ crontab -l | tee crontab-backup.txt | sed 's/old/new/' | crontab –
tee
https://riptutorial.com/zh-CN/home 15
$ ls | tee file1 file2 file3
tee
tee。–atee。
$ ls | tee –a file
https://riptutorial.com/zh-CN/linux/topic/10588/
https://riptutorial.com/zh-CN/home 16
6: 'tar'
-
-c - 。
-x --extract 。
-t --list 。
-f --file = ARCHIVE 。
-v --verbose 。
-
-a --auto-compress 。
-j --bzip2 bzip2。
-J --xz --lzma xz。
-z --gzip gzip。
Examples
tar -cf ./my-archive.tar ./my-folder/
-v
tar -cvf ./my-archive.tar ./my-folder/
'gzip'-z
tar -czf ./my-archive.tar.gz ./my-folder/
-j'bzip2'
tar -cjf ./my-archive.tar.bz2 ./my-folder/
-J'xz'
tar -cJf ./my-archive.tar.xz ./my-folder/
tar -xf archive-name.tar
https://riptutorial.com/zh-CN/home 17
tar -xf archive-name.tar -C ./directory/destination
tar -tvf archive.tar
-t。tar.gz-z
tar -tzvf archive.tar.gz
--exclude。
tar -cf archive.tar ./my-folder/ --exclude="my-folder/sub1" --exclude="my-folder/sub3"
my-folder/ sub1/ sub2/ sub3/
./archive.tar my-folder/ sub2/
--strip-components
--strip-components=NUMBER strip NUMBER leading components from file names on extraction
tar -xf --strip-components=1 archive-name.tar
tar -tf archive.tar.gz Folder-In-Archive/ Folder-In-Archive/file1 Folder-In-Archive/Another-Folder/ Folder-In-Archive/Another-Folder/file2
'tar' https://riptutorial.com/zh-CN/linux/topic/5097/-tar-
https://riptutorial.com/zh-CN/home 18
7:
。。。
•root•
Examples
passwd
root
passwd username
root
useradd username
root
userdel username
root
userdel -r username
groups
idID。
groups username
id usernameID。
https://riptutorial.com/zh-CN/linux/topic/6260/
https://riptutorial.com/zh-CN/home 19
8:
Examples
apt
A dvanced P ackage T ool'apt'DebianSlackwareLinux。
Packages.gz。
sudo apt-get update
。;
sudo apt-get upgrade
DIST dist-upgrade。。
sudo apt-get dist-upgrade
pacman
sudo pacman -S <programName>
sudo pacman -Syu
pacman
pacman -Ss string1 string2 ...
sudo pacman -S package_name1 package_name2 ...
yum
Y ellowU pdaterM DogifiedYellow Dog LinuxRed HatFedoraCentOS。Linuxrpms。
//。
yum search <queryString>
https://riptutorial.com/zh-CN/home 20
。
sudo yum install <packageName>
。;。
sudo yum update
aptyum。
https://riptutorial.com/zh-CN/linux/topic/5703/
https://riptutorial.com/zh-CN/home 21
9:
Midnight Commandermc。。
Examples
Midnight Commander
Midnight Commander。
F1
F2
F3
F4
F5
F6
F7
F8
F9
F10mc
Midnight Commander
F4。
mcedit <filename>
。
F1
F2
F3。。。
F4/
F5/
F6/
F7
F8
https://riptutorial.com/zh-CN/home 22
F9
F10
https://riptutorial.com/zh-CN/linux/topic/9691/
https://riptutorial.com/zh-CN/home 23
10: SSH
shell。 OpenSSHTelnetshell。OpenSSHGNU / Linux。SSHSSH。
Examples
SSH
# ssh -p port user@server-address
port - ssh22。•
user - SSH。•
- IP /。•
。web-servers.com2020usr1SSH。SSH
# ssh -p 2020 [email protected]
。usr1 [email protected] 。
ProxyJump。
# ssh -J [email protected]:2020 [email protected] -p 2222
10.0.0.12020ssh10.0.0.22222ssh。。-JOpenSSH 7.3。
OpenSSH
SSHSSHopenssh
Debian
# apt-get install openssh
Arch Linux
# pacman -S openssh
# yum install openssh
SSH
ssh-keygen [-t rsa | rsa1 | dsa ] [-C <comment>] [-b bits]
https://riptutorial.com/zh-CN/home 24
ssh-keygen -t rsa -b 4096 - C [email protected]
~/.ssh/id_rsa ~/.ssh/id_rsa~/.ssh/id_rsa ~/.ssh/id_rsa.pub 。
man.openbsd.org
SSH
SSH。Linux/etc/ssh/sshd_config
。。
Port (chose a number between 0 - 65535, normaly greater than four digits) PasswordAuthentication yes AllowUsers user1 user2 ...etc
SSH。
ssh
SSHssh
Ubuntu
sudo service ssh stop
Debian
sudo /etc/init.d/ssh stop
Arch Linux
sudo killall sshd
。“”。
id_rsaid_rsa.pub。~/.ssh/authorized_keys。
ssh <user>@<ssh-server> 'cat >> ~/.ssh/authorized_keys' < id_rsa.pub
ssh <user>@<ssh-server> -i id_rsa
SSH https://riptutorial.com/zh-CN/linux/topic/7388/-ssh-
https://riptutorial.com/zh-CN/home 25
11: chroot
rootchroot。。
chroot [] [shell]•
Examples
1.
API
cd /location/of/new/root mount -t proc proc proc/ mount --rbind /sys sys/ mount --rbind /dev dev/ mount --rbind /run run/ (optionally)
2.
chrootDNS
cp /etc/resolv.conf etc/resolv.conf
3.
root/ location / of / new / rootshell/bin/bash
chroot /location/of/new/root /bin/bash
4.
chrootingbash
source /etc/profile source ~/.bashrc
5.
chroot
export PS1="(chroot) $PS1"
6.
chroot
exit
7.
cd / umount --recursive /location/of/new/root
8.
root•LinuxLive CD•chrootuname -m•chrootmodprobe •
https://riptutorial.com/zh-CN/home 26
chroot
root/。
•initramfs•
•••
chroot https://riptutorial.com/zh-CN/linux/topic/10727/-chroot-
https://riptutorial.com/zh-CN/home 27
12:
Examples
Ubuntu
service --status-all
service --status-allservice --status-allSystem V。
+ -。+ - SERVICENAME。
Upstart。sudo initctl listUpstart。Upstart--status-all。
https //askubuntu.com/questions/407075/how-to-read-service-status-all-results
systemctl•systemctl --failed•
SysV
systemctl get-default•systemctl set-default <target-name>•
systemctl start [service-name]•systemctl stop [service-name]•systemctl restart [service-name]•systemctl reload [service-name]•systemctl status [service-name]•
systemctl is-enabled [service-name]•systemctl is-active [service-name]•systemctl enable [service-name]•systemctl disable [service-name]•
systemctl mask [service-name]•systemctl unmask [service-name]•
systemd
systemctl daemon-reload
https://riptutorial.com/zh-CN/linux/topic/6516/
https://riptutorial.com/zh-CN/home 28
13:
Examples
//。
df -h
[root@mail ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup-lv_root 19G 1.6G 16G 9% / tmpfs 245M 0 245M 0% /dev/shm /dev/sda1 485M 47M 413M 11% /boot
/ partition9% 。
df
[root@mail ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/VG-root 1.9T 1.7T 89G 95% / /dev/mapper/VG-var 431G 145G 264G 36% /var devtmpfs 7.8G 204K 7.8G 1% /dev tmpfs 7.8G 4.0K 7.8G 1% /dev/shm /dev/md1 495M 126M 344M 27% /boot ku.example.com:9421 2.5T 487G 2.0T 20% /mnt/test tmpfs 500M 86M 415M 18% /var/ngx_pagespeed_cache
/95%/var36%。
2T/mnt/test /var/ngx_pagespeed_cacheramdisk / tmpfs/var/ngx_pagespeed_cache 。
df -h。
duFILE。
-sh
-s, --summarize display only a total for each argument -h, --human-readable print sizes in human readable format (e.g., 1K 234M 2G)
du -sh *
572K Documents 208M Downloads 4,0K Music 724K Pictures
https://riptutorial.com/zh-CN/home 29
4,0K Public 4,0K Templates 4,0K Videos
du -sh .[!.]* *
6,3M .atom 4,0K .bash_history 4,0K .bash_logout 8,0K .bashrc 350M .cache 195M .config 12K .dbus 4,0K .dmrc 44K .gconf 60K .gem 520K .gimp-2.8 28K .gnome 4,0K .ICEauthority 8,3M .local 8,0K .nano 404K .nv 36K .pki 4,0K .profile 8,0K .ssh 0 .sudo_as_admin_successful 4,0K .Xauthority 4,0K .xsession-errors 4,0K .xsession-errors.old 572K Documents 208M Downloads 4,0K Music 724K Pictures 4,0K Public 4,0K Templates 4,0K Videos
-c
du -sch .[!.]* *
.
.
. 4,0K Templates 4,0K Videos 769M total
du/。Webdu。
sudo du -sch /.[!.]* /*
16K /.VolumeIcon.icns 24K /.VolumeIcon.png 13M /bin
https://riptutorial.com/zh-CN/home 30
57M /boot 4,0K /cdrom 620K /dev 13M /etc 779M /home 0 /initrd.img 406M /lib 3,9M /lib32 4,0K /lib64 16K /lost+found 4,0K /media 4,0K /mnt 367M /opt du: cannot access '/proc/18221/task/18221/fd/4': No such file or directory du: cannot access '/proc/18221/task/18221/fdinfo/4': No such file or directory du: cannot access '/proc/18221/fd/4': No such file or directory du: cannot access '/proc/18221/fdinfo/4': No such file or directory 0 /proc 20K /root du: cannot access '/run/user/1000/gvfs': Permission denied 9,4M /run 13M /sbin 4,0K /srv 0 /sys 72K /tmp 3,5G /usr 639M /var 0 /vmlinuz 5,8G total
。1GB
sudo du --threshold=1G -ch /.[!.]* /*
1,4G /usr/lib 1,8G /usr/share 3,5G /usr 5,8G total
https://riptutorial.com/zh-CN/linux/topic/6650/
https://riptutorial.com/zh-CN/home 31
14: Linux
uname - 。
uname []
•
Examples
debian
lsb_release -a 。
Debian
$ lsb_release -a No LSB modules are available. Distributor ID: Debian Description: Debian GNU/Linux testing (stretch) Release: testing Codename: stretch
Ubuntu
$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 14.04.4 LTS Release: 14.04 Codename: trusty
lsb_release/etc/issue。ubuntu
$ cat /etc/issue Ubuntu 12.04.5 LTS \n \l
/etc/debian_version
DebianFedoraRHELopenSUSE - lsb_release 。
RHEL / CentOS / Fedora
/etc/redhat-release
cat /etc/redhat-release
Fedora 24 Fedora release 24 (Twenty Four)
debianlsb_release -aFedora 24
https://riptutorial.com/zh-CN/home 32
LSB Version: :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch Distributor ID: Fedora Description: Fedora release 24 (Twenty Four) Release: 24 Codename: TwentyFour
systemd
ArchCentOSCoreOSDebianFedoraMageiaopenSUSERed Hat Enterprise LinuxSUSE Linux Enterprise ServerUbuntu。。
/etc/os-release 。NAME VERSION ID VERSION_IDPRETTY_NAME 。
Fedora
NAME=Fedora VERSION="24 (Workstation Edition)" ID=fedora VERSION_ID=24 PRETTY_NAME="Fedora 24 (Workstation Edition)" ANSI_COLOR="0;34" CPE_NAME="cpe:/o:fedoraproject:fedora:24" HOME_URL="https://fedoraproject.org/" BUG_REPORT_URL="https://bugzilla.redhat.com/" REDHAT_BUGZILLA_PRODUCT="Fedora" REDHAT_BUGZILLA_PRODUCT_VERSION=24 REDHAT_SUPPORT_PRODUCT="Fedora" REDHAT_SUPPORT_PRODUCT_VERSION=24 PRIVACY_POLICY_URL=https://fedoraproject.org/wiki/Legal:PrivacyPolicy VARIANT="Workstation Edition" VARIANT_ID=workstation
CentOS
NAME="CentOS Linux" VERSION="7 (Core)" ID="centos" ID_LIKE="rhel fedora" VERSION_ID="7" PRETTY_NAME="CentOS Linux 7 (Core)" ANSI_COLOR="0;31" CPE_NAME="cpe:/o:centos:centos:7" HOME_URL="https://www.centos.org/" BUG_REPORT_URL="https://bugs.centos.org/" CENTOS_MANTISBT_PROJECT="CentOS-7" CENTOS_MANTISBT_PROJECT_VERSION="7" REDHAT_SUPPORT_PRODUCT="centos" REDHAT_SUPPORT_PRODUCT_VERSION="7"
freedesktop ; - systemd。
bash shell/etc/os-release
https://riptutorial.com/zh-CN/home 33
$ ( source /etc/os-release && echo "$PRETTY_NAME" ) Fedora 24 (Workstation Edition)
Uname -
Unameu nix 。uname。
uname [OPTION]
OPTION uname-s。
-a--all - -p-i 。
> uname -a SunOS hope 5.7 Generic_106541-08 sun4m sparc SUNW,SPARCstation-10
-s - kernel-name 。
-n - nodename 。
-r - kernel-release 。
-v - kernel-version 。
-m - 。
-p - “ ”。
-i - “ ”。
-o - 。
- 。
- 。
uname -a 。
Arch
$ uname -a Linux nokia 4.6.4-1-ARCH #1 SMP PREEMPT Mon Jul 11 19:12:32 CEST 2016 x86_64 GNU/Linuxenter code here
linuxdebianrpm
https://riptutorial.com/zh-CN/home 34
Linux/ etc / lsb-releasedebian/ etc / redhat-releaseRPM。DebianRPMLinux MintCent-Os。
Ubuntu
cat / etc / *
DISTRIB_ID = Ubuntu DISTRIB_RELEASE = 14.04 DISTRIB_CODENAME = trusty DISTRIB_DESCRIPTION =“Ubuntu 14.04 LTS”
GNU coreutils
GNU coreutilsLinux。
。
`$ uname -a
......
`Linux Scibearspace 3.16.0-4-amd641 SMP Debian 3.16.7-ckt25-2 + deb8u32016-07-02x86_64 GNU / Linux
Scibearspace
Scibearspace•3.16.0-4-amd64•SMP Debian 3.16.7-CKT25-2 + deb8u33.16debian•debian 83。•
RHELSuSe。
Linux https://riptutorial.com/zh-CN/linux/topic/872/linux
https://riptutorial.com/zh-CN/home 35
15: LAMP L inux A pache M ySQL P HPLinuxApache HTTP ServerWebMySQLRDBMSDB D ata B asePHPBack End。
LAMPWeb。WindowsWAMP W indows A pache M ySQL P HP
Examples
Arch LinuxLAMP
pacman -Syu apache php php-apache mariadb
HTTP/etc/httpd/conf/httpd.conf
ServerAdmin [email protected] 。
WEBServerRoot "/etc/httpd" 。
<Directory "/etc/httpd">
chmod o+x /etc/httpd
AllowOverride from none (default) to AllAllowOverride from none (default) to All.htaccess。
~/public_html。 http// localhost / yourusername / 。
Include conf/extra/httpd-userdir.conf
root~/public_html755。
chmod 755 /home chmod 755 /home/username chmod 755 /home/username/public_html
SSL
LoadModule ssl_module modules/mod_ssl.so
Include conf/extra/httpd-vhosts.conf
/etc/httpd/conf/extra/httpd-vhosts.conf。 /etc/hosts
/etc/httpd/conf/extra/httpd-default.confServerSignatureOffServerTokenProd
https://riptutorial.com/zh-CN/home 36
PHP
/etc/httpd/conf/httpd.conf
LoadModule mpm_event_module modules/mod_mpm_event.so
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
LoadModuleLoadModule php7_module modules/libphp7.so
Include conf/extra/php7_module.conf
/etc/php/php.ini
extension=mysqli.soextension=pdo_mysql.so
date.timezone = America/Argentina/Buenos_Aires, date.default_latitude = 0.0, date.default_longitude = 0.0
MySQL
root
mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
MySQL。
MySQL
systemctl enable mysqld systemctl start mysqld
sh /usr/bin/mysql_secure_installation
Web。
UbuntuLAMP
apache
sudo apt-get install apache2
MySql
sudo apt-get install mysql-server
PHP
sudo apt-get install php5 libapache2-mod-php5
https://riptutorial.com/zh-CN/home 37
sudo systemctl restart apache2
PHP
php -r 'echo "\n\nYour PHP installation is working fine.\n\n\n";'
CentoOSLAMP
Apache Web Server
WebApache。
sudo yum -y install httpd
Apache Web。
sudo systemctl enable --now httpd
HTTP//
Apache Web。
MariaDB Server
MariaDB
sudo yum -y install mariadb-server
MariaDB
sudo systemctl enable --now mariadb
mysql_secure_installation。
root•••
PHP
sudo yum -y install php php-common
Apachehttpd。
sudo systemctl restart httpd
PHP/ var / www / htmlindex.php。
HTTP//localhost/index.php
https://riptutorial.com/zh-CN/home 38
。php
php --version
PHP 5.4.16 (cli) (built: Nov 6 2016 00:29:02) Copyright (c) 1997-2013 The PHP Group
PHP。Web。
https://riptutorial.com/zh-CN/linux/topic/6573/
https://riptutorial.com/zh-CN/home 39
16:
systemdUbuntuservice <name> [start|stop|status]systemctl [start|stop|status] <name> 。
Examples
System-VinitRHEL / CentOS 6
service <service> start
service <service> stop
systemdUbuntu> = 15.04RHEL / CentOS> = 7
systemctl <service> dnsmasq
systemctl <service> dnsmasq
System-VinitRHEL / CentOS 6
service <service> status
systemdUbuntu> = 15.04RHEL / CentOS> = 7.0
systemctl status <service>
systemdFedora => 15Ubuntu> = 15.04RHEL / CentOS> = 7
systemctl status [servicename]
... [servicename]; systemctl status sshd 。
。
journalctl。 journalctl -xe1000less 。journalctl -f 。
-t
journalctl -f -t sshd
-p -p warnings- -b“” -S“” -
journalctl -p err -S yesterday
。
journalctltail。-f “”。
tail -f /var/log/messages
tail -f /var/log/secure
https://riptutorial.com/zh-CN/home 40
auditd linux auditing/var/log/audit/ 。/var/log/messages/var/log/messages/var/log/
https://riptutorial.com/zh-CN/linux/topic/4809/
https://riptutorial.com/zh-CN/home 41
17: Linux
Examples
UbuntuLinux
15 GB。
Ubuntu> = 13.04
AGit
Ubuntugit。Kernel Git Guide。 git
fakeroot debian/rules clean
B
- Ubuntu。follow
sudo apt-get build-dep linux-image-`uname -r`1.
C
Ubuntu。
kernel.org。1.
cd
tar xf linux-*.tar.xz cd linux-*
2.
ncurses
make menuconfig
3.
→< Exit > 。4.
Return。5.
make
make
-j n。
6.
https://riptutorial.com/zh-CN/home 42
arch/[arch]/boot/bzImage [arch]uname -a 。
Linux https://riptutorial.com/zh-CN/linux/topic/379/linux
https://riptutorial.com/zh-CN/home 43
18:
TCP / IP。 Linux。。NICeth0eth1。
Examples
IFCONFIG
$ ifconfig -a
$ ifconfig <interface>
$ ifconfig eth0 eth0 Link encap:Ethernet HWaddr xx:xx:xx:xx:xx:xx inet addr:x.x.x.x Bcast:x.x.x.x Mask:x.x.x.x inet6 addr: xxxx::xxx:xxxx:xxxx:xxxx/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:4426618 errors:0 dropped:1124 overruns:0 frame:0 TX packets:189171 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:382611580 (382.6 MB) TX bytes:36923665 (36.9 MB) Interrupt:16 Memory:fb5e0000-fb600000
Ethtool -
$ ethtool <interface>
$ ethtool eth0 Settings for eth0: Supported ports: [ TP ] Supported link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Full Supported pause frame use: No Supports auto-negotiation: Yes Advertised link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Full Advertised pause frame use: No Advertised auto-negotiation: Yes Speed: 1000Mb/s Duplex: Full Port: Twisted Pair PHYAD: 1 Transceiver: internal Auto-negotiation: on MDI-X: on (auto) Supports Wake-on: pumbg Wake-on: g Current message level: 0x00000007 (7) drv probe link Link detected: yes
https://riptutorial.com/zh-CN/home 44
ip - /
$ ip { link | ... | route | macsec } man ip
$ ip link show
eth0wan
$ ip link set dev eth0 name wan
eth0
$ ip link set dev eth0 up
$ ip addr show
delip255.255.255.0
$ ip addr add 1.2.3.4/24 brd + dev eth0
IP
DHCPIP
DHCPDHCPdhclientIP
$ dhclient <interface>
/etc/network/interfacesDHCP IP
auto eth0 iface eth0 inet dhcp
/etc/network/interfaces
/etc/network/interfaces。
auto eth0 # Bring up the interface on boot iface eth0 inet static address 10.10.70.10 netmask 255.255.0.0 gateway 10.10.1.1 dns-nameservers 10.10.1.20 dns-nameservers 10.10.1.30
。
https://riptutorial.com/zh-CN/home 45
ifconfig
ifconfigIP
$ ifconfig <interface> <ip-address>/<mask> up
$ ifconfig eth0 10.10.50.100/16 up
DNS
/etc/hostsDNS
127.0.0.1 your-node-name.your-domain.com localhost.localdomain localhost XXX.XXX.XXX.XXX node-name
hostsRFC 952
DNS
/etc/resolv.confDNS
nameserver 8.8.8.8 # IP address of the primary name server nameserver 8.8.4.4 # IP address of the secondary name server
DNSdigDNS
$ dig google.com @your.dns.server.com +short
routeIP$ route # Displays list or routes and also resolves host names $ route -n # Displays list of routes without resolving host names for faster results
/
adddel
-host xxxx IP
-net xxxx
gw xxxx
netmask xxxx
default
$ route add -host xxxx eth1•$ route add -net 2.2.2.0 netmask 255.255.255.0 eth0•
•
https://riptutorial.com/zh-CN/home 46
cidrroute add -net 2.2.2.0/24 eth0route add -net 2.2.2.0/24 eth0$ route add default gw 2.2.2.1 eth0•$ route del -net 2.2.2.0/24•
ipIP$ ip route show # List routing table
/
adddelchangeappendreplace
showflush
restore stdin
get
$ ip route add default via 1.2.3.2541.2.3.254 $ ip route add default via 1.2.3.254•192.168.1.1eth0 $ ip route add default via 192.168.1.1 dev eth0•
LinuxmacOS<hostname>IP。
。/ etc / hosts。
IP<ip_rem> 1. 2.
<hostname> 。3.
•
。/ .hosts---。。 。•
cat Unix。IP192.168.1.44PCping remote_pcIP。shell
$ sudo cat 192.168.1.44 remote_pc
ping
$ ping remote_pc
https://riptutorial.com/zh-CN/linux/topic/8206/
https://riptutorial.com/zh-CN/home 47
19: Linux
Examples
-a / - all。
$uname -a Linux hostname 3.13.0-88-generic #135-Ubuntu SMP Wed Jun 8 21:10:42 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
。
。
Linux。
uname。
uname -a Linux df1-ws-5084 4.4.0-64-generic85-Ubuntu SMP Mon Feb 20 11:50:30 UTC 2017 x86_64 x86_64 x86_64 GNU / Linux
uname [OPTION] ...。OPTION-s。
-a - allomit -p-i if unknown-s - kernel-name-n - nnameamehostname -r - kernel-release-v - kernel-version-m - -p - -i - -o - - --version
Linux https://riptutorial.com/zh-CN/linux/topic/6041/linux
https://riptutorial.com/zh-CN/home 48
20:
。
Examples
Ubuntu
lshw。CPU。
$ sudo lshw | less (or more) $ sudo lshw -html > myhardware.html $ sudo lshw -xml > myhardware.xml
PCI
$ lspci -tv
USB
$ lsusb -tv
BIOS
$ dmidecode -q | less
sda
$ hdparm -i /dev/sda
/
$ smartctl -A /dev/sda | grep Power_On_Hours # How long has this disk (system) been powered on in total $ hdparm -tT /dev/sda # Do a read speed test on disk sda $ badblocks -s /dev/sda # Test for unreadable blocks on disk sda
CPU/
Ubuntu
$ cat /proc/cpuinfo
processor : 0 vendor_id : GenuineIntel cpu family : 6
https://riptutorial.com/zh-CN/home 49
model : 15 model name : Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz stepping : 11 cpu MHz : 1596.000 cache size : 4096 KB physical id : 0 siblings : 4 core id : 0 cpu cores : 4 apicid : 0 initial apicid : 0 fpu : yes fpu_exception : yes cpuid level : 10 wp : yes flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx lm constant_tsc arch_perfmon pebs bts rep_good pni dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm lahf_lm tpr_shadow vnmi flexpriority bogomips : 4800.18 clflush size : 64 cache_alignment : 64 address sizes : 36 bits physical, 48 bits virtual power management: .... .. processor : 3 vendor_id : GenuineIntel cpu family : 6 model : 15 model name : Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz stepping : 11 cpu MHz : 1596.000 cache size : 4096 KB physical id : 0 siblings : 4 core id : 3 cpu cores : 4 apicid : 3 initial apicid : 3 fpu : yes fpu_exception : yes cpuid level : 10 wp : yes flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx lm constant_tsc arch_perfmon pebs bts rep_good pni dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm lahf_lm tpr_shadow vnmi flexpriority bogomips : 4800.30 clflush size : 64 cache_alignment : 64 address sizes : 36 bits physical, 48 bits virtual power management:
$ grep -c processor /proc/cpuinfo
linux
https://riptutorial.com/zh-CN/home 50
ps PID。
。
$ ps -e -o pid,args --forest
cpu
$ ps -e -o pcpu,cpu,nice,state,cputime,args --sort pcpu | sed '/^ 0.0 /d'
memKB。
$ ps -e -orss=,args= | sort -b -k1,1n | pr -TW$COLUMNS
“firefox-bin”
$ ps -C firefox-bin -L -o pid,tid,pcpu,state
lsofID
$ lsof -p $$
$ lsof ~
$ top
ps。
top
$ htop -d 5
$ atop
atop600iotopiftop
$ sudo iotop
CPUI / O
Linuxstat
mpstat
https://riptutorial.com/zh-CN/home 51
$ mpstat 2 10
freeRAMI / O
$ vmstat 2 10
iostat 。
$ iostat -kx 2
netstat
$ netstat -ntlp # open TCP sockets $ netstat -nulp # open UDP sockets $ netstat -nxlp # open Unix sockets
$ sudo iftop
I / Odstat 。vmstat iostatifstat
lscpulshw
lscpulscpuCPU。
$ lscpu Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 4 On-line CPU(s) list: 0-3 Thread(s) per core: 1 Core(s) per socket: 4 Socket(s): 1 NUMA node(s): 1 Vendor ID: GenuineIntel CPU family: 6 Model: 23 Stepping: 10 CPU MHz: 1998.000 BogoMIPS: 5303.14 Virtualization: VT-x L1d cache: 32K L1i cache: 32K L2 cache: 2048K NUMA node0 CPU(s): 0-3
https://riptutorial.com/zh-CN/home 52
lshw
$ lshw | grep cpu df1-ws-5084 description: Computer width: 64 bits capabilities: vsyscall32 *-core description: Motherboard physical id: 0 *-memory description: System memory physical id: 0 size: 5881MiB *-cpu product: Intel(R) Pentium(R) CPU G3220 @ 3.00GHz vendor: Intel Corp. physical id: 1 bus info: cpu@0 size: 3GHz capacity: 3GHz width: 64 bits
https://riptutorial.com/zh-CN/linux/topic/8932/
https://riptutorial.com/zh-CN/home 53
21:
shell。shell。lsshellls/shell。。 shellCLI。
Examples
shell
BASH B ourne A gain SH ellshell。
LinuxshellELFchsh ch ange sh ell。
chsh -lshell
[user@localhost ~]$ chsh -l /bin/sh /bin/bash /sbin/nologin /usr/bin/sh /usr/bin/bash /usr/sbin/nologin /usr/bin/fish
Linux chsh -l。/ etc / shellsshell。cat
[user@localhost ~]$ cat /etc/shells # /etc/shells: valid login shells /bin/sh /bin/bash /sbin/nologin /usr/bin/sh /usr/bin/bash /usr/sbin/nologin /usr/bin/fish
shellfish chsh -s
[user@localhost ~]$ chsh -s /usr/bin/fish Changing shell for user. Password: Shell changed.
shell。
shellrootchsh。user_2shellfishchsh -s /usr/bin/fish user_2 。
shell$SHELLshell
~ echo $SHELL /usr/bin/fish
https://riptutorial.com/zh-CN/home 54
chsh
-s shell
shellshell。
-l - --list-shells
/ etc / shellsshell。
-h - --help
。
-v - --version
。
Shell
Shell
。。PS1。。 PS1shell。 user@host ~ $ bruce@gotham ~ $ 。
PS1 ='\ w $' ~ $ shell。Root。
PS1 ='\ h $' gotham $ shell
PS1 ='\ u $' bruce $ shell
PS1 ='\ t $' 22:37:31 $ shell24
PS1 ='@ $' 10:37 PM shell12
PS1 =' $'' 732shell
PS1 ='dude $' dude $shell
shell
Ctrl-k /
Ctrl-y /
Ctrl-a
https://riptutorial.com/zh-CN/home 55
Ctrl-e
Ctrl-d
Ctrl-l /
Ctrl-u
Ctrl-_
Ctrl-c //
Ctrl-r
~/.bash_history shell500/
history
history | grep <key-word> <key-word>
bash。
.bash_aliases。
alias command_alias='actual_command'
actual_command command_alias。
alias install='sudo apt-get -y install'
alias installsudo apt-get -y install 。bashsudo apt-get -y install 。
bashlocate。mykey.pem
locate mykey.pem
random7897_mykey_0fidw.pem。mykeypem。locategrep
locate pem | grep mykey
。
locate。 locate。updatedb。
locate find
find / -name mykey.pem -print
locate mykey.pem。。 find。
https://riptutorial.com/zh-CN/home 56
https://riptutorial.com/zh-CN/linux/topic/2731/
https://riptutorial.com/zh-CN/home 57
S. No
Contributors
1 GNU / Linux
7heo.tk, Ajay Sangale, annaken, Armali, caped114, colelemonz, Community, Daniel Käfer, depperm, e.dan, EsmaeelE, Jarryd, Jensd, karel, KerDam, likewhoa, Mateusz Piotrowski, Mike P, mnoronha, Mohammad, Naveen Chakravarthy, Nikhil Raj, Paradox, Rubio, Sudip Bhandari, sudo, tedm1106, Tejus Prasad, TiansHUo, Todd, user, vishram0709, Whoami, Zumo de Vidrio
2 GnuPGGPG Aaron Skomra, BrightOne, Paradox, v7d8dpo4
3 ls foxtrot9, parkydr, Philip Kirkbride
4 SCP manav m-n, Riley Guerin
5 BrightOne, kuldeep mishra
6 'tar' Baard Kopperud, embedded, Marsso, Not22
7 geek1011, mattdm
8 Paradox, Philip Kirkbride, Rubio
9 user
10 SSHAnagh Hegde, BrightOne, C.W.Holeman II, EsmaeelE, Filipe, Manuel, Rajesh Rengaraj, Todd, user
11 chroot BrightOne
12 Ajay Sangale, Anagh Hegde, BrightOne, Federico Ponzi, leeor
13 mertyildiran, zyio
14 LinuxAni Menon, DaveM, fedorqui, lardenn, lcipriani, mattdm, Neil, Nikhil Raj, Sergey Stolyarov, Teddy
15Arden Shackelford, EsmaeelE, FOP, Nhan, Philip Kirkbride, S.Rohit
16 Flamewires, mattdm
17 Linux Léo Léopold Hertz , Nathan Osman
18 ctafur, Kiran Vemuri, Y4Rv1K
19 Linux fdeslaur, S.Rohit
https://riptutorial.com/zh-CN/home 58
20 christian x, Deepak K M, Kiran Vemuri, S.Rohit, Y4Rv1K
21Anagh Hegde, Ani Menon, Arden Shackelford, caped114, Emmanuel Mathi-Amorim, Jahid, Jensd, lardenn, oznek, Paradox, Philip Kirkbride, Quaker, Rubio, Samuel L., user
https://riptutorial.com/zh-CN/home 59