linux基础命令

linux基础命令

1.ls 的使用

ls–>查看当前目录下的所有内容

ls常见参数:
-a 查看目录下的所有文件,包括隐藏文件
-l 长列表显示
-h human 以人性化的方式显示出来
-t 按修改时间进行排序
-S 按文件的Size排序

以root文件夹为例:

[root@cuichengjie ~]# ls /root
anaconda-ks.cfg  Desktop  Documents  Downloads  initial-setup-ks.cfg  Music  Pictures  Public  Templates  Videos

[root@cuichengjie ~]# ls -a /root/
.                .bash_history  .bashrc  .cshrc   Documents  .ICEauthority         Music     .tcshrc    .viminfo
..               .bash_logout   .cache   .dbus    Downloads  initial-setup-ks.cfg  Pictures  Templates  .Xauthority
anaconda-ks.cfg  .bash_profile  .config  Desktop  .esd_auth  .local                Public    Videos

[root@cuichengjie ~]# ls -l
total 8
-rw-------. 1 root root 2012 Dec 24 18:56 anaconda-ks.cfg
drwxr-xr-x. 3 root root   16 Dec 24 20:58 Desktop
drwxr-xr-x. 2 root root    6 Dec 24 18:59 Documents
drwxr-xr-x. 2 root root    6 Dec 24 18:59 Downloads
-rw-r--r--. 1 root root 2046 Dec 24 18:58 initial-setup-ks.cfg
drwxr-xr-x. 2 root root    6 Dec 24 18:59 Music
drwxr-xr-x. 2 root root    6 Dec 24 18:59 Pictures
drwxr-xr-x. 2 root root    6 Dec 24 18:59 Public
drwxr-xr-x. 2 root root    6 Dec 24 18:59 Templates
drwxr-xr-x. 2 root root    6 Dec 24 18:59 Videos

[root@cuichengjie ~]# ll -h //以人性化的方式  将2012简化为2.0K 更方便观看
total 8.0K
-rw-------. 1 root root 2.0K Dec 24 18:56 anaconda-ks.cfg
drwxr-xr-x. 3 root root   16 Dec 24 20:58 Desktop
drwxr-xr-x. 2 root root    6 Dec 24 18:59 Documents
drwxr-xr-x. 2 root root    6 Dec 24 18:59 Downloads
-rw-r--r--. 1 root root 2.0K Dec 24 18:58 initial-setup-ks.cfg
drwxr-xr-x. 2 root root    6 Dec 24 18:59 Music
drwxr-xr-x. 2 root root    6 Dec 24 18:59 Pictures
drwxr-xr-x. 2 root root    6 Dec 24 18:59 Public
drwxr-xr-x. 2 root root    6 Dec 24 18:59 Templates
drwxr-xr-x. 2 root root    6 Dec 24 18:59 Videos

[root@cuichengjie ~]# ls -t  //按照修改的时间进行排序
Desktop  Documents  Downloads  Music  Pictures  Public  Templates  Videos  initial-setup-ks.cfg  anaconda-ks.cfg

[root@cuichengjie ~]# ls -S  //按照文件的大小进行排序
initial-setup-ks.cfg  anaconda-ks.cfg  Desktop  Documents  Downloads  Music  Pictures  Public  Templates  Videos
2.cd 的使用

cd–> 路径切换(文件定位路径)

绝对路径:从/开始的路径 例如 /home/qf/zz
相对路径:相对于当前目录开始

cd专用:
cd~ 返回到用户的家目录
cd- 返回上次所在的目录
cd 返回用户的家目录
cd… 返回上一级目录

命令 pwd 为查看当前所在的目录

[root@localhost ~]# pwd //查看当前所在的目录
/root

3.文件夹/文件的创建、复制、移动、删除
3.1 文件的创建(touch)
  [root@cuichengjie ~]# touch /root/Desktop/qf.txt    //在/root/Desktop位置上创建了qf.txt文件

  [root@cuichengjie ~]# touch /root/Desktop/qf{1..10}.txt    //在此位置上创建了qf1~10.txt,共10个文件,1,10最先创建
