Linux第二天 基础命令及软件安装

提兵百万西湖上,立马吴山第一峰!这篇文章主要讲述Linux第二天 基础命令及软件安装相关的知识,希望能为你提供帮助。
?基础命令?


  • ??增、删、改、查?
查询:查看目录下有什么 ,查看文件中的内容
ls、cat、more、less、man

创建:创建文件 创建目录
##创建文件
touch 文件名
echo hello > 文件名

##创建目录
mkdir 目录名

改:剪切和复制
mv 重命名和剪切移动文件
cp 复制拷贝文件
符号链接ln -s 绝对路径源文件 建立链接文件绝对路径
例如:ln -s /usr/src/Aba.txt /home/admin/Des

删除:
rm -f 文件 强制删除文件
rm -rf 递归删除 强制删除目录以及目录下文件

  • 获取命令帮助
manhelp--help
/+内容##在显示信息中查询内容

  • ls
-a 显示隐藏文件
-l 显示文件的详细信息
-lh 显示文件大小 (du -sh 目录 显示目录大小)
-R 递归显示目录中的子目录的内容
ls|grep "过滤内容" 过滤
内部命令 命令解释器自带的命令 help cd
外部命令 安装的第三方软件带的命令 基本都有帮助手册

  • dd拷贝或转换文件
示例:/tmp 目录中建立一个大小位 100m 的文件
[root@bobi tmp]# dd if=/dev/zero of=/tmp/bigfile bs=1M count=100
100+0 records in
100+0 records out
104857600 bytes (105 MB) copied, 0.397239 s, 264 MB/s
[root@bobi tmp]# ll -h /tmp/bigfile
-rw-r--r-- 1 root root 100M Apr3 14:51 /tmp/bigfile

  • 解压缩
-z gzip    -j bzip2
-x 解包   -c 压包   -C 指定解包位置
压缩
tar zcf /tmp/bigfile.tar.gz ./allfile
tar jcf /tmp/bigfile.tar.bz2 ./allfile
[root@bobi tmp]# tar zcf /tmp/bigfile.tar.gz ./bigfile
[root@bobi tmp]# ls
ababatmpvmware-root_955-3988228421
bigfilevmware-root_50225-2909161691vmware-root_963-4256545027
bigfile.tar.gzvmware-root_50263-3178002564yum.log
ks-script-DZ0OfEvmware-root_6282-726370616
[root@bobi tmp]# tar tf bigfile.tar.gz
./bigfile

[root@bobi tmp]# tar jcf /tmp/bigfile.tar.bz2 ./bigfile
[root@bobi tmp]# ls
ababaks-script-DZ0OfEvmware-root_6282-726370616
bigfiletmpvmware-root_955-3988228421
bigfile.tar.bz2vmware-root_50225-2909161691vmware-root_963-4256545027
bigfile.tar.gzvmware-root_50263-3178002564yum.log

?解?压
tar xf /tmp/bigfile.bar.gz -C /root
tar xf /tmp/bigfile.bar.bz2 -C /root
[root@bobi tmp]# rm -fr bigfile
[root@bobi tmp]# ls
ababatmpvmware-root_955-3988228421
bigfile.tar.bz2vmware-root_50225-2909161691vmware-root_963-4256545027
bigfile.tar.gzvmware-root_50263-3178002564yum.log
ks-script-DZ0OfEvmware-root_6282-726370616

[root@bobi tmp]# tar xf bigfile.tar.gz
[root@bobi tmp]# ls
ababaks-script-DZ0OfEvmware-root_6282-726370616
bigfiletmpvmware-root_955-3988228421
bigfile.tar.bz2vmware-root_50225-2909161691vmware-root_963-4256545027
bigfile.tar.gzvmware-root_50263-3178002564yum.log

[root@bobi tmp]# rm -fr bigfile

