System directory Structure
/root 这是系统管理员(root user)的目录。/bin 这里存放了标准的(或者说是缺省的)linux的工具,比如像“ls”、“vi”还有“more”等等。/etc 系统重要配置文件, 以及常用服务配置文件/var 存放系统引导启动时产生的可变文件,文件通常动态更改的,例如: 缓存目录,日志文件/run 系统启动后, 运行的程序产生的运行时数据, 包括进程的pid文件,锁文件等/home 普通用户的主目录, 普通用户的家目录默认为/HOME/USERNAME/root 超级管理员的主目录, 普通用户无权操作/tmp 存放临时文件, 一般存放超过10天以上都会自动删除,可以更改删除临时文件的期限/boot 存放系统引导时候需要的文件/dev 存放设备文件/usr 安装的软件, 共享库, 重要的子目录有/usr/bin 用户命令目录/usr/sbin 管理员命令目录/usr/local 本地自定义安装的软件 /media 有些linux的发行版使用这个目录来挂载那些usb接口的移动硬盘(包括U盘)、CD/DVD驱动器等等。 /mnt 这个目录一般是用于存放挂载储存设备的挂载目录的,比如有cdrom 等目录。 /proc 操作系统运行时,进程信息及内核信息(比如cpu、硬盘分区、内存信息等)存放在这里。
File path positioning
1. Absolute path:
The Linux system uses the directory tree file organization structure, under Linux each directory or the file can begin to search from the root directory, for example:/usr/bin directory. This full path from the root directory is called an absolute path, and the absolute path must begin with "/".
2. Relative path
Relative path, the key point is the current path. Assuming the current directory is /usr/local
under, then its upper-level directory (/usr) can be used: /usr/local
the Lower directory (SRC) can be represented by the./src. The so-called (.) and (..) The directory actually belongs to the relative path.
Common uses of 3.CD commands:
. 表示用户所处的当前目录.. 表示上级目录;~ 表示当前用户自己的家目录cd - //切换上次所在目录cd ~ //切换至当前用户家目录cd //切换至当前用户家目录cd . //.代表当前目录,一般在拷贝、移动等情况下使用cd .. //切换至当前目录的上级目录
Directory Management Commands
1. Directory creation commands mkdir
(options) (parameters)
Options
-Z: Sets the security context, which is valid when SELinux is used;
-m< Target properties > or--mode< Target properties > Set directory permissions while setting up the directory;
-P or--parents if the upper-level directory to be set up is not yet established, the upper-level directory will be established;
--version Displays version information.
Instance
Sub-directory test under Directory/usr/meng, and only the file owner has read, write, and Execute permissions, others do not have access
Mkdir-m 700/usr/meng/test
In the current directory to establish the bin and bin Os_1 directory, the permissions set to the main file readable, write, execute, the same group of users can read and execute, other users do not have access to
Mkdir-p-m Bin/os_1
File Management Commands
Linux
Everything is a file, in the configuration of Linux, to a large extent is the process of processing files, so it is necessary to master the relevant operation of the file. Here we describe how to do, create, delete, move, rename, and view the contents of the file, as to how to edit the file, in the following details of the editor when the detailed description.
Options
-A: or--time=atime or--time=access or--time=use only change the access time;
-C: Or--no-create does not establish any documents;
-d:< Time Date > Use the specified date time, not the current time;
-F: This parameter ignores non-processing and is only responsible for the compatibility of BSD version touch directives;
-M: or--time=mtime or--time=modify only the change time;
-r:< reference file or directory > set the date and time of the specified file or directory to the same date and time as the reference file or directory;
-t:< Date Time > Use the specified datetime, not the current time;
--help: Online Help;
--version: Displays version information.
1. File Creation command
touch
# touch filename# touch filename_1 filename_2# touch file{1..10}# touch file{a,b,c}# touch file{a..z}
2. File time
stat
[[email protected] ~]# stat 1.txt File: ‘1.txt’ Size: 25 Blocks: 8 IO Block: 4096 regular fileDevice: fd00h/64768d Inode: 5773072 Links: 1Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)Access: 2018-05-29 09:01:36.529542000 +0800Modify: 2018-05-29 09:01:34.442542000 +0800Change: 2018-05-29 09:01:34.442542000 +0800 Birth: - 访问时间:atime,查看内容 修改时间:mtime,修改内容 改变时间:ctime,文件属性,比如权限 删除时间:dtime,文件被删除的时间
3. File directory copy command CP
Options
-A: The effect of this parameter is the same as specifying the "-DPR" parameter;
-D: When a symbolic connection is copied, the destination file or directory is also established as a symbolic connection and points to the original file or directory connected to the source file or directory;
-F: Forcibly copy the file or directory, regardless of whether the destination file or directory already exists;
-I: Ask the user before overwriting existing files;
-L: Make a hard connection to the source file instead of copying the file;
-P: Preserves the properties of the source file or directory;
-R/R: Recursive processing, all files under the specified directory are processed together with subdirectories;
-S: Create a symbolic connection to the source file instead of copying the file;
-U: When using this parameter, the file will only be copied when the source file is changed more than the target file is updated or if the target file corresponding to the name does not exist.
-S: Replaces the default suffix of the file with the specified suffix "SUFFIX" when backing up the file;
-B: The target file is backed up before overwriting the existing file target;
-V: Displays the actions performed by the command in detail.
Instance
If a file is copied to a target file and the target file already exists, the contents of the target file will be destroyed. All parameters in this command can be either an absolute pathname or a relative path name. It usually uses a point. or dot. The form. For example, the following command copies the specified file to the current directory:
Copy file to directory/usr/men/tmp and rename to File1
CP File/usr/men/tmp/file1
Copy all files and their subdirectories under directory/usr/men to the directory/usr/zh
Cp-r/usr/men/usr/zh
interactively copy all. c files in the directory/usr/men that begin with M to the directory/usr/zh
Cp-i/usr/men M*.c/usr/zh
When we use the CP command to copy files under Linux, sometimes we will need to overwrite some files with the same name, when overwriting the file, we will have to keep pressing Y to determine the execution overwrite. The number of files is not much good, but if hundreds of estimates press Y to vomit blood, so toss a half-day summed up a method:
CP aaa/*/BBB
Copy directory AAA under All to the/BBB directory, at this time if the/BBB directory has the same name as the AAA file, you need to press Y to confirm and will skip the sub-directory under the AAA directory.
Cp-r aaa/*/bbb
This time you still need to press Y to confirm the operation, but the subdirectories are not ignored.
Cp-r-a aaa/*/bbb
Still need to press Y to confirm the operation, and the AAA directory and subdirectories and file attributes are also passed to the/bbb.
\cp-r-a aaa/*/bbb
Successfully, no prompt was pressed for y, the directory attribute was passed, and the directory was not skipped.
4. File directory Move command
mv
Options
--backup=< backup mode;: If you need to overwrite the file, overwrite the previous backup;
-B: When the file is present, create a backup for it before overwriting;
-F: If the target file or directory is duplicated with an existing file or directory, the existing file or directory is overwritten directly;
-I: An interactive operation that asks the user before overwriting, if the source file has the same name as a file in the destination file or destination directory, asks the user if the target file is overwritten. The user enters "Y" to indicate that the target file will be overwritten, and "N" is entered to cancel the movement of the source file. This avoids overwriting the file by mistake.
--strip-trailing-slashes: Delete the slash "/" in the source file;
-s< suffix: Specify a suffix for the backup file instead of using the default suffix;
--target-directory=< directory;: Specify the source file to be moved to the target directory;
-U: The move operation is performed when the source file is newer than the destination file or the destination file does not exist.
//移动文件至tmp目录# mv file /tmp///移动文件至tmp目录并修改名称为file_test# mv file /tmp/file_test//移动目录至/tmp目录下# mv dir/ /tmp///移动多个文件或多个目录至同一个目录# touch file{1..3}# mv file1 file2 file3 /opt/# mkdir dir{1..3}# mv dir1/ dir2/ dir3/ /opt
5. File Directory Delete command rm
The RM command can delete one or more files or directories in a directory, or it can delete all files and subdirectories of a directory and its subordinates. For linked files, only the entire linked file is deleted, and the original file remains unchanged.
Options
-D: Delete the hard connection data of the directory you want to delete to 0, delete the directory;
-F: Forcibly deleting files or directories;
-I: Ask the user before deleting an existing file or directory;
-R or-R: Recursive processing, all files under the specified directory are processed in conjunction with subdirectories;
--preserve-root: Do not recursively operate the root directory;
-V: Displays the detailed execution of the instruction.
//删除文件, 默认会提醒是否删除文件# rm anan//强制删除文件, 不提醒# rm anan -f//删除目录,会提醒# rm -r dir///强制删除目录,不提醒# rm -rf dir///示例# mkdir /home/dir10# touch /home/dir10/{file2,file3,.file4}# rm -rf /home/dir10/* //不包括隐藏文件 # ls /home/dir10/ -a. .. .file4//示例2# touch file{1..10}# touch {1..10}.pdf# rm -rf file* # rm -rf *.pdf
File View command
cat //查看文件内容示例:cat /etc/passwd示例:cat -n /etc/passwd //-n参数行号 示例:cat >> xuliangwei.txt <<EOF //追加数据 test EOFhead //查看文件头部内容,默认前十行示例:head /etc/passwd 示例:head -n5 /etc/passwd //-n参数指定查看头几行tail //查看文件尾部内容,默认最后十行示例:tail /etc/passwd 示例:tail -f /var/log/messages // -f参数跟随尾部输出而变化more //按空格可翻页查看文件内容,按q可推出示例:more /etc/passwdless //和more类似示例:less /etc/passwd
File Download command
wget //文件下载-O //指定,更改名称 -T //超时时间-q //安静下载(关闭wget输出)--spider //网络爬虫 示例:wget http://www.baidu.comcurl //文件下载示例:curl -o http://www.baidu.comyum install lrzszrz //文件上传sz //文件下载示例:sz filename
Command Lookup command
locate //查找文件或者目录示例:locate /etc/sh //搜索etc目录下所有以sh开头的文件示例:locate -i /etc/sh //搜索etc目录下,所有以sh开头的文件,忽略大小写which //查找系统PATH变量目录下的命令(绝对路径)示例:which lswhereis //查找文件索引数据库下的命令、源文件、man文件。非PATH变量查找,所以查找的面比which要广 -b,-m示例:whereis ls示例:whereis -b ls
03-linux System basic Commands