Some common Linux commands to learn Record

Some common Linux commands

ls display the target list

ls -a shows all files and directories (ls the default file name or directory name is considered shadow possession, will not be listed. "");

ls -l displays a list of directory contents in long format. From left to right output information includes a file name, file type, permissions mode, the number of hard links, owner, group, last modification time of the file size and file and the like;

https://blog.csdn.net/bearcatfly/article/details/54617095 owner, group, others concept

Common file types 

Up to a Linux file types, plain text files (the ASCII); binary (binary); file data format (Data); various compressed file a first attribute is [-]. 

Catalog file
is a directory, use # cd command entry. The first property is [d], for example [d rwx rwx rwx]

File management
FIFO is a special type of file, its main purpose is to address the multiple programs simultaneously access a file error caused. FIFO is an acronym for first-in-first-out (FIFO) is. The first property is the [p]
linked files
similar to Windows shortcuts below. The first property is [L], for example [lrwxrwxrwx]
block device file
block device file: is storing data for access to the system interface device, simply, is hard. One example hard disk code is / dev / hda1 and other documents. The first property is a [b]
character device file
character device file: the serial port interface device, such as a keyboard, a mouse, and the like. The first property is [c]
socket file
such documents are commonly used in network data connections, mainly for network communication, may be a socket communication between processes on a single host. Can start a request to listen for client, the client may communicate data through the socket. The first property is [s], most often seen in this type of file / var / run directory

 

    • man

man command help command under Linux, you can view the Linux instructions in the Help, help, and configuration file programming help and other information through the man command.

For example, man ls ls command will list on usage, and other information

/ Content to search from looking down

? Content to be searched from the bottom up to find

 

Third, the commonly used ports

 

Fourth, the pipeline |

Pipes: a command can be output as an input of another command through the pipeline.

"|" Is a command pipeline operator, referred to as the pipe character. Linux using the pipe symbol provided by the "|" two commands separated by pipe character to the left output of the command will be used as input pipe symbol to the right of command. Continuous use of pipelines means that the first command will output the second command as input, the output of the second command will enter as the third command, and so on.

For example: ls -lah | more ,,,, man ls | more

(-Lah displays all files in a directory

more命令是一个基于vi编辑器文本过滤器,它以全屏幕的方式按页显示文本文件的内容,支持vi中的关键字定位操作。more名单中内置了若干快捷键,常用的有H(获得帮助信息),Enter(向下翻滚一行),空格(向下滚动一屏),Q(退出命令)。)

 

五、ln命令

Linux ln命令是一个非常重要命令,它的功能是为某一个文件在另外一个位置建立一个同步的链接。

当我们需要在不同的目录,用到相同的文件时,我们不需要在每一个需要的目录下都放一个必须相同的文件,我们只要在某个固定的目录,放上该文件,然后在 其它的目录下用ln命令链接(link)它就可以,不必重复的占用磁盘空间。

 

六、 vi 文本编辑器 vim

i:在当前字符前插入文本,进入插入模式

Esc:从编辑模式切换到命令模式;

wq:在命令模式下,执行存盘退出操作;

w:在命令模式下,执行存盘操作;

w!:在命令模式下,执行强制存盘操作;

q:在命令模式下,执行退出vi操作;

q!:在命令模式下,执行强制退出vi操作;

 

 

 

七、cd命令 切换工作目录至…

cd 进入用户主目录;

cd ~ 进入用户主目录;

cd - 返回进入此目录之前所在的目录;

