黑马程序员C++系统班学习笔记(一)——Linux操作系统一

黑马程序员C++系统班链接:https://www.bilibili.com/video/av37403127?from=search&seid=5509409937472093685

本笔记旨在记录学习过程中的收获,内容均来自于黑马程序员C++系统班课程。

一、 Linux目录结构介绍(我所使用的为Ubuntu 16.04)

1、绝对路径与相对路径

绝对路径:“ / ”

相对路径:指目标目录相对于当前目录的位置     “ . ” 表示当前目录   、 “ .. ”表示上一级目录

2、目录结构

/ :根目录

/bin :可执行二进制文件的目录(放工具)常用命令有  ls 、tar、mv、cat

/boot :内核文件

/dev :设备文件

/etc :配置文件

/home :家目录

/lib :库函数(放库文件)

/usr/include :头文件

二、文件权限说明

1、文件类型(五种)    命令行输入: ls -l(以树状图形式查看)
      例如:-rw-r--r--  1 cubot cubot     8980 6月  10  2018 examples.desktop
                 drwxrwxr-x 13 cubot cubot     4096 1月   2 20:49 LIN

(1)第一个字母代表文件的类型     

           -:普通文件

          d :文件夹

           l :链接文件

          c : 硬件字符设备

          b :硬件块设备

          s : 管道文件

(2)后九个字母分别代表三组权限:

         文件所有者、用户者、其他用户拥有的权限

2、文件权限管理

 -r  :只读

-w :只写

-x : 执行

三、Linux命令格式

(1)command [-options][parameter]

          说明:command:命令名,相应功能的英文单词或单词的缩写

           [-options]:选项,可用来对命令进行控制,也可以省略,[]代表可选

           parameter:传给命令的参数,可以是零个一个或多个

(2)查看帮助文档:--help 或者 man

(3)自动补全功能:TAB键

(4)历史命令:当系统执行过一些命令后,可按上下键翻看以前的命令,history将执行过的命令列举出来。

四、常用命令

(1)查看文件信息:ls

ls -a :显示指定目录下所有子目录与文件,包括隐藏文件

cubot@cubot-NUC:/usr/include$ ls -a
.                   jerror.h            pwd.h
..                  jmorecfg.h          python2.7
aio.h               jpegint.h           python3.5
aliases.h           jpeglib.h           python3.5m
alloca.h            KHR                 rdma
argp.h              lame                re_comp.h
argz.h              langinfo.h          regex.h

ls -l  :以列表方式显示文件的详细信息

cubot@cubot-NUC:/usr/include$ ls -l
total 3076
-rw-r--r--   1 root root   7441 1月  15  2018 aio.h
-rw-r--r--   1 root root   2031 1月  15  2018 aliases.h
-rw-r--r--   1 root root   1203 1月  15  2018 alloca.h
-rw-r--r--   1 root root  25303 1月  15  2018 argp.h
-rw-r--r--   1 root root   7117 1月  15  2018 argz.h
-rw-r--r--   1 root root   1730 1月  15  2018 ar.h
drwxr-xr-x   2 root root   4096 6月  10  2018 arpa
drwxr-xr-x   2 root root   4096 12月 22 13:31 asm-generic

ls -h :配合 -l 以人性化的方式显示文件大小

cubot@cubot-NUC:/usr/include$ ls -l -h
total 3.1M
-rw-r--r--   1 root root 7.3K 1月  15  2018 aio.h
-rw-r--r--   1 root root 2.0K 1月  15  2018 aliases.h
-rw-r--r--   1 root root 1.2K 1月  15  2018 alloca.h
-rw-r--r--   1 root root  25K 1月  15  2018 argp.h
-rw-r--r--   1 root root 7.0K 1月  15  2018 argz.h
-rw-r--r--   1 root root 1.7K 1月  15  2018 ar.h
drwxr-xr-x   2 root root 4.0K 6月  10  2018 arpa
drwxr-xr-x   2 root root 4.0K 12月 22 13:31 asm-generic
 

