linux知识

来源:互联网 发布:淘宝流失金额多少正常 编辑:程序博客网 时间:2024/06/06 03:36

X window与文本模式的切换

  • [Ctrl] + [Alt] + [F1] ~ [F6] :文字接口(tty1 ~ tty6)
  • [Ctrl] + [Alt] + [F7] :图形接口(gnome/kde)

在Linux默认的登陆模式中,主要分为两种:

  • 一种是仅有纯文本接口(所谓的运行等级run level 3)的登陆环境,在这种环境中你可以有tty1~tty6的终端界面,但是并没有图形窗口接口的环境。
  • 另一种则是图形接口的登陆环境(所谓的运行等级run level 5)。在这个环境中你就具有tty1~tty7。

lmz:图形界面中可以启动文字界面,文字界面也可以启动图形界面。

 startx 

不过startx这个命令并非万灵丹,你要让startx生效至少需要其他几件事情的配合。

Linux默认提供了七个Run level给我们使用,其中最常用到的就是run level 3与run level 5这两者了。 如果你想要让Linux在下次启动时使用纯文本环境(run level 3)来登陆, 只要修订一下/etc/inittab这个文件的内容,就能够在下次重新启动时生效了!

shell变量

  • 变量的取用与取消
name=VBirdecho $nameunset name  (取消刚刚配置的 name 这个变量内容)
  • 用 env 观察环境变量与常见环境变量说明

    • HISTSIZE
    • MAIL
    • LANG
  • 用 set 观察所有变量 (含环境变量与自定义变量)

    • $:(关于本 shell 的 PID)
    • ?:(关于上个运行命令的回传值)
  • export: 自定义变量转成环境变量
    变量分为自定义变量和环境变量,两者的主要区别在于:该变量是否会被子程序所继续引用。
    子程序仅会继承父程序的环境变量, 子程序不会继承父程序的自定义变量。

export 变量名称  //将自定义变量转为环境变量export           //显示出所有的环境变量

lmz:可以将自定义变量当做局部变量,将环境变量当做全局变量。
可以进一步思考,这两种变量类型的区别在什么地方?
这两个变量在内存中的区域不一样!

su

su [-lm] [-c 命令] [username]

选项与参数:
__- :单纯使用 - 如『 su - 』代表使用 login-shell 的变量文件读取方式来登陆系统;
若使用者名称没有加上去,则代表切换为 root 的身份__。
-l :与 - 类似,但后面需要加欲切换的使用者账号!也是 login-shell 的方式。
-m :-m 与 -p 是一样的,表示『使用目前的环境配置,而不读取新使用者的配置文件』
-c :仅进行一次命令,所以 -c 后面可以加上命令!

su :切换成为 root 的身份,读取的变量配置方式为 non-login shell 的方式
su -:切换成为 root 的身份,读取的变量配置方式为 login shell 的方式

单纯使用su切换成为 root 的身份,读取的变量配置方式为 non-login shell 的方式,这种方式很多原本的变量不会被改变, 尤其是我们之前谈过很多次的 PATH 这个变量,由于没有改变成为 root 的环境 (一堆 /sbin, /usr/sbin 等目录都没有被包含进来), 因此很多 root 惯用的命令就只能使用绝对路径来运行。

那我如果只是想要运行一个只有 root 才能进行的命令,且运行完毕就恢复原本的身份呢?那就可以加上 -c 这个选项:

su - -c "head -n 3 /etc/shadow"          需要输入root密码

su用法总结:

  • 切换用户。切记要用su - username
  • 运行命令。su - -c "command",需要root密码。与su command区分,需要用户密码。

sudo

sudo [-b] [-u 新使用者账号]

选项与参数:
-b :将后续的命令放到背景中让系统自行运行,而不与目前的 shell 产生影响
-u :后面可以接欲切换的使用者,若无此项则代表切换身份为 root 。

当我的主机是多人共管的环境时,如果大家都要使用 su 来切换成为 root 的身份,那么不就每个人都得要知道 root 的口令,这样口令太多人知道可能会流出去。
sudo 可以让你以其他用户的身份运行命令 (通常是使用 root 的身份来运行命令)。
并非所有人都能够运行 sudo , 而是仅有规范到 /etc/sudoers 内的用户才能够运行 sudo

