linux命令第一天

linux上的目录结构1.
所有目录都是以/开始 ,“/”是linux的根目录

根据目录下的文件夹:
bin|sbin:它是linux上可执行文件的存放目录
dev:它是设备目录(鼠标,键盘等)
lib64|lib:它是linux上库文件的存放路径
mnt:挂载目录,
run|boot|proc:都属于和linux系统启动相关
var:存放程序运行日志,自定义安装软件的目录
opt:自已安装软件使用的目录
usr:linux系统安装软件的默认目录
重要
etc:linux系统系统配置文件的存放目录,只有管理员才能修改
root:linux上系统管理员的主目录
home:linux上的所有用户(非root用户)的主目录(相当于windows上的c:/user)

1.pwd命令

pwd 查看当前目录的路径

2.ls命令

ls 查看目录下的文件或文件夹

ls [配置项] [目录路径] #表示查看指定目录下的文件,如果不传入目录路径,表示查看当前目录下的文件

[root@oracle ~]# ls #查看当前目录下的文件

anaconda-ks.cfg
[root@oracle ~]# ls /root
anaconda-ks.cfg

[root@oracle ~]# ls / #查看根目录下的所有文件

bin   dev  home  lib64  mnt  proc  run   srv  tmp  var
boot  etc  lib   media  opt  root  sbin  sys  usr

ls -l 目录路径 #查看目录下文件的详细信息可以简写为ll

[root@oracle ~]# ls -l #查看当前目录下的文件的详细信息

总用量 4
-rw-------. 1 root root 1228 3月  25 08:57 anaconda-ks.cfg
[root@oracle ~]# ll  #同ls -l
总用量 4
-rw-------. 1 root root 1228 3月  25 08:57 anaconda-ks.cfg

ls -a 目录路径 #查看目录下的隐藏文件

[root@oracle ~]# ls -a  #查看当前目录下所有的文件(包含隐藏文件)
.  ..  anaconda-ks.cfg  .bash_logout  .bash_profile  .bashrc  .cshrc  .tcshrc
[root@oracle ~]#

**ls -lh **# -l 查看详细信息 h以合适的单位显示文件的大小

[root@oracle ~]# ls -lh #查看目录下的文件的详细信息,以合适单位显示文件大小 总用量 4.0K

-rw-------. 1 root root 1.2K 3月  25 08:57 anaconda-ks.cfg
[root@oracle ~]# ls -alh
总用量 24K
dr-xr-x---.  2 root root  114 3月  25 08:57 .
dr-xr-xr-x. 17 root root  224 3月  25 08:55 ..
-rw-------.  1 root root 1.2K 3月  25 08:57 anaconda-ks.cfg
-rw-r--r--.  1 root root   18 12月 29 2013 .bash_logout
-rw-r--r--.  1 root root  176 12月 29 2013 .bash_profile
-rw-r--r--.  1 root root  176 12月 29 2013 .bashrc
-rw-r--r--.  1 root root  100 12月 29 2013 .cshrc
-rw-r--r--.  1 root root  129 12月 29 2013 .tcshrc

3.cd命令

cd 目录路径 #切换目录

目录路径:绝对路径:以根目录开始的路径叫绝对路径
/root #绝对路径

相对路径: 不是以根目录开始的,相对于当前目录的路径,相对路径
root #相对路径

           . 表示当前路径
	 .. 表示当前路径的上一级目录
[root@oracle ~]# pwd
/root
[root@oracle ~]# cd /usr/local  #切换到/usr/lcoal目录下
[root@oracle local]# pwd
/usr/local
[root@oracle local]# cd ..  #切换到当前目录的上一级目录
[root@oracle usr]# pwd
/usr
[root@oracle usr]# cd local  #切换到当前目录下的local目录
[root@oracle local]# pwd
/usr/local
[root@oracle local]# cd ../share  #切换到和local同级的share目录
[root@oracle share]# pwd
/usr/share
[root@oracle share]# cd #不添加任何内容表示切换到当前用户的主目录下
[root@oracle ~]# pwd
/root

[root@oracle ~]# cd /usr/local
[root@oracle local]# pwd
/usr/local
[root@oracle local]# cd ~ # ~表示当前用户的主目录,表示切换到当前用户的主目录下
[root@oracle ~]# pwd
/root

4.mkdir命令

mkdir [配置项] 目录路径 #表示创建目录