[root@bobi tmp]# tar xf bigfile.tar.bz2
[root@bobi tmp]# ls
ababaks-script-DZ0OfEvmware-root_6282-726370616
bigfiletmpvmware-root_955-3988228421
bigfile.tar.bz2vmware-root_50225-2909161691vmware-root_963-4256545027
bigfile.tar.gzvmware-root_50263-3178002564yum.log

[root@bobi tmp]# tar xf bigfile.tar.bz2 -C /tmp/ababa/
[root@bobi tmp]# cd ababa
[root@bobi ababa]# ls
1.txtbigfile

查看包里的内容
tar tf bigfile.tar.gz    
[root@bobi tmp]# tar tf bigfile.tar.gz
./bigfile

  • vim
分三种工作模式
vim /tmp/test.txt 进入命令模式

末行模式 :


:wq
保存并退出
:q!
不保存退出
:set nu
显示行号
:%s#old#new#g
每一行中的 old 替换成 new
:50,56d
删除 50-56 行的数据
命令模式有非常多的快速编辑快捷键
2yy
复制当前行及下一行
p
粘贴到当前行下
dd
删除当前行
gg
回到第一行
G
到最后一行
50gg
快速跳转至第 50 行
i a
从命令模式进入输入模式
/ < word>
从光标位置向后查找
? < word>
从光标位置向前查找












?软件安装?
分类
  • 源码包的安装
GUN 社区或 Github 社区
特点:
1. 以压缩包的形式提供给用户
2. 开源 源代码公开,不收费
安装事项:
(解压位置:/usr/src        安装位置:/usr/local)
1、上传源码包到系统
rz -be
[root@bobi ~]# rz -be
rz waiting to receive.
?aê? zmodem ′?ê??£°′ Ctrl+C è????£
100%9498 KB 9498 KB/s 00:00:010 Errors

[root@bobi ~]# ls
anaconda-ks.cfghttpd-2.4.53.tar.gz


2、解压源码包到指定的位置: /usr/src/
[root@bobi ~]# tar xf httpd-2.4.53.tar.gz -C /usr/src/
[root@bobi ~]#
[root@bobi ~]# cd /usr/src/
[root@bobi src]# ls
debughttpd-2.4.53kernels

3、?进入解压路径了解软件的作用以及安装方法?
[root@bobi src]# cd httpd-2.4.53/
[root@bobi httpd-2.4.53]# ls
ABOUT_APACHELICENSEVERSIONINGdocsmodules
Apache-apr2.dswMakefile.inacinclude.m4emacs-styleos
Apache.dswMakefile.winap.dhttpd.depserver
BuildAll.dspNOTICEapache_probes.dhttpd.dspsrclib
BuildBin.dspNWGNUmakefilebuildhttpd.maksupport
CHANGESREADMEbuildconfhttpd.spectest
CMakeLists.txtREADME.CHANGESchanges-entriesinclude
INSTALLREADME.cmakeconfig.layoutlibhttpd.dep
InstallBin.dspREADME.platformsconfigurelibhttpd.dsp
LAYOUTROADMAPconfigure.inlibhttpd.mak

4、?查看 README 文件:?
【Linux第二天 基础命令及软件安装】?了解?服务软件 协议 版本官网 官方路径手册所在位置
?5、查看 INSTALL 文件:?
      $ ./configure --prefix=PREFIX(文件夹)  检查编译环境
    $ make      产生编译文件
    $ make install        安装编译文件
    $ PREFIX/bin/apachectl start        开启服务
?6、检查apache编译环境?
?./configure --prefix=/usr/local/httpd?
[root@bobi httpd-2.4.53]# ./configure --prefix=/usr/local/httpd
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
configure:
configure: Configuring Apache Portable Runtime library...
configure:
checking for APR... no
configure: error: APR not found.Please read the documentation.

发现报错:configure: error: APR not found.   Please read the documentation.(缺ARP编译环境)
百度搜索报错信息,解决办法:

下载3个安装包:
Apr 及 apr-util: https://apr.apache.org/download.cgi
Pcre下载 : https://sourceforge.net/projects/pcre/

  • 上传APR包到系统:
