【若泽大数据基础第一天】基础-Linux基础命令一

本文详细介绍了Linux系统中常用的命令操作,包括用户管理、目录切换、文件操作、环境配置等,适合初学者快速掌握和查阅。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Linux系统用户

[root@hadoop614 ~]# id
uid=0(root) gid=0(root) groups=0(root)  # root为unix系统超级管理员用户

Linux基础命令

  • 查看当前所在目录:pwd
[root@hadoop614 ~]# pwd
/root    						# /root为当前所在目录
  • 切换所在目录:cd
[root@hadoop614 ~]# cd /etc  	# / 表示根目录,为Linux系统一级目录 
						 	 	# etc为根目录下的二级目录
							 	# ~为表示用户家目录 
[root@hadoop614 etc]# 			# ‘#’表示用当前用户为管理员用户
					   			# etc位置表示当前所在目录
[root@hadoop614 etc]# cd   		# 切换到用户家目录
[root@hadoop614 ~]# cd ~   		# 切换到用户家目录
					   
  • 查看所在目录下内容:ls
[root@hadoop614 ~]# ls			# 查询当前目录下所有显性文件和目录名称
1.txt  2.sh  3.ini  4.py

[root@hadoop614 ~]# ls -l		# -l :等同于‘ll’;显示当前目录内容及其属性
total 0
-rw-r--r-- 1 root root 0 Jan 20 12:34 1.txt	# -rw-r--r-- 表示文件或文件夹权限
-rw-r--r-- 1 root root 0 Jan 20 12:34 2.sh	# root表示文件或文件夹所属用户
-rw-r--r-- 1 root root 0 Jan 20 12:34 3.ini	# root表示文件或文件夹所属组
-rw-r--r-- 1 root root 0 Jan 20 12:34 4.py	# 后面依次为文件大小,更新月 日期 时间 名字
[root@hadoop614 ~]# ll -a		# -a 表示查询当前目录下所有文件和目录名称(包含隐藏文件)
								# 隐藏文件/目录:以 . 开头的文件或目录
total 48
dr-xr-x---.  5 root root 4096 Jan 20 12:34 .	#表示当前目录
dr-xr-xr-x. 18 root root 4096 Jan 15 21:33 ..	#表示父目录/上一级目录
-rw-------   1 root root  321 Jan 16 23:20 .bash_history	#用户历史输入命令记录文件
-rw-r--r--.  1 root root   18 Dec 29  2013 .bash_logout		# 用户登录记录文件
-rw-r--r--.  1 root root  176 Dec 29  2013 .bash_profile	# 用户环境变量配置文件
-rw-r--r--.  1 root root  176 Dec 29  2013 .bashrc			# 用户环境变量配置文件
····· #内容过多,不做展示
[root@hadoop614 ~]# ll -rt	# r 表示正序排序 t 表示时间 :按时间正序排序
total 8
-rw-r--r-- 1 root root  0 Jan 20 12:34 4.py
-rw-r--r-- 1 root root  0 Jan 20 12:34 3.ini
-rw-r--r-- 1 root root 61 Jan 20 12:47 1.txt
-rw-r--r-- 1 root root  2 Jan 20 12:48 2.sh
[root@hadoop614 ~]# ll -h	#提升文件或目录大小的可读性
total 660K
-rw-r--r-- 1 root root   61 Jan 20 12:47 1.txt
-rw-r--r-- 1 root root 655K Jan 20 12:50 services
  • 清空当前屏幕:clear
  • 查看当前系统网卡IP地址:ifconfig

Linux : ifconfig
Windows : ipconfig
unix/AIX : ifconifg -a