sudo 的运行流程:

  • 当用户运行 sudo 时,系统于 /etc/sudoers 文件中搜寻该使用者是否有运行 sudo 的权限;
  • 若使用者具有可运行 sudo 的权限后,便让使用者『输入用户自己的口令』来确认;
  • 若口令输入成功,便开始进行 sudo 后续接的命令(但 root 运行 sudo 时,不需要输入口令);
  • 若欲切换的身份与运行者身份相同,那也不需要输入口令。

login与non-login shell

login shell:取得 bash 时需要完整的登陆流程的,就称为 login shell。

  • tty1 ~ tty6 登陆,需要输入用户的账号与密码,此时取得的 bash 就称为login shell;

non-login shell:取得 bash 接口的方法不需要重复登陆的举动

  • 以 X window 登陆 Linux 后, 再以 X 的图形化接口启动终端机,此时那个终端接口并没有需要再次的输入账号与密码,那个 bash 的环境就称为 non-login shell了。
  • 在原本的 bash 环境下再次下达 bash 这个命令,同样的也没有输入账号密码, 那第二个 bash (子程序) 也是 non-login shell 。

这两个取得 bash 的情况中,读取的配置文件数据并不一样所致。

login shell会读取这两个配置文件

  1. /etc/profile:这是系统整体的配置,你最好不要修改这个文件;
  2. ~/.bash_profile 或 ~/.bash_login 或 ~/.profile:属于使用者个人配置,你要改自己的数据,就写入这里!

lmz:

  • bash 的 login shell 整体环境配置文件其实只有 /etc/profile,但是 /etc/profile 还会呼叫出其他的配置文件。
  • bash 的 login shell 个人环境配置文件只会读取上面三个文件的其中一个, 而读取的顺序则是依照上面的顺序。

non-login shell仅会读取 ~/.bashrc

interactive与non-interactive shell

交互shell从用户在终端(tty/pts)下读取输入的命令, 执行并返回结果.
非交互shell一般是执行的shell脚本等, 可以在后台执行.

A shell running a script is always a non-interactive shell, but the script can emulate an interactive shell by prompting the user to input values.

source与.

我们登录login shell的过程中一般都会读取/etc/profile与~/.bash_profile文件,如果登陆成功后又修改了这两个文件,要使这些修改的配置文件生效一般都会需要重新登陆。现在提供一种不许需要重新登陆就能使配置文件生效的办法(选其一):

source 配置文件. 配置文件

/etc folder

etc目录详解

THE HISTORY OF /ETC FOLDER IN LINUX/UNIX

In initial days of UNIX OS development there is a folder for each type of data like /bin folder for all your executable binaries

/boot folder for all booting related information.

/dev folder for all hardware devices attached to machine.

But people encountered a situation to keep some files which can be a config file or a data file or a socket file or some other files. So they implemented a folder to keep all these files in it and they named it as /etc(As said earlier etcetera). As time passed the meaning of this folder has changed but not the name “etc”. Now /etc folder means a central location for all your configuration files are located and this can be treated as nerve centre of your Linux/Unix machine.

/ETC FOLDER CONTENT CAN BE DIVIDED INTO FOLLOWING GROUPS

1)Configuration tables(tab like crontab, fstab, mtab etc)2)Running Configurations(rc like rc.local, rc1.d, bashrc, wgetrc etc)3)Configuration files(conf/cfg like pam.conf, ntp.conf etc)4)Deny/Allow files()5)Other directories6)Other Files

1. TABLE FILES (THE _TAB) IN /ETC FOLDER IN LINUX_

These are the files which end with tab or start with tab(which is short form of table) such as crontab, fstab, inittab etc. These files main intention is to keep a table of content for their corresponding settings.

/etc/inittab –Contains what are the run-levels, what system have to do at each run-level and default run-level info.

2. RUNNING CONFIGURATION FILES(_RC) IN /ETC FOLDER_

These are again a type of config files which will force a service to start/stop, for a user to use specific environment etc.

/etc/bash.bashrc –System wide bash shell running configuration file.

/etc/nanorc –Nano editor running configurations

rc0.d, rc1.d, rc2.d, rc3.d, rc4.d, rc5.d, rc6.d, rcS.d –running configurations like what services has to start and stop for each run level from zero to six. If you observe rcS.d this folder is same as rc1.d folder which means Single run level.

/etc/rc.local –This file contains commands which need to be executed after completing booting. we can edit this file and keep the commands which we want to execute at the time of booting.

vimrc –VIEW Improved editor system level configuration is stored here.

wgetrc –wget related running configurations.

3. __CONF__IG FILES IN /ETC FOLDER