[root@bobi ~]# rz -be
rz waiting to receive.
?aê? zmodem ′?ê??£°′ Ctrl+C è????£
100%1068 KB 1068 KB/s 00:00:010 Errors
[root@bobi ~]# ls
anaconda-ks.cfgapr-1.7.0.tar.gzhttpd-2.4.53.tar.gz


  • 解压
[root@bobi ~]# tar xf apr-1.7.0.tar.gz -C /usr/src/
[root@bobi ~]#
[root@bobi ~]# cd /usr/src/
[root@bobi src]# ls
apr-1.7.0debughttpd-2.4.53kernels

  • 检查apr编译环境
./configure --prefix=/usr/local/apr
[root@bobi src]# cd apr-1.7.0/
[root@bobi apr-1.7.0]# ./configure --prefix=/usr/local/apr
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
Configuring APR library
...
config.status: executing libtool commands
rm: cannot remove libtoolT: No such file or directory
config.status: executing default commands

发现报错:rm: cannot remove libtoolT: No such file or directory
百度搜索报错信息,解决办法:

[root@bobi apr-1.7.0]#yum install libtool
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Determining fastest mirrors
...
(2/3): updates/7/x86_64/primary_db|14 MB00:02
(3/3): epel/x86_64/primary_db| 7.0 MB00:02
Package libtool-2.4.2-22.el7_3.x86_64 already installed and latest version
Nothing to do

[root@bobi apr-1.7.0]# ./configure --prefix=/usr/local/apr
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
Configuring APR library
...
config.status: executing default commands
config.status: include/apr.h is unchanged
config.status: include/arch/unix/apr_private.h is unchanged

  • 产生编译文件
[root@bobi apr-1.7.0]# make
make[1]: Entering directory `/usr/src/apr-1.7.0
/bin/sh /usr/src/apr-1.7.0/libtool --silent --mode=compile gcc -g -O2 -pthread-DHAVE_CONFIG_H-DLINUX -D_REENTRANT -D_GNU_SOURCE-I./include -I/usr/src/apr-1.7.0/include/arch/unix -I./include/arch/unix -I/usr/src/apr-1.7.0/include/arch/unix -I/usr/src/apr-1.7.0/include -I/usr/src/apr-1.7.0/include/private -I/usr/src/apr-1.7.0/include/private-o encoding/apr_encode.lo -c encoding/apr_encode.c & & touch encoding/apr_encode.lo
...
sed -e s,^\\(apr_build.*=\\).*$,\\1/usr/local/apr/build-1, -e s,^\\(top_build.*=\\).*$,\\1/usr/local/apr/build-1, < build/apr_rules.mk > build/apr_rules.out
make[1]: Leaving directory `/usr/src/apr-1.7.0

  • 安装编译文件