cd .. 返回上级目录(若当前目录为“/“,则执行完后还在“/";".."为上级目录的意思);

cd ../.. 返回上两级目录;

 

八、pwd 查看当前目录

 

九、which命令

使用which命令,就可以看到某个系统命令是否存在,以及执行的到底是哪一个位置的命令。

 

十、whatis命令

是用于查询一个命令执行什么功能,并将查询结果打印到终端上。

 

十一、file命令

查看文件信息 例如file a.txt

 

十二、根目录下的文件

/:处于树形结构的最顶端。

/bin:存放所有用户都可使用的linux基本操作命令

/dev:设备文件目录,虚拟文件系统。

/home:默认存放用户的宿主目录(除了root用户)。

/misc:自动挂载服务目录,对应autofs服务。

/proc:虚拟文件系统,不能建立和删除文件。

/usr:安装除操作系统本身外应用程序或组件。

/boot:存放开机启动加载程序的核心文件

/etc:主机、系统或网络配置文件存放目录。

/media:移动存储设备默认挂载点。(如光盘)。

/root:管理员root的宿主目录。

/tmp:临时文件存放区域。

/var:动态文件或数据存放目录,默认日志文件都存放在这个目录下,建议单独划分一个分区。

/sbin:系统管理相关的二进制文件存放在这个目录下(多数管理命令默认只有管理员可以使用)

/bin:存放最常用命令;

/boot:启动Linux的核心文件;

/dev:设备文件;

/etc:存放各种配置文件;

/home:用户主目录;

/lib:系统最基本的动态链接共享库;

/mnt:一般是空的,用来临时挂载别的文件系统;

/proc:虚拟目录,是内存的映射;

/sbin:系统管理员命令存放目录;

/usr:最大的目录,存放应用程序和文件;

/usr/X11R6:X-Window目录;

/usr/src:Linux源代码;

/usr/include:系统头文件;

/usr/lib:存放常用动态链接共享库、静态档案库;

/usr/bin、/usr/sbin:这是对/bin、/sbin的一个补充

 

十三、cat命令

cat 命令用于连接文件并打印到标准输出设备上。

将文件1.2的内容放在文件3中去:

cat -X 文件1 文件2 > 文件3 (如果文件3里有内容,则3中内容被覆盖)

cat -X 文件1 文件2 >> 文件3 (追加在文件3内容后面,不会覆盖)

    -n 或 --number:由 1 开始对所有输出的行数编号。

-b 或 --number-nonblank:和 -n 相似,只不过对于空白行不编号。

-s 或 --squeeze-blank:当遇到有连续两行以上的空白行,就代换为一行的空白行。

清空文件内容:cat /dev/null > 文件 例如:cat /dev/null > /etc/test.txt

 

十四、cp命令

cp命令用来将一个或多个源文件或者目录复制到指定的目的文件或目录。

cp -X 文件 要复制到的目录/新文件名 例如:cp test.py Music/01_test.py

(但是注意,若要复制的目标文件夹下已有相同文件名的文件,原文件将被覆盖,不会提示)

-f 当文件重名时,强制覆盖

-r 递归复制,将一个目录里的所有文件,复制到另一个目录里 例如:cp -r /bin/sg /etc/jh

-b 当文件重名时,备份一份

-i 当文件重名时,会提示要不要覆盖

 

十五、rm命令

rm命令可以删除一个目录中的一个或多个文件或目录,也可以将某个目录及其下属的所有文件及其子目录均删除掉。对于链接文件,只是删除整个链接文件,而原有文件保持不变。

rm -X 要删除的文件

-d:直接把欲删除的目录的硬连接数据删除成0,删除该目录;删除有可能存在文件

-f:强制删除文件或目录;

-i:删除已有文件或目录之前先询问用户;

-r或-R:递归处理,将指定目录下的所有文件与子目录一并处理;

-v:显示指令的详细执行过程。

 

十六、mv命令

mv命令用来对文件或目录重新命名,或者将文件从一个目录移到另一个目录中。

-b:当文件存在时,覆盖前,为其创建一个备份;

-f:若目标文件或目录与现有的文件或目录重复,则直接覆盖现有的文件或目录;

-i:交互式操作,覆盖前先行询问用户,如果源文件与目标文件或目标目录中的文件同名,则询问用户是否覆盖目标文件。用户输入”y”,表示将覆盖目标文件;输入”n”,表示取消对源文件的移动。这样可以避免误将文件覆盖。

例如:1、将文件重命名将文件ex3改名为new1

mv ex3 new1

将目录/usr/men中的所有文件移到当前目录(用.表示)中:

mv /usr/men/* .

 

十七、chmod命令——用来变更文件或目录的权限

权限范围的表示法如下:

u User,即文件或目录的拥有者;
g Group,即文件或目录的所属群组;
o Other,除了文件或目录拥有者或所属群组之外,其他用户皆属于这个范围;
a All,即全部的用户,包含拥有者,所属群组以及其他用户;
r 读取权限,数字代号为“4”;
w 写入权限,数字代号为“2”;
x 执行或切换权限,数字代号为“1”;
- 不具任何权限,数字代号为“0”;
s 特殊功能说明:变更文件或目录的权限。

例如:

chmod u+x,g+w f01  //为文件f01设置自己可以执行,组员可以写入的权限

chmod u=rwx,g=rw,o=r f01

chmod 764 f01

chmod a+x f01  //对文件f01的u,g,o都设置可执行属性

十八、mkdir命令——用来创建目录

-m:建立目录的同时设置目录的权限

例如:mkdir -m 777 da

-p:若所要建立目录的上层目录目前尚未建立,则会一并建立上层目录

例如:mkdir -p-m 750 bin/os_1

在当前目录中建立bin和bin下的os_1目录,权限设置为文件主可读、写、执行,同组用户可读和执行,其他用户无权访问

 

 

十九、touth文件

有两个功能:一是用于把已存在文件的时间标签更新为系统当前的时间(默认方式),它们的数据将原封不动地保留下来;二是用来创建新的空文件。

-a:只更改存取时间;

-d:<时间日期> 使用指定的日期时间,而非现在的时间;

 

 

二十、tree命令——以树状图列出目录的内容

 

二十一、ps命令——用于报告当前系统的进程状态

 

二十二、find命令——用来在指定目录下查找文件

find 文件夹 -name 查找目标 例如:find / -name aba,txt(当不知道在什么文件夹下时可用根目录)

find 文件夹 -iname 查找目标 (同上,但不区分大小写)

find . 列出当前目录及子目录下所有文件和文件夹

 

二十三、locate命令——用来查找文件或目录,比find快

搜索etc目录下所有以sh开头的文件:

locate /etc/sh

搜索用户主目录下,所有以m开头的文件:

locate ~/m

搜索用户主目录下,所有以m开头的文件,并且忽略大小写:

locate -i ~/m

 

二十四、head——用于显示文件的开头的内容。默认显示文件的头10行内容。

例如:man ls | head

若要指定看多少行,则:head -n 行数

 

二十五、less命令

less命令的作用与more十分相似,都可以用来浏览文字档案的内容,不同的是less命令允许用户向前或向后浏览文件,而more命令只能向前浏览。用less命令显示文件时,用PageUp键向上翻页,用PageDown键向下翻页。要退出less程序,应按Q键。

Guess you like

Origin www.cnblogs.com/yjxing/p/11582391.html