3.2 文件夹的创建(mkdir)
[root@cuichengjie ~]# mkdir /root/dir1    //在root路径上创建了dir1这个文件夹

[root@cuichengjie ~]# mkdir dir2       //在当前所在路径上创建了dir2这个文件夹

[root@cuichengjie ~]# mkdir -v cui{1..5}    //在当前所在路径上创建5个连续名称的文件夹
mkdir: created directory ‘cui1’
mkdir: created directory ‘cui2’
mkdir: created directory ‘cui3’     // -v 在此表示显示创建详情
mkdir: created directory ‘cui4’
mkdir: created directory ‘cui5’

 [root@cuichengjie ~]# mkdir -pv /root/Desktop/dir3/dir4         //在/root/Desktop/上创建了dir3,在dir3里又包含了新创建的dir4
mkdir: created directory ‘/root/Desktop/dir3’
mkdir: created directory ‘/root/Desktop/dir3/dir4’

//     -p表示递归创建    上局命令先在Desktop创建dir3,然后又在dir3里创建了dir4

参数解析:
-p:递归创建
-v:显示创建详情
3.3 文件/文件夹的复制(cp)
格式为: cp -v 文件名 复制到的路径

[root@cuichengjie ~]# cp -v /root/Desktop/qf1.txt /home/
‘/root/Desktop/qf1.txt’ -> ‘/home/qf1.txt’

[root@cuichengjie ~]# ls /home/               //qf1.txt被复制到home目录中
cuichengjie1  qf1.txt      

[root@cuichengjie ~]# cp -rv /root/Desktop/qf /home/    //文件夹的复制
‘/root/Desktop/qf’ -> ‘/home/qf’
‘/root/Desktop/qf/qf.txt’ -> ‘/home/qf/qf.txt’ 

-r为复制目录      在复制文件夹时,会将文件夹里面的内容一同复制

[root@cuichengjie ~]# cp -v /root/Desktop/qf /root/cui1
cp: omitting directory ‘/root/Desktop/qf’       //待解决

一次性拷贝多个文件:

[root@cuichengjie ~]# cd /root/Desktop/         //进入桌面
[root@cuichengjie Desktop]# ls           //显示桌面上的所有文件
dir3  qf  qf10.txt  qf1.txt  qf2.txt  qf3.txt  qf4.txt  qf5.txt  qf6.txt  qf7.txt  qf8.txt  qf9.txt  qf.txt
[root@cuichengjie Desktop]# cp -v qf1.txt qf2.txt /opt/        //如果未进入桌面,则所复制的文件应带上绝对路径
‘qf1.txt’ -> ‘/opt/qf1.txt’
‘qf2.txt’ -> ‘/opt/qf2.txt’

[root@cuichengjie Desktop]# cp -v qf2.txt /opt/b.txt
‘qf2.txt’ -> ‘/opt/b.txt’                    //将qf2.txt拷贝到opt中,并改名为b.txt,文件内容不变


3.4 文件/文件夹的删除(rm -rf)
[root@cuichengjie Desktop]# rm -rfv qf1.txt      //删除Desktop上的qf1.txt文件
removed ‘qf1.txt’
[root@cuichengjie Desktop]# rm -rfv qf       //删除Desktop上的qf文件夹,连同里面所有文件一同删除
removed ‘qf/qf.txt’
removed directory: ‘qf’
[root@cuichengjie Desktop]# rm -rfv /root/Desktop/*    //*指代该文件夹内所有的内容
removed directory: ‘/root/Desktop/dir3/dir4’
removed directory: ‘/root/Desktop/dir3’
removed ‘/root/Desktop/qf10.txt’
removed ‘/root/Desktop/qf2.txt’
removed ‘/root/Desktop/qf3.txt’
removed ‘/root/Desktop/qf4.txt’
removed ‘/root/Desktop/qf5.txt’
removed ‘/root/Desktop/qf6.txt’
removed ‘/root/Desktop/qf7.txt’
removed ‘/root/Desktop/qf8.txt’
removed ‘/root/Desktop/qf9.txt’
removed ‘/root/Desktop/qf.txt’

参数解析:
-r 递归

-f force强制

-v 显示操作详情

-pwd 查看当前目录
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值