[root@bobi apr-1.7.0]# make install
make[1]: Entering directory `/usr/src/apr-1.7.0
make[1]: Nothing to be done for `local-all.
make[1]: Leaving directory `/usr/src/apr-1.7.0
...
/usr/bin/install -c -m 644 build/apr_rules.out /usr/local/apr/build-1/apr_rules.mk
/usr/bin/install -c -m 755 apr-config.out /usr/local/apr/bin/apr-1-config

  • 检查编译文件
[root@bobi apr-1.7.0]# cd /usr/local/
[root@bobi local]# ls
aprbinetcgamesincludeliblib64libexecsbinsharesrc
[root@bobi local]# cd apr/
[root@bobi apr]# ls
binbuild-1includelib

APR包安装成功
7、继续检查apache的编译环境
./configure --prefix=/usr/local/httpd
[root@bobi apr]# cd /usr/src/httpd-2.4.53/
[root@bobi httpd-2.4.53]# ./configure --prefix=/usr/local/httpd
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
configure:
configure: Configuring Apache Portable Runtime library...
configure:
checking for APR... yes
setting CC to "gcc"
setting CPP to "gcc -E"
setting CFLAGS to " -g -O2 -pthread"
setting CPPFLAGS to " -DLINUX -D_REENTRANT -D_GNU_SOURCE"
setting LDFLAGS to " "
configure:
configure: Configuring Apache Portable Runtime Utility library...
configure:
checking for APR-util... no
configure: error: APR-util not found.Please read the documentation.

发现报错:configure: error: APR-util not found.   Please read the documentation.(缺少APR-util编译环境)
百度搜索报错信息,解决办法:
  • 上传APR-util包到系统:
[root@bobi ~]# rz -be
rz waiting to receive.
?aê? zmodem ′?ê??£°′ Ctrl+C è????£
100%541 KB541 KB/s 00:00:010 Errors

[root@bobi ~]# ls
anaconda-ks.cfgapr-1.7.0.tar.gzapr-util-1.6.1.tar.gzhttpd-2.4.53.tar.gz

  • 解压
[root@bobi ~]# tar xf apr-util-1.6.1.tar.gz -C /usr/src/
[root@bobi ~]# cd /usr/src/
[root@bobi src]# ls
apr-1.7.0apr-util-1.6.1debughttpd-2.4.53kernels
[root@bobi src]# cd apr-util-1.6.1/
[root@bobi apr-util-1.6.1]# ls
CHANGESaprutil.depconfigure.inlibaprutil.mak
CMakeLists.txtaprutil.dspcryptolibaprutil.rc
LICENSEaprutil.dswdbdmemcache
Makefile.inaprutil.makdbmmisc
Makefile.winapu-config.indocsredis
NOTICEbucketsencodingrenames_pending
NWGNUmakefilebuildexport_vars.sh.instrmatch
READMEbuild-outputs.mkhookstest
README.FREETDSbuild.confincludeuri
README.cmakebuildconfldapxlate
apr-util.pc.inconfig.layoutlibaprutil.depxml
apr-util.specconfigurelibaprutil.dsp

  • 检查apr-util编译环境
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@bobi apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
...
config.status: creating test/Makefile
config.status: creating include/private/apu_config.h
config.status: executing default commands

  • 产生编译文件
[root@bobi apr-util-1.6.1]# make
make[1]: Entering directory `/usr/src/apr-util-1.6.1
/bin/sh /usr/local/apr/build-1/libtool --silent --mode=compile gcc -g -O2 -pthread-DHAVE_CONFIG_H-DLINUX -D_REENTRANT -D_GNU_SOURCE-I/usr/src/apr-util-1
...
xml/apr_xml.c:35:19: fatal error: expat.h: No such file or directory
#include < expat.h>
make[1]: *** [xml/apr_xml.lo] Error 1
make[1]: Leaving directory `/usr/src/apr-util-1.6.1
make: *** [all-recursive] Error 1

发现报错:xml/apr_xml.c:35:19: fatal error: expat.h: No such file or directory(缺少依赖)
百度搜索报错信息,解决办法:
  yum install expat-devel
[root@bobi apr-util-1.6.1]# yum install expat-devel
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
...
Installed:
expat-devel.x86_64 0:2.1.0-14.el7_9
Dependency Updated:
expat.x86_64 0:2.1.0-14.el7_9

Complete!

  • 继续执行 make
[root@bobi apr-util-1.6.1]# make
make[1]: Entering directory `/usr/src/apr-util-1.6.1
/bin/sh /usr/local/apr/build-1/libtool --silent --mode=compile gcc -g -O2 -pthre
...
de/apr-1export_vars.c | sed -e s/^\\#[^!]*// | sed -e /^$/d > > aprutil.exp
sed s,^\\(location=\\).*$,\\1installed, < apu-1-config > apu-config.out
make[1]: Leaving directory `/usr/src/apr-util-1.6.1

  • 安装编译文件
[root@bobi apr-util-1.6.1]# make install
make[1]: Entering directory `/usr/src/apr-util-1.6.1
make[1]: Nothing to be done for `local-all

    推荐阅读