[root@oracle ~]# mkdir data  #在当前目录下创建一个data目录
[root@oracle ~]# ls #查看当前目录下的文件
anaconda-ks.cfg  data 
[root@oracle ~]# cd data #切换到当前目录下的data目录
[root@oracle data]# pwd
/root/data
[root@oracle data]# mkdir /root/a #使用绝对路径在/root目录下创建一个a目录(上级目录必须存在否则不能创建)
[root@oracle data]# ls /root
a  anaconda-ks.cfg  data
[root@oracle data]# pwd
/root/data
[root@oracle data]# cd 
[root@oracle ~]# pwd
/root
[root@oracle ~]# ls
a  anaconda-ks.cfg  data

mkdir -p 目录路径 #同时创建多级目录

[root@oracle ~]# mkdir x/y/z #创建z目录时,因为x和y目录都不存在,所有不允许创建
mkdir: 无法创建目录"x/y/z": 没有那个文件或目录
[root@oracle ~]# mkdir -p x/y/z #-p参数,创建多级目录,先创建目录x再创建y,最后创建z目录
[root@oracle ~]# ls
a  anaconda-ks.cfg  data  x
[root@oracle ~]# ls x
y
[root@oracle ~]# ls x/y
z

5.rmdir命令

rmdir 目录路径 #删除目录命令,只能删除一个空的目录

[root@oracle ~]# ls
a  anaconda-ks.cfg  data  x
[root@oracle ~]# rmdir a #删除当前目录下的空目录a
[root@oracle ~]# ls
anaconda-ks.cfg  data  x

[root@oracle ~]# rmdir x #不能删除不为空的目录
rmdir: 删除 "x" 失败: 目录非空

6.touch命令

touch:创建文件命令

touch 文件路径 #创建一个空文件

[root@oracle ~]# touch 1.txt  #创建一个空1.txt文件
[root@oracle ~]# ls
1.txt  anaconda-ks.cfg  data  x
[root@oracle ~]# touch 2.txt #创建一个空的2.txt文件
[root@oracle ~]# ls
1.txt  2.txt  anaconda-ks.cfg  data  x
[root@oracle ~]# touch /root/3.txt #在/root目录下创建一个3.txt文件
[root@oracle ~]# ls
1.txt  2.txt  3.txt  anaconda-ks.cfg  data  x
[root@oracle ~]# touch 4.txt 5.txt 6.txt 7.txt #在当前目录下创建4个txt文件分别是4.txt,5.txt,6.txt,7.txt
[root@oracle ~]# ls
1.txt  2.txt  3.txt  4.txt  5.txt  6.txt  7.txt  anaconda-ks.cfg  data  x

7.rm命令

rm 删除命令

rm [配置项] 文件路径

[root@oracle ~]# rm 1.txt #删除1.txt文件有提示,输入y表示删除,输入n表示不删除
rm:是否删除普通空文件 "1.txt"?y
[root@oracle ~]# ls
2.txt  3.txt  4.txt  5.txt  6.txt  7.txt  anaconda-ks.cfg  data  x
[root@oracle ~]# rm 2.txt
rm:是否删除普通空文件 "2.txt"?n
[root@oracle ~]# ls
2.txt  3.txt  4.txt  5.txt  6.txt  7.txt  anaconda-ks.cfg  data  x
rm -f 文件路径 #强制删除
[root@oracle ~]# rm -f 2.txt  #强制删除2.txt文件,不提示直接删除
[root@oracle ~]# ls
3.txt  4.txt  5.txt  6.txt  7.txt  anaconda-ks.cfg  data  x

**rm -rf **文件夹路径 #强制删除文件夹下的所有文件

[root@oracle ~]# rm -rf x  #强制删除当前目录下的x目录及x目录下的所有文件和文件夹
[root@oracle ~]# ls
3.txt  4.txt  5.txt  6.txt  7.txt  anaconda-ks.cfg  data

[root@oracle ~]# rm -rf /root/* #表示删除/root目录下的所有文件但不删除目录/root
[root@oracle ~]# ls

8.cat 命令

cat:读取文件(查看文件内容,合并文件)

[root@Oralce kk]# cat 1.txt
kkkkk阿斯利康的垃圾了咖啡[root@Oralce kk]# 

-n 从1开始对所有输出行编号

[root@Oralce kk]# cat -n 1.txt
     1	jdajdkajkdnaanakjsnkajndakjkjdak
     2	sakjdakjdnakkkk阿斯利康的垃圾了咖啡sd
     3	sada

-b 从1开始对所有非空输出行编号
-s 将多个相邻的空行合并成一个空行

vi 修改文件(写文件)
esc退出,
:wq:保存并退出,
**:q!**不保存退出

[root@Oralce kk]# vi 1.txt
[root@Oralce kk]# cat 1.txt
jdajdkajkdnaanakjsnkajndakjkjdak
sakjdakjdnakkkk阿斯利康的垃圾了咖啡sd
sada
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值