原创Blog。转载请注明出处

附上之前訪问量比較高的几篇linux博客

本人使用shell的8个小技巧

grep的九个经典使用场景

sed命令具体解释

awk命令具体解释

linux中全部的东西都是文件,命令就是一个一个二进制文件

1、ls

/bin/ls

经常使用选项

-a 全部文件(包含隐藏文件)

-l 具体信息

-d 文件夹属性

-i 查看inode

举例

[root@localhost testForCsdn]# ls
fileList first second
[root@localhost testForCsdn]# ls -a
. .. fileList first second
[root@localhost testForCsdn]# ls -l
total 16
-rw-r--r-- 1 root root 100 Oct 18 23:12 fileList
-rw-r--r-- 1 root root 0 Oct 24 18:04 first
-rw-r--r-- 1 root root 0 Oct 24 18:04 second
[root@localhost testForCsdn]# ls -al
total 32
drwxr-xr-x 2 root root 4096 Oct 24 18:04 .
drwxr-x--- 17 root root 4096 Oct 24 17:56 ..
-rw-r--r-- 1 root root 100 Oct 18 23:12 fileList
-rw-r--r-- 1 root root 0 Oct 24 18:04 first
-rw-r--r-- 1 root root 0 Oct 24 18:04 second
[root@localhost testForCsdn]# ls -d
.
[root@localhost testForCsdn]# ls -i
2256719 fileList 2256718 first 2256730 second

分析下

-rw-r--r-- 1 root root 100 Oct 18 23:12 fileList

对于这一行来说,从左至右分析

-表示这是一个二进制文件

rw-r--r-- 分别r表示读权限,w表示写权限,-表示没有权限。假设是x表示可运行权限,一共9个,三个一组。分别表示创建者,所属组,其它人

所以,对于创建者来说是rw-就是可读写不可运行,对于所属组就是r--仅仅有读的权限,其它人仅仅有读的权限

1表示硬链接数目

第一个root表示用户

第二个root表示用户组

100表示文件大小,假设是文件夹就是文件夹和子文件夹大小

Oct 18 23:13:12 表示最后改动的时间

fileList 表示文件名称

2、cd 

change direction

和cd配合的经常使用命令还有

pwd  查看当前文件夹

改变文件夹

首先解说下文件夹

/ 根分区,全部的文件和文件夹都由此開始

/bin 用户可运行文件

/sbin 系统可运行文件,主要供管理员使用。s为super

/etc 配置文件

/dev 设备文件

/proc 进程信息。如/proc/cpuinfo包括了处理器信息

/var  变量文件如log,mail

/usr 用户程序。为用户应用程序存放文件

/home 用户主文件夹

/boot 启动载入项

/opt 可选应用

/mnt 挂载文件夹

/media 可移动媒体 如/media/cdrom

/srv 服务数据

举例

[root@localhost etc]# cd /etc/
[root@localhost etc]# pwd
/etc
[root@localhost etc]# cd ~
[root@localhost ~]# pwd
/root

这里要说明的是

cd ~代表回到当前登陆用户的主文件夹

假设是root回到/root/

假设是普通用户,回到/home/

3、touch 

创建空白文件文件或者改动文件的时间戳

经常使用选项

-a 仅仅更改存取时间

-c 不建立不论什么文档

-d 使用指定的日期

-m 仅仅更改变动时间

-r  把指定文档的或者文件夹的日期时间改为和參考文档的同样

-t  设置指定的时间戳

举例

[root@localhost testForCsdn]# ls -l
total 16
-rw-r--r-- 1 root root 100 Oct 18 23:12 fileList
-rw-r--r-- 1 root root 0 Oct 24 18:04 first
-rw-r--r-- 1 root root 0 Oct 24 18:04 second
[root@localhost testForCsdn]# touch thrid
[root@localhost testForCsdn]# ls -l
total 20
-rw-r--r-- 1 root root 100 Oct 18 23:12 fileList
-rw-r--r-- 1 root root 0 Oct 24 18:04 first
-rw-r--r-- 1 root root 0 Oct 24 18:04 second
-rw-r--r-- 1 root root 0 Oct 24 18:34 thrid
[root@localhost testForCsdn]# touch -t 201410250935.40 thrid
[root@localhost testForCsdn]# ls -l
total 20
-rw-r--r-- 1 root root 100 Oct 18 23:12 fileList
-rw-r--r-- 1 root root 0 Oct 24 18:04 first
-rw-r--r-- 1 root root 0 Oct 24 18:04 second
-rw-r--r-- 1 root root 0 Oct 25 2014 thrid

能够看到,用-t更改了时间戳

4 mkdir

创建一个文件夹

经常使用选项

-m 创建时候指定权限

