Linux基础命令学习

1、如何在root用户与普通用户之间切换

切换至root用户语法:

[ym@localhost root]$ su -

Password:

[root@localhost ~]#

切换至普通用户ym的语法:

[root@localhost ~]# su ym

[ym@localhost root]$

 

2、文件删除

[ym@localhost dir1]$ rm<    #文件名包好特殊字符的无法直接删除,这时要加双

-bash: syntax error nearunexpected token `newline’

[ym@localhost dir1]$ rmfile1.txt

[ym@localhost dir1]$ dir

< <~ file.txt test test1test2 text

[ym@localhost dir1]$ rmfile.txt

[ym@localhost dir1]$ di

r< <~ test test1 test2text

[ym@localhost dir1]$ rm “<”

[ym@localhost dir1]$ dir<

~ test test1 test2 text

[ym@localhost dir1]$ rm“<~”

[ym@localhost dir1]$ dir

test test1 test2 text

[ym@localhost dir1]$

 

3、如何查询Linux所有的用户以及密码

[root@localhost ~]# vim/etc/passwd #查询用户信息

[root@localhost ~]# vim/etc/shadow #查询密码,注获取的不是明文密码,如果需要则要用户自己破解

 

4、利用环境变量$PS1$PS2控制命令行提示符的格式

可以用echo命令来显示当前提示符的设置

[root@localhost ~]# echo $PS1

[\u@\h \W]\$

[root@localhost ~]# echo $PS2

>

[root@localhost ~]#

PS1:控制默认命令行提示符的格式

PS2:控制后续命令行提示符的格式

 

5、查看bash手册

man命令用来访问存储在Linux系统上的手册条目。

man后面加入想要查找的工具名称,就可以找到那个工具对应的手册。如:

[root@localhost ~]# man dateFormatting page, please wait…

[root@localhost ~]# man bashFormatting page, please wait…

 

6、遍历目录

Linux文件系统上,你可以使用切换目录命令来将shell会话的一切切换至另一个目录。

cd格式如下:

cd destination

目标路径参数存在两种方式表达:

(1)绝对文件路径;

(2)相对文件路径;

    单点符(.),表示当前目录;

    双点符(..),表示当前目录的父目录。

 

7、基本列表功能

ls命令最基本的格式会显示当前目录下的文件和目录

[ym@localhost ~]$ ls

Desktop Documents MusicPictures Templates dir1 Downloads newfile Public Videos

如果没有安装支持彩色的终端模拟器,可用带-F参数的ls命令来轻松区分文件和目录,命令如下:

[ym@localhost ~]$ ls -F

Desktop/ Documents/ Music/Pictures/ Templates/ dir1/ Downloads/ newfile Public/ Videos/

要把隐藏的文件和普通文件和目录一起显示出来,就得用到-a参数

[ym@localhost ~]$ ls -a

. Documents .gnote Pictures ..Downloads .gnupg Public

-R参数时ls命令的另一个参数,它列出了当前目录下包含的目录中的文件。

[ym@localhost ~]$ ls -F -R

.: Desktop/ Documents/ Music/Pictures/ Templates/ dir1/ Downloads/ newfile Public/ Videos/

./Desktop:gnome-terminal.desktop*

./dir1: test/ test1 test2 text

./dir1/test: test test1

./Documents:

 

8、输出文件的详细信息

-l参数会产生长列表格式输出,包含了目录中每个文件的更多相关信息:

[ym@localhost ~]$ ls -l

total 36

drwxr-xr-x. 2 ym ym 4096 Nov10 20:37 Desktop

 drwxrwxr-x. 3 ym ym 4096Nov 30 00:13 dir1

drwxr-xr-x. 2 ym ym 4096 Nov10 20:23 Documents

9、过滤输出列表

ls命令支持在命令行下定义过滤器。

它会用过滤器来决定应该在输出中显示哪些文件或目录

[ym@localhost ~]$ ls-l dir1/

 total 8

drwxrwxr-x. 2 ym ym 4096 Nov10 20:51 test

-rw-rw-r—. 1 ym ym 0 Nov 2923:05 test1

 -rw-rw-r—. 1 ym ym 0 Nov29 23:30 test2

 ls命令能够识别标准通配符,并在过滤器中用它们进行模式匹配

? :问号代表一个字符

*:星号代表零个或多个字符

 

10、空文件创建

可以用touch命令创建空文件

[ym@localhost ~]$ ls

 Desktop Documents MusicPictures Templates dir1 Downloads newfile Public Videos

 [ym@localhost ~]$ touchpython.py

 [ym@localhost ~]$ ls

Desktop Documents MusicPictures python.py Videos dir1 Downloads newfile Public Templates

默认情况下,touch使用当前时间。可以通过-t参数加上特定的时间戳来指定时间:

[ym@localhost ~]$ touch -t201112251200 test1

[ym@localhost ~]$ ls -l test1

-rw-rw-r—. 1 ym ym 0 Dec 252011 test1

11Python程序的调用

[ym@localhost ~]$ vimpython.py #写入代码

[ym@localhost ~]$ pythonpython.py [10, 1, 2, 3, 4] [1, 2, 3, 4, 10]

[ym@localhost ~]$ catpython.py #查看代码

a=[10,1,2,3,4]

print(a)

print(sorted(a))

12、复制文件

在最基本的用法里,cp命令需要两个参数,源对象和目标对象: cp source destination

[ym@localhost ~]$ ls

Desktop Documents Music Picturespython.py test1 dir1 Downloads newfile Public Templates Videos

[ym@localhost ~]$ cp test1test2

[ym@localhost ~]$ ls

Desktop Documents MusicPictures python.py test1 Videos dir1 Downloads newfile Public Templates test2

可以用点文件把文件复制到当前所在的目录

 

13mysql的安装

step1yum search mysql #查看可安装列表

root@localhost ~]# yum searchmysql

step2: sudo yum installmysql-server.x86_64 #安装mysql服务器版本

[root@localhost ~]# sudo yuminstall mysql-server.x86_64

step3:验证安装是否成功。

[ym@localhost ~]$ mysql #验证安装是否成功

ERROR 2002 (HY000): Can’tconnect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)

step4:先查看 /etc/rc.d/init.d/mysqldstatus看看mysql是否已经启动.另外看看是不是权限问题.

[root@localhost ~]#/etc/rc.d/init.d/mysqld status #mysql是否已经启动

mysqld is stopped

step5: service mysqld start #启动服务

[root@localhost ~]# servicemysqld start

Initializing MySQL database:

Installing MySQL systemtables… OK

Filling help tables… OK

Step6:验证是否安装成功

[ym@localhost dir1]$ mysql

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值