注:反斜杠:将转移字符转化为普通字符 

(2)输出重定向命令:>

Linux允许将命令执行结果重定向到一个文件,本应显示在终端上的内容保存到指定文件中。

cubot@cubot-NUC:~/LIN$ ls >text.txt(如果text.txt不存在,则创建,存在则覆盖其内容)
cubot@cubot-NUC:~/LIN$ ls

cubot@cubot-NUC:~/LIN$ gedit text.txt
保存在指定的text.txt中

10-22
10-22.zip
32.png
PNP
qipange
runClion.sh
text.txt

cubot@cubot-NUC:~/LIN$ ls >>text.txt
保存上一次的内容,再重新保存到指定文件中

10-22
10-22.zip
32.png
PNP
qipange
runClion.sh
text.txt
10-22
10-22.zip
32.png
PNP
qipange
runClion.sh
text.txt

(3) 分屏显示:more

查看内容时,在信息过长无法在一屏上显示时,会出现快速滚屏,使得用户无法看清文件的内容,此时可以使用more命令,每次只显示一页,按下空格键可以显示下一页,按下q键退出显示,按下h键可以获取帮助。

cubot@cubot-NUC:/usr/include$ more stdio.h 
/* Define ISO C stdio on top of C++ iostreams.
   Copyright (C) 1991-2016 Free Software Foundation, Inc.
   This file is part of the GNU C Library.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.
cubot@cubot-NUC:/usr/include$ q
The program 'q' can be found in the following packages:
 * python-q-text-as-data
 * python3-q-text-as-data
Try: sudo apt install <selected package>

 (4)管道:l

管道:一个命令的输出可以通过管道做为另一个命令的输入。

cubot@cubot-NUC:/usr/include$ ls | grep std
libyasm-stdint.h
stdc-predef.h
stdint.h
stdio_ext.h

管道我们可以理解现实生活中的管子,管子的一头塞东西进去,另一头取出来,这里 ”|“的左右分为两端,左端塞东西(写),右端取东西(读)。  

cubot@cubot-NUC:/bin$ ls -alh | more
total 13M
drwxr-xr-x  2 root root  4.0K 11月 29 11:34 .
drwxr-xr-x 24 root root  4.0K 12月 22 13:31 ..
-rwxr-xr-x  1 root root 1014K 5月  16  2017 bash
--More--

(5)清屏:clear

clear作用为清除终端上的显示,也可以使用快捷键:ctrl+l

(6)切换工作目录:cd

在使用Linux的时候,经常需要更换工作目录,cd命令可以帮助用户切换工作目录,Linux所有的目录和文件名大小写敏感。

cd后面可跟绝对路径,也可跟相对路径。如果省略目录,则默认切换到当前用户的主目录。

cd    :切换到当前用户的主目录(/home/用户目录),用户登录的时候,默认的目录就是用户的主目录。

cubot@cubot-NUC:~$ cd /home/

cd ~ :切换到当前用户的主目录(/home/用户目录)

cubot@cubot-NUC:/home$ cd ~

cubot@cubot-NUC:/$

cd .  :切换到当前目录

cubot@cubot-NUC:~$ cd /home/
cubot@cubot-NUC:/home$ cd .

cubot@cubot-NUC:/home$

cd ..  :切换到上级目录

cubot@cubot-NUC:/home$ cd ..

cubot@cubot-NUC:/$

cd -   :可进入上一个进入的目录
cubot@cubot-NUC:/$ cd -
/home
cubot@cubot-NUC:/home$ 

(7)显示当前路径:pwd 

使用pwd命令可以显示当前的工作目录,该命令很简单,直接输入pwd即可。

cubot@cubot-NUC:/home$ cd /usr/include/
cubot@cubot-NUC:/usr/include$ pwd

/usr/include

猜你喜欢

转载自blog.csdn.net/weixin_42694430/article/details/85763382