-p 指定路径。假设该路径上有些文件夹不存在,则会创建。就是能够一次创建多层文件夹

-v 显示具体信息

举例

[root@localhost testForCsdn]# mkdir -m 777 firstDir
[root@localhost testForCsdn]# ls -al
total 44
drwxr-xr-x 3 root root 4096 Oct 24 18:41 .
drwxr-x--- 17 root root 4096 Oct 24 17:56 ..
-rw-r--r-- 1 root root 100 Oct 18 23:12 fileList
-rw-r--r-- 1 root root 0 Oct 24 18:04 first
drwxrwxrwx 2 root root 4096 Oct 24 18:41 firstDir
-rw-r--r-- 1 root root 0 Oct 24 18:04 second
-rw-r--r-- 1 root root 0 Oct 25 2014 thrid
[root@localhost testForCsdn]# mkdir -p firstDir/secondDir/thridDir
[root@localhost testForCsdn]# cd firstDir/secondDir/thridDir/
[root@localhost thridDir]# pwd
/root/testForCsdn/firstDir/secondDir/thridDir

能够看到。通过-p一次创建了多层文件夹。-m在创建文件夹的同一时候给予777的权限

5 cp 

copy

经常使用选项

-b 删除覆盖目的文件的时候先备份

-i  询问是否覆盖

-P 保留源文件的或者文件夹的属性:全部者,所属组,权限时间

-r 复制文件夹

举例

