本节主要内容

  1. 怎样获取帮助文档
  2. Linux文件系统简单介绍
  3. 文件夹操作
  4. 訪问权限

1. 怎样获取帮助文档

在实际工作过程其中,常常会忘记命令的使用方式。比如ls命令后面能够跟哪些參数,此时能够使用man命令来查看其使用方式。比如

//man命令获取命令帮助手冊
xtwy@ubuntu:~$ man ls

能够使用键盘上的 来显示下一行或上一行命令,也能够使用 进行上一页或下一页(屏)命令的查看,另外 空格鍵也能够用来显示下一屏的命令。想退出命令查看,直接按q鍵退出就可以。也能够h鍵显示less命令列表(man命令通过less命令输出结果)

2. Linux文件系统简单介绍

(一) 文件和文件夹

本节从使用者的角度来介绍Linux文件系统,Linux依据文件形式将文件分为文件夹和普通文件,例如以下图:

文件夹或文件的名称长度不超过255个字符,文件或文件夹名可由下列字符构成:

  • Uppercase letters (A–Z)
  • Lowercase letters (a–z)
  • Numbers (0–9)
  • Underscore ( _ )
  • Period(.)
  • Comma(,)
    文件或文件夹名区分大写和小写,属于不同的文件或文件夹

(二) 文件扩展名与不可见文件名称

与Window操作系统有非常大不同的是。Linux文件对文件扩展名没有强制要求。比如假设编写了一个c语言源文件,你能够将其命名为complier.c,也能够是其他如complier、complier.ccc等文件名称。但不推荐这么做,由于假设能将文件扩展名与特定的文件进行关联的话。有利于理解文件内容,眼下约定成俗的linux文件扩展名例如以下表:

带扩展名的文件名称 扩展名的含义
max.c C语言源文件
max.o 编码后的目标代码文件
max max.c相应的可运行文件
memo.txt 文本文件
memo.pdf pdf文件。必须在GUI界面上使用xpdf或kpdf才干查看
memo.ps PostScript文件。必须在GUI界面上使用ghostscript或kpdf才干查看
memo.z 经压缩程序压缩后的文件,可使用uncompress或gunzip解压
memo.gz 经gzip压缩程序压缩后的文件,可使用gunzip解压
memo.tar.gz或memo.tgz 经gzip压缩后的tar归档文件,可使用gunzip解压
memo.bz2 经bzip2压缩后的文件,可使用bunzip2解压
memo.html html文件。使用GUI环境的firefox查看
memo.jpg等 图像文件,使用GUI环境的照片查看器打开

在前一讲中我们看到。linux中还存在大量的隐藏文件。採用ls -a 命令能够显示。想定义隐藏文件。仅仅要文件名称或文件夹以.開始就可以

(三) 绝对路径与相对路径

在Linux中绝对路径与相对路径是一个非常重要的概念。下图给出了什么是绝对路径

全部以根文件夹”/”作为開始的都是绝对路径,其他的均为相对路径

//绝对路径訪问
xtwy@ubuntu:~/Public$ cd /home/
xtwy@ubuntu:/home$ ls
xtwy
//相对路径訪问
xtwy@ubuntu:/home$ cd xtwy/

3. 文件夹操作

(一) 创建文件夹 mkdir

为演示方便,使用下列文件夹结构进行演示:

1 绝对路径创建方式

//使用绝对路径创建
root@ubuntu:/home# mkdir /home/max
root@ubuntu:/home# ls
max  xtwy
root@ubuntu:/home# 

2 相对路径创建方式

//使用相对路径进行创建
root@ubuntu:/home# mkdir max/names
root@ubuntu:/home# mkdir max/temp
root@ubuntu:/home# mkdir max/literature
root@ubuntu:/home# cd max
root@ubuntu:/home/max# mkdir demo
root@ubuntu:/home/max# ls
demo  literature  names  temp

有时不想层层文件夹创建。此时能够在mkdir 后面加上參数 -p(parents)。将父子文件夹一起创建

root@ubuntu:/home/max# mkdir -p literature/promo
root@ubuntu:/home/max# ls
demo  literature  names  temp
root@ubuntu:/home/max# cd literature/
root@ubuntu:/home/max/literature# ls
promo

(二) 更改文件夹 cd

工作文件夹与主文件夹的区别
用户每次登录后的默认文件夹就是主文件夹,与系统会话期间保持不变,主文件夹用~表示

xtwy@ubuntu:/root$ cd ~
xtwy@ubuntu:~$ pwd
/home/xtwy

工作文件夹又称当前文件夹,cd命令运行完毕后的文件夹就是工作文件夹,它是能够任意改变的。