These are the main configuration files for many applications installed in your machine. These files are text files which can be edited with editors like VI editor so that applications works according to your requirement.

/etc/asound.conf –Configuration file for your speakers and audio devices.

/etc/dnsmasq.conf –DNS client related configuration file

/etc/exports –NFS share configuration file. In this file we will share our local folder to a specific IP address or network with different.

/etc/grub.conf –Main configuration file for grub boot loader

/etc/shadow –User login password hashes are stored here.

/etc/group –User groups information such as which user belongs to which group, what is GID etc.

/etc/passwd –User configurations such as user login name, shell, UID and GID are stored here.

/etc/my.cnf –Mysql configuration file.

/etc/hosts –Hosts to IP address mapping file, This is mother of all name to IP matching files.

/etc/resolv.conf –DNS and domain client configuration file. With out proper DNS server in this file, we can not access internet.

4. DENY/ALLOW FILES IN /ETC FOLDER

These are the files which contain what users are allowed/denied for particular service, what IP address are allowed/denied to access our services etc.

linux启动

GPL

The GNU General Public License (GNU GPL or GPL) is a widely used free software license, which guarantees end users the freedom to run, study, share and modify the software.[6] The license was originally written by Richard Stallman of the Free Software Foundation (FSF) for the GNU Project, and grants the recipients of a computer program the rights of the Free Software Definition.[7] The GPL is a copyleft license, which means that derivative work can only be distributed under the same license terms. This is in distinction to permissive free software licenses, of which the BSD licenses and the MIT License are widely used examples. GPL was the first copyleft license for general use.

GNU Project

The GNU Project is a free software, mass collaboration project, announced on September 27, 1983, by Richard Stallman at MIT. Its aim is to give computer users freedom and control in their use of their computers and computing devices, by collaboratively developing and providing software that is based on the following freedom rights: users are free to run the software, share it (copy, distribute), study it and modify it. GNU software guarantees these freedom-rights legally (via its license), and is therefore free software; the use of the word “free” always being taken to refer to freedom.

GNOME

GNOME is a desktop environment that is composed entirely of free and open-source software. GNOME was originally an acronym for GNU Network Object Model Environment. Its target operating system is Linux, but it is also supported on most derivatives of BSD.[8]

GNOME is developed by The GNOME Project, which is composed of both volunteers and paid contributors, the largest corporate contributor being Red Hat.[9][10] It is an international project that aims to develop software frameworks for the development of software, to program end-user applications based on these frameworks, and to coordinate efforts for internationalization and localization and accessibility of that software.

GNOME is part of the GNU Project.[11]

lmz:GNOME Ubuntu和KDE Ubuntu是两个不同的桌面环境。

在默认设置下,KDE注重绚丽的特效效果,界面类似于Win7;而Gnome更注重性能,是Redhat、Centos的默认用户界面。ubuntu的默认用户界面是unity。

swap file

A swap file (or swap space or, in Windows NT, a pagefile) is a space on a hard disk used as the virtual memory extension of a computer’s real memory (RAM). Having a swap file allows your computer’s operating system to pretend that you have more RAM than you actually do. The least recently used files in RAM can be “swapped out” to your hard disk until they are needed later so that new files can be “swapped in” to RAM. In larger operating systems (such as IBM’s OS/390), the units that are moved are called pages and the swapping is called paging.

virtual memory

Virtual memory is a feature of an operating system (OS) that allows a computer to compensate for shortages of physical memory by temporarily transferring pages of data from random access memory (RAM) to disk storage.


Eventually, the OS will need to retrieve the data that was moved temporarily to disk storage – but remember, the only reason the OS moved pages of data from RAM to disk storage was that it was running out of RAM. To solve the problem, the operating system will need to move other pages to hard disk so it has room to bring back the pages it needs right away. This process is known as paging or swapping and the temporary storage space on the hard disk is called a pagefile or a swap file.

发行版分类

两类:

  • 商业公司维护的发行版本,Redhat(RHEL)
  • 社区组织维护的发行版本,Debian

Redhat,应该称为Redhat系列,包括RHEL(Redhat Enterprise Linux,也就是所谓的Redhat Advance Server,收费版本)、Fedora Core(由原来的Redhat桌面版本发展而来,免费版本)、CentOS(RHEL的社区克隆版本,免费)。