[root@localhost testForCsdn]# ls
fileList firstDir second thrid
[root@localhost testForCsdn]# ls firstDir/
fileList second
[root@localhost testForCsdn]# cp thrid firstDir/
[root@localhost testForCsdn]# cp -b fileList firstDir/
cp: overwrite `firstDir/fileList'? y
[root@localhost testForCsdn]# ls firstDir/
fileList fileList~ second thrid
[root@localhost testForCsdn]# mkdir secondDic
[root@localhost testForCsdn]# cp -r firstDir/ secondDic/
[root@localhost testForCsdn]# ls secondDic/
firstDir

顺便说下scp:举个样例

scp是远程拷贝,假设要远程复制文件夹用-r

scp -r root@192.168.0.12:~/testCSDN/ localCSDN/

把192.168.0.12的~/testCSDN复制到localCSND下

6、mv

剪切和重命名

举例

[root@localhost testForCsdn]# ls
fileList firstDir second secondDic thrid
You have new mail in /var/spool/mail/root
[root@localhost testForCsdn]# mkdir tempDic
[root@localhost testForCsdn]# ls
fileList firstDir second secondDic tempDic thrid
[root@localhost testForCsdn]# mv fileList newName
[root@localhost testForCsdn]# mv newName tempDic/
[root@localhost testForCsdn]# ls
firstDir second secondDic tempDic thrid
[root@localhost testForCsdn]# ls tempDic/
newName

7 cat more

都是用来查看文件内容

cat适合较短的文件

More会分页查看:空格翻页。回车下一行。q退出

cat filename

more filename

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvSGVsbG9fSHdj/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">

8 head tail

查看文件的前几行,后几行

tail -f能够用来动态查看文件的后几行

举例

9 ln

创建软连接和硬链接

软链接:类似于windows中的快捷方式

硬链接:两个文件同步更新

软链接能够跨文件系统,硬链接不能够

举例

创建一个软连接

[root@localhost ~]# ln -s file.txt file.hardlink

创建一个硬链接

[root@localhost ~]# ln file.txt file.hardlink

能够看到。file.txt的硬链接数目变成了2

-rw-r--r-- 2 root root   210 Oct 19 07:54 file.hardlink
lrwxrwxrwx 1 root root 8 Oct 24 19:14 file.softlink -> file.txt
-rw-r--r-- 2 root root 210 Oct 19 07:54 file.txt

然后。改动file.txt

在文件開始键入testCSDN

再查看硬链接

[root@localhost ~]# head -5 file.hardlink
testForCSDN
backup
bin
boot
dev

能够看到,同步更新了内容

具体解释linux文件处理的的经常使用命令的更多相关文章

  1. Linux文件和目录管理常用重要命令

    一.目录与路径 1.相对路径与绝对路径 因为我们在Linux系统中,常常要涉及到目录的切换,所以我们必须要了解 "路径" 以及 "相对路径" 与 "绝 ...

  2. 『学了就忘』Linux文件系统管理 — 61、使用parted命令进行分区

    目录 1.parted命令介绍 2.parted交互模式 3.建立分区 (1)查看分区 (2)修改成GPT分区表 (3)建立分区 (4)建立文件系统(格式化) (5)调整分区大小 (6)删除分区 1. ...

  3. 『学了就忘』Linux文件系统管理 — 59、使用fdisk命令进行手工分区

    目录 1.手工分区前提 (1)要有一块新的硬盘 (2)在虚拟机中添加一块新硬盘 2.手工分区 (1)查看Linux系统所有硬盘及分区 (2)手工分区:详细步骤 (3)保存手工分区 3.硬盘格式化 4. ...

  4. Linux文件的加压缩解压缩tar命令

    linux下使用tar命令   解压 语法:tar [主选项+辅选项] 文件或者目录 使用该命令时,主选项是必须要有的,它告诉tar要做什么事情,辅选项是辅助使用的,可以选用.主选项:c 创建新的档案 ...

  5. Linux文件和目录的777、755、644权限解释

    Linux文件和目录的权限 1.文件权限 在linux系统中,文件或目录的权限可以分为3种: r:4 读 w:2 写 x:1  执行(运行)-:对应数值0 数字 4 .2 和 1表示读.写.执行权限 ...

  6. Linux实战教学笔记08:Linux 文件的属性(上半部分)

    第八节 Linux 文件的属性(上半部分) 标签(空格分隔):Linux实战教学笔记 第1章 Linux中的文件 1.1 文件属性概述(ls -lhi) linux里一切皆文件 Linux系统中的文件 ...

  7. Linux文件系统介绍(转)

    文章转自:http://www.iteye.com/topic/816268 文件系统是linux的一个十分基础的知识,同时也是学习linux的必备知识. 本文将站在一个较高的视图来了解linux的文 ...

  8. linux 文件类型 文件权限

    linux中常见的文件类型有: “—”表示普通文件 :-rw-r--r-- 1 root root 41727 07-13 02:56 install.log   “d”表示目录 :drwxr-xr- ...

  9. Linux常用命令英文全称与中文解释Linux系统

    Linux常用命令英文全称与中文解释Linux系统(转)   Linux常用命令英文全称与中文解释Linux系统 man: Manual 意思是手册,可以用这个命令查询其他命令的用法. pwd:Pri ...

随机推荐

  1. Elasticsearch 7.1.1 集群 + 配置身份验证

    一.安装Elasticsearch 1.1 环境说明 Centos7.6 Elasticsearch7.1.1 #挂载数据盘 fdisk /dev/vdb n,p,,回车,回车,wq fdisk -l ...

  2. im4java+GraphicsMagick

    package com.jeeplus.modules.isp.utils; import java.io.ByteArrayInputStream; import java.io.ByteArray ...

  3. POJ 3114 Tarjan+Dijkstra

    题意: 间谍在战争期间想要传递一份谍报回国,谍报可以在邮局之间传递,但这种传递是单向的,并且会少耗一些时间.但是如果两个邮局在同一个国家的话,那么谍报在这两个邮局之间传递是不消耗时间的.如果几个邮局发 ...

  4. 解决QQ未启用状态,QQ留言图标未启用

    最近由于腾讯升级QQ一些东西,导致QQ图标成未启用状态:如图 解决方法,到腾讯此站点登陆一下即可, http://wp.qq.com/set.html 另外设置 没有保存按钮,如果选择完全公开,到自己 ...

  5. Laravel5.1学习笔记7 视图

    视图 (View) 基本用法 传递数据到视图 在多个视图中分享数据 视图组件   #基本用法 视图里面包含了你应用程序所提供的 HTML 代码,并且提供一个简单的方式来分离控制器和网页呈现上的逻辑.视 ...

  6. php正则表达式应用

    正则表达式 1.替换“/\d/”,“#”,$str:正则表达式\d 数字,替换为#,字符串 $str = "2hello 5li 6lei"; echo preg_replace( ...

  7. WEB笔记-2 剖析CSS规则

    2.1 剖析CSS规则   规则即指令,其声明了需要修改的元素及要应用给元素的样式.     2.2 为文档添加样式的三种方法   行内样式:直接写在HTML文档标签中的style属性当中,行内元素只 ...

  8. Vuex教程简单实例

    什么是Vuex? vuex是一个专门为vue.js设计的集中式状态管理架构.状态?我把它理解为在data中的属性需要共享给其他vue组件使用的部分,就叫做状态.简单的说就是data中需要共用的属性. ...

  9. sass使用中出现的问题

    问题一:ruby按照官方文档安装后更换gem源时,报错Error fetching https://gems.ruby-china.org/: bad response Not Found 404 ( ...

  10. linux -- 扩容 /home 空间( xfs文件系统分区扩容指定挂载点)

    问题: /home空间容量不够使用,扩容卷组,扩容挂载点 方法: 1. 确认有可用的物理磁盘 fdisk -l -- 查看磁盘信息 df -h -- 查看当前挂载信息 vgs -- 查看当前卷组信息 ...