//.表示当前文件夹即工作文件夹
//..表示当前文件夹的上一级文件夹
xtwy@ubuntu:~$ cd .
xtwy@ubuntu:~$ cd ..
xtwy@ubuntu:/home$

(三) 删除文件夹 rmdir

rmdir是remove directory的简称,用于删除文件夹,它先删除文件夹下的全部文件,然后再删除该文件夹,但当文件夹下还有子文件夹时。该命令不能运行。须要使用rm命令,比如

//删除temp文件夹,先删除文件夹下的文件
//再删除temp文件夹自身
root@ubuntu:/home/max# rmdir temp/
root@ubuntu:/home/max# rmdir literature/
rmdir: failed to remove `literature/': Directory not empty
root@ubuntu:/home/max# rm -r literature/
root@ubuntu:/home/max# ls
demo  names

其中rm -r中的r指的是递归的删除文件夹及文件夹中的文件,因此它具有非常强的破坏力,要慎重使用。

(四) 移动文件夹 mv

//将文件夹demo移到/home/xtwy/文件夹下
root@ubuntu:/home/max# mv demo/ /home/xtwy/
root@ubuntu:/home/max# cd /home/xtwy/
root@ubuntu:/home/xtwy# ls
demo     Documents  examples.desktop  Pictures  Templates
Desktop  Downloads  Music             Public    Videos
root@ubuntu:/home/xtwy# rmdir demo
//原来文件夹的demo文件夹已经不存在了
root@ubuntu:/home/xtwy# cd /home/max/
root@ubuntu:/home/max# ls
names

(五) 拷贝文件夹 cp

前面用mv命令移动文件夹,有时候须要对文件夹进行拷贝,使用方式例如以下:

//先创建一个演示文件夹。用-p,父文件夹假设不存在将会被创建
root@ubuntu:/home/max# mkdir -p literature/demo
//由于literature还包含子文件夹,此时拷贝不成功
root@ubuntu:/home/max# cp literature/ /home/xtwy/
cp: omitting directory `literature/'
//假设包含子文件夹的话,则加上-r參数,表示递归地拷贝
root@ubuntu:/home/max# cp -r literature/ /home/xtwy/
root@ubuntu:/home/max# cd /homt
bash: cd: /homt: No such file or directory
root@ubuntu:/home/max# cd /home/xtwy/
root@ubuntu:/home/xtwy# ls
Desktop    Downloads         literature  Pictures  Templates
Documents  examples.desktop  Music       Public    Videos
root@ubuntu:/home/xtwy# cd literature/
root@ubuntu:/home/xtwy/literature# ls
demo

4. 文件操作

(一) 创建文件

直接通过命令行的方式创建文件的方式有多种,常常使用方式例如以下:

//通过echo命令。将输出的命令重定向到文件
root@ubuntu:/home/xtwy# echo "hello linux" > hello.txt
root@ubuntu:/home/xtwy# ls
Desktop    Downloads         hello.txt   Music     Public     Videos
Documents  examples.desktop  literature  Pictures  Templates
//touch命令。怎样文件不存在。会创建文件
root@ubuntu:/home/xtwy# touch hell1.txt
root@ubuntu:/home/xtwy# ls
Desktop    Downloads         hell1.txt  literature  Pictures  Templates
Documents  examples.desktop  hello.txt  Music       Public    Videos

(二) 显示文件内容

cate命令能够显示文件内容。它的全称是catenate。意思是将单词一个接一个地连接起来

root@ubuntu:/home/xtwy# cat hello.txt
hello linux

cat命令会将文件里全部的内容全部一次性显示出现,比如