[root@hadoop614 ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
       inet 172.17.64.32  netmask 255.255.240.0  broadcast 172.17.79.255
       ether 00:16:3e:0e:05:61  txqueuelen 1000  (Ethernet)
       RX packets 93473  bytes 8748270 (8.3 MiB)
       RX errors 0  dropped 0  overruns 0  frame 0
       TX packets 77688  bytes 8952210 (8.5 MiB)
       TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
       inet 127.0.0.1  netmask 255.0.0.0
       loop  txqueuelen 1000  (Local Loopback)
       RX packets 0  bytes 0 (0.0 B)
       RX errors 0  dropped 0  overruns 0  frame 0
       TX packets 0  bytes 0 (0.0 B)
       TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

  • 创建目录 :mkdir
[root@hadoop614 ~]# mkdir abc		# 创建目录名为 abc
[root@hadoop614 ~]# ll
total 664
-rw-r--r-- 1 root root     61 Jan 20 12:47 1.txt	# -rw-r--r-- 第一个‘-’表示文件
drwxr-xr-x 2 root root   4096 Jan 20 13:03 abc	# drwxr-xr-x 中的’d'表示目录directory
-rw-r--r-- 1 root root 670293 Jan 20 12:50 services
[root@hadoop614 ~]# mkdir -p a/b/c	# -p:表示若创建目标目录的父目录不存在则创建父目录
[root@hadoop614 ~]# ll a/b
total 4
drwxr-xr-x 2 root root 4096 Jan 20 13:08 c
[root@hadoop614 ~]# mkdir 1 2 3 	# 同时创建多个目录,目录名间以空格区分
[root@hadoop614 ~]# ll
total 12
drwxr-xr-x 2 root root 4096 Jan 20 13:10 1
drwxr-xr-x 2 root root 4096 Jan 20 13:10 2
drwxr-xr-x 2 root root 4096 Jan 20 13:10 3
  • 创建文件:touch #创建空文件

touch + 文件名

[root@hadoop614 ~]# touch ruozedata.txt
[root@hadoop614 ~]# ll
total 12
drwxr-xr-x 2 root root 4096 Jan 20 13:10 1
drwxr-xr-x 2 root root 4096 Jan 20 13:10 2
drwxr-xr-x 2 root root 4096 Jan 20 13:10 3
-rw-r--r-- 1 root root    0 Jan 20 13:18 ruozedata.txt
  • 像控制台输出打印:echo
[root@hadoop614 ~]# echo Hello World
Hello World
  • 输入输出重定向:< > << >>
类型符号作用
标准输出重定向命令 > 文件以覆盖的方式,把命令的正确输出输出到指定的文件或设备中
命令 >> 文件以追加的方式,把命令的正确输出输出到指定的文件或设备中
标准错误输出重定向错误命令2 > 文件以覆盖的方式,把命令的错误输出输出到指定的文件或设备中
错误命令2 >> 文件以追加的方式,把命令的错误输出输出到指定的文件或设备中
正确输出和错误输出同时保存命令 > 文件2>&1以捜盖的方式,把正确输出和错误输出都保存到同一个文件中
命令 >> 文件2>&1以追加的方式,把正确输出和错误输出都保存到同一个文件中
命令&>文件以覆盖的方式,把正确输出和错误输出都保存到同一个文件中
命令&>>文件以追加的方式,把正确输出和错误输出都保存到同一个文件中
命令>>文件1 2>>文件2把正确的输出追加到文件1中,把错误的输出追加到文件2中
  • 移动文件:mv # move的简写

mv + 原文件名/目录名 + 新名称 --以空格区分,可用于重命名
移动的文件始终只有一份

[root@hadoop614 ~]# mv ruozedata.txt ruozedata.txt_20190120
[root@hadoop614 ~]# mv 1 direct
[root@hadoop614 ~]# ll
total 12
drwxr-xr-x 2 root root 4096 Jan 20 13:10 2
drwxr-xr-x 2 root root 4096 Jan 20 13:10 3
drwxr-xr-x 2 root root 4096 Jan 20 13:10 direct
-rw-r--r-- 1 root root    0 Jan 20 13:12 ruozedata.txt_20190120
  • 复制文件:cp #copy简写

cp + 原文件名/目录名 + 新名称 --以空格区分,可用于重命名
负责的文件会有多份

[root@hadoop614 ~]# cp ruozedata.txt ./1/
[root@hadoop614 ~]# ll ./1/
total 0
-rw-r--r-- 1 root root 0 Jan 20 13:23 ruozedata.txt
  • 查看命令帮助:--help
[root@hadoop614 ~]# ls --help
Usage: ls [OPTION]... [FILE]...
····· # 内容过多,不做展示
  • 查看文件内容:mroe/cat/tail
[root@hadoop614 ~]# cat ruozedata.txt 	# 直接向控制台打印文件所有内容
a b c
www.ruozedata.com
www.baidu.com
[root@hadoop614 ~]# 
more 文件内容一页一页的往下翻 按空格键往下  回退不了  按q退出
[root@hadoop614 etc]# more ld.so.cache
ld.so-1.7.0
 
--More--(5%)
less 文件内容 往下 往下  按上下箭头的按键   按q退出
  • 别名:alias
alias rzcd='cd /root/ruozedata/'  # 当前会话生效
  • 配置环境变量

全局环境变量:/etc/profile #所有用户均可使用

[root@hadoop614 ~]# vi /etc/profile			# vim编译器
[root@hadoop614 ~]# source /etc/profile		# 使环境变量立即生效

/etc/profile文件

个人环境变量:~/.base_profile # 只有所属用户生效

[root@hadoop614 ~]# vi  ~/.bash_profile
[root@hadoop614 ~]# source /etc/profile

在这里插入图片描述

  • 删除:rm
[root@hadoop614 ~]# rm ruozedata.txt 		# 只能删除文件
rm: remove regular file ‘ruozedata.txt’? y		# 询问是否删除文件 y->yes;n->no
[root@hadoop614 ~]# rm -r 1			# -r 表示可以删除目录和文件
rm: descend into directory ‘1’? y		#1目录中有内容,是否进入1目录
rm: remove regular empty file ‘1/ruozedata.txt’? y		# 1目录中有文件,是否删除
rm: remove directory ‘1’? y		# 是否删除目录
[root@hadoop614 ~]# rm -rf 2	# f参数表示强制,即不再询问是否进行下一步
[root@hadoop614 ~]# 
注:不允许使用使用 'rm -rf /' 命令
  • 设置变量

变量:可以变化的量,以键值对的方式存在
设置 key=value =前后不能有空格
使用 ${key}

[root@hadoop614 ~]# user=xiaohai
[root@hadoop614 ~]# echo ${user}
xiaohai
[root@hadoop614 ~]# echo ${USER}		# shell 脚本中使用此方法获取当前登录的用户,或执行此脚本的用户
root
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值