Debian,或者称Debian系列,包括Debian和Ubuntu等。Debian是社区类Linux操作系统的典范,是迄今为止最遵循GNU规范的Linux系统。Ubuntu严格来说不能算一个独立的发行版本,Ubuntu是基于Debian的unstable版本加强而来,可以这么说,Ubuntu就是一个拥有Debian所有的优点,以及自己所加强的优点的近乎完美的 Linux桌面系统。

linux kernel

目录

目录 描述 / 第一层次结构的根、整个文件系统层次结构的根目录。 /bin/ 需要在单用户模式可用的必要命令(可执行文件);面向所有用户,例如:cat、ls、cp,和/usr/bin类似。 /sbin/ 必要的系统二进制文件,例如: init、 ip、mount。sbin目录下的命令,普通用户都执行不了。 /boot/ 引导程序文件,例如:kernel、initrd;时常是一个单独的分区[6] /dev/ 必要设备, 例如:, /dev/null. /home/ 用户的家目录,包含保存的文件、个人设置等,一般为单独的分区。 /lib/ /bin/ and /sbin/中二进制文件必要的库文件。 /media/ 可移除媒体(如CD-ROM)的挂载点 (在FHS-2.3中出现)。 /mnt/ 临时挂载的文件系统。比如cdrom,u盘等,直接插入光驱无法使用,要先挂载后使用 /lost+found 在ext3文件系统中,当系统意外崩溃或机器意外关机,会产生一些文件碎片在这里。当系统在开机启动的过程中fsck工具会检查这里,并修复已经损坏的文件系统。当系统发生问题。可能会有文件被移动到这个目录中,可能需要用手工的方式来修复,或移到文件到原来的位置上。 /opt/ 可选应用软件包。 /proc/ 直接写入内存 /sys/ /root/ 超级用户的家目录 /srv/ 站点的具体数据,由系统提供。 /tmp/ 临时文件(参见 /var/tmp),在系统重启时目录中文件不会被保留。 /usr/ 默认软件都会存于该目录下。用于存储只读用户数据的第二层次;包含绝大多数的(多)用户工具和应用程序。 /var/ 变量文件——在正常运行的系统中其内容不断变化的文件,如日志,脱机文件和临时电子邮件文件。有时是一个单独的分区。如果不单独分区,有可能会把整个分区充满。如果单独分区,给大给小都不合适。

默认软件都会存于该目录下。用于存储只读用户数据的第二层次;包含绝大多数的用户工具和应用程序。

目录 描述 /usr/X11R6 存放X-Windows的目录; /usr/games 存放着XteamLinux自带的小游戏; /usr/doc Linux技术文档; /usr/include 用来存放Linux下开发和编译应用程序所需要的头文件; /usr/lib 存放一些常用的动态链接共享库和静态档案库; /usr/man 帮助文档所在的目录; /usr/src Linux开放的源代码,就存在这个目录,爱好者们别放过哦; /usr/bin/ 非必要可执行文件 (在单用户模式中不需要);面向所有用户。 /usr/lib/ /usr/bin/和/usr/sbin/中二进制文件的库。 /usr/sbin/ 非必要的系统二进制文件,例如:大量网络服务的守护进程。 /usr/share/ 体系结构无关(共享)数据。 /usr/src/ 源代码,例如:内核源代码及其头文件。 /usr/X11R6/ X Window系统版本 11, Release 6. /usr/local/ 本地数据的第三层次,具体到本台主机。通常而言有进一步的子目录,例如:bin/、lib/、share/.这是提供给一般用户的/usr目录,在这里安装一般的应用软件;

分区

磁盘磁面上有一个特别的扇区即第一个扇区,这个扇区特别是因为它记录了两个信息:

  • 磁盘分割表 ,也就是你这个磁盘的分割的相关信息,如起始磁柱,结束磁柱大小为64bytes
  • MBR(master boot record ) 即主要启动引导区,可以安装启动管理程序的地方 大小为 446bytes

主分区:最多四个
扩展分区:最多一个
主分区+扩展分区:最多四个
扩展分区里面可以继续分逻辑分区。
格式化的只要目的是写入文件系统(fat16/fat32/ntfs/ext2/ext3/ext4)。格式化干两件事:生成block与inode。

设备文件名

硬件 设备文件名 IDE硬盘 /dev/hd[a-d] SCSI/SATA/USB硬盘 /dev/sd[a-p] 光驱 /dev/cdrom或/dev/hdc 软盘 /dev/fd[0-1] 鼠标 /dev/mouse

tags:linux

0 0
原创粉丝点击