root@ubuntu:/home/xtwy# cat /etc/profile
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).if [ -d /etc/profile.d ]; thenfor i in /etc/profile.d/*.sh; doif [ -r $i ]; then. $ifidoneunset i......

有时候我们希望能够分屏查看文件内容,此时能够使用less或more分页程序。less和more的使用方式相差不大,通过空格键显示下一屏信息,它们之间的区别在于less在文件末尾会显示END消息,而more直接返回shell终端。比如:
less命令

more命令

(三) cp命令拷贝文件

root@ubuntu:/home/xtwy# ls
Desktop    Downloads         hell1.txt  literature  Pictures  Templates
Documents  examples.desktop  hello.txt  Music       Public    Videos
//拷贝文件
root@ubuntu:/home/xtwy# cp hell1.txt literature/demo
root@ubuntu:/home/xtwy# cd literature/demo
//cd -返回上一次运行的工作文件夹
root@ubuntu:/home/xtwy/literature/demo# cd -
/home/xtwy

须要注意的是cp命令在复制时,假设目标文件夹中已存在该文件,系统不会给出警告,而是直接覆盖。因此它可能存在销毁文件的风险,为解决问题能够使用-i參数让系统给出警告,比如:

root@ubuntu:/home/xtwy# cp -i hell1.txt literature/demo
cp: overwrite `literature/demo/hell1.txt'?

(三) mv命令移动或重命名文件

//在同一文件夹时,相当于文件重命名,运行完毕后hell1.txt不存在
root@ubuntu:/home/xtwy# mv hell1.txt hell2.txt
root@ubuntu:/home/xtwy# ls
Desktop    Downloads         hell2.txt  literature  Pictures  Templates
Documents  examples.desktop  hello.txt  Music       Public    Videos
//移动hell2.txt到literature/demo
root@ubuntu:/home/xtwy# mv hell2.txt literature/demo
root@ubuntu:/home/xtwy# cd literature/demo/
root@ubuntu:/home/xtwy/literature/demo# ls
hell1.txt  hell2.txt
root@ubuntu:/home/xtwy/literature/demo# cd -
/home/xtwy
//源文件夹hell2.txt已不存在
root@ubuntu:/home/xtwy# ls
Desktop    Downloads         hello.txt   Music     Public     Videos
Documents  examples.desktop  literature  Pictures  Templates

(四)显示文件头部或尾部

显示文件头部内容用head命令。尾部用tail命令,默认显示行数为10

root@ubuntu:/home/xtwy# head ~/.bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples# If not running interactively, don't do anything
[ -z "$PS1" ] && return# don't put duplicate lines in the history. See bash(1) for more options
# ... or force ignoredups and ignorespace
HISTCONTROL=ignoredups:ignorespace
root@ubuntu:/home/xtwy# tail ~/.bashrc
if [ -f ~/.bash_aliases ]; then. ~/.bash_aliases
fi# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
#if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
#    . /etc/bash_completion
#fi

head及tail的默认行数是能够改动的,比如:

//仅显示前两行
root@ubuntu:/home/xtwy# head -2 ~/.bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)

tail命令在查看日志文件内容增长时可能常常会使用,比如在hadoop启动之后,会产生很多日志,但出现故障时,能够採用tail命令动态地监測日志文件内容的增长。查看问题出在哪个地方。

//初始显示情况
root@ubuntu:/home/xtwy# tail -f hello.txt
hello linux//向文件里追加内容
root@ubuntu:/home/xtwy# echo "hello linux linux" >> hello.txt//追加后的输出情况
root@ubuntu:/home/xtwy# tail -f hello.txt
hello linux
hello linux linux

(五)其他常见文件操作命令

以下的命令都不会改变文件内容

root@ubuntu:/home/xtwy# cp hello.txt hello1.txt
root@ubuntu:/home/xtwy# ls
Desktop    Downloads         hello1.txt  literature  Pictures  Templates
Documents  examples.desktop  hello.txt   Music       Public    Videos
//依据文件内容排序
root@ubuntu:/home/xtwy# sort hello1.txt
hello linux
hello linux linux
//逆序输出
root@ubuntu:/home/xtwy# sort -r  hello1.txt
hello linux linux
hello linux
//diff进行内容比較
root@ubuntu:/home/xtwy# diff hello1.txt hello.txt
//向文件里追加内容
root@ubuntu:/home/xtwy# echo "hello linux linux" >> hello.txt
//内容比較
root@ubuntu:/home/xtwy# diff hello1.txt hello.txt
2a3
> hello linux linux
//格式化输出
//-u參数将文件分成多块
//比較的两个文件分别用-、+表示
//本例中 -表示hello1.txt,+表示hello.txt
root@ubuntu:/home/xtwy# diff -u hello1.txt hello.txt
--- hello1.txt  2015-08-22 17:28:44.071202558 -0700
+++ hello.txt   2015-08-22 17:29:49.131181281 -0700
//@@xxx@@用于标识行起始编号、行数
//-1,2表示 hello1.txt文件起始编号为1,行数为2
//+1,3表示 hello.txt文件起始编号为1。行数为3
@@ -1,2 +1,3 @@hello linuxhello linux linux
+hello linux linux

加入公众微信号。能够了解很多其他最新Spark、Scala相关技术资讯

转载于:https://www.cnblogs.com/gccbuaa/p/7145666.html

Spark修炼之道(基础篇)——Linux大数据开发基础:第二节:Linux文件系统、文件夹(一)...相关推荐

  1. 大数据开发成长之路——Linux基础

    Linux基础 这里主要介绍学习大数据过程中用到的Linux基础知识,现在主攻的方向是大数据开发,欢迎大家共同交流. 环境 推荐安装VMware虚拟机并安装CentOS操作系统,具体资源的下载和安装可 ...

  2. 大数据开发基础入门与项目实战(三)Hadoop核心及生态圈技术栈之5.即席查询Impala介绍及入门使用

    文章目录 前言 1.Impala概述 (1)Impala的概念和优势 (2)Impala的缺点及适用场景 2.Impala的安装与入门 (1)准备工作 (2)制作本地yum源 (3)安装Impala ...

  3. 大数据入门培训之大数据开发基础知识学习

    在目前相信大多数IT开发人员对于人工智能+大数据并不陌生,使用的场景也越来越广,日常开发中前端同学也逐渐接触了更多与大数据相关的开发需求.因此对大数据知识也有必要进行一些学习理解,带大家来学习了解一下 ...

  4. 零基础能学大数据开发吗 可以从哪些方面入手

    大数据作为当下呼声特别高的IT技术,想学大数据的朋友已经从一个变成两个,从两个变成三个,但是计数单位,也是从个到百到千到万到亿,接下来还可能更高.零基础能学大数据吗?郑州大数据培训哪家好? 面对这个问 ...

  5. 大数据开发基础入门与项目实战(一)Java SE之1.初识计算机和Java语言

    文章目录 前言 1.计算机的体系结构 (1)计算机的基本概念 (2)常见的主要硬件 (3)主要硬件的详解 Ⅰ CPU Ⅱ 内存 Ⅲ 硬盘 Ⅳ 输入输出设备 (4)常见的主要软件 (5)计算机的体系结构 ...

  6. Hadoop大数据开发基础项目化教程

    项目一 大数据时代 大数据定义: 所谓大数据( Big Data ),或称巨量资料,指的是"所涉及的资料量规模巨大到无法通过 目前主流软件工具,在合理时间内达到撷取.管理.处理.并整理成为帮 ...

  7. Hadoop大数据开发基础

    项目一:大数据时代 大数据定义: 所谓大数据( Big Data ),或称巨量资料,指的是"所涉及的资料量规模巨大到无法通过 目前主流软件工具,在合理时间内达到撷取.管理.处理.并整理成为帮 ...

  8. 两个读书笔记:springboot+vue.js分布式组件全栈开发训练营 + 大数据开发基础

    (springboot+vue.js分布式组件全栈开发训练营原文在notion中, 大数据开发在思维导图中, 这个博客只是保存, 无法阅读. ) what is different between s ...

  9. 大数据开发基础入门与项目实战(二)Java Web数据可视化之3.Linux概述、安装和结构

    文章目录 前言 1.Linux概述 (1)Linux简介 (2)Linux的应用领域及版本介绍 2.安装Linux (1)VMWare的安装 (2)使用VMWare构建虚拟机器 (3)安装CentOS ...

最新文章

  1. XGBOOST带试验源码
  2. 前端开发应届生面试指南(含各大公司具体指南及面试真题)
  3. 未将对象引用设置到对象的实例
  4. python商务图表_Excel职场商务图表高效制作
  5. ThreadLocal可能引起的内存泄露
  6. 机器人编程与python语言的区别_一分钟看懂“机器人编程”和“少儿编程”的区别!...
  7. LwIP应用开发笔记之五:LwIP无操作系统TCP服务器
  8. c语言树莓派音乐播放器,使用web端来控制我的树莓派播放音乐
  9. lingo入门(数据部分)
  10. datetime数据类型_当pandas遇上数据类型问题
  11. ES6学习笔记六(新增数据结构)
  12. mysql5.5.53安装教程_mysql5.5.28安装教程 超详细!
  13. 鸿蒙不是手机系统?智慧屏曝光,华为将布局“贾维斯”智能时代
  14. 谈腾讯地图web api如何实现类似百度地图内置的城市切换、关键字输入提示功能
  15. skywang的博客目录(持续更新中...)
  16. 组织机构、权限、角色设计
  17. 【网络设备】Cisco路由器密码重置及配置
  18. C++搜索算法和曼哈顿距离之最少连通代价
  19. 详细解析STM32的时钟系统
  20. IT行业都有哪些职位?工作内容及升职路线

热门文章

  1. ffmpeg转码器移植VC的工程:ffmpeg for MFC
  2. ActionScript 3.0 API 中的 Video 类
  3. 6种java垃圾回收算法_学习java垃圾回收
  4. macOS下JetBrains配置修改错误导致无法启动解决方案
  5. Element Form表单布局(一行多列)
  6. linux中找到最耗CPU的那段Java代码
  7. 解决 GitHub 拉取代码网速慢的问题
  8. datagrid combobox 选择后显示valueField 而不是 textValue解决方法
  9. NYOJ101 - 两点距离
  10. linux 编程 调度,Linux的进程线程及调度