Devops系列:Centos7 快捷键、目录结构、用户目录
一.快捷键
1.历史命令
查看历史命令:history
[root@centos-master ~]# history 1 2020-10-25 21:03:39 2 2020-09-17 20:43:52 ls1 2020-10-25 21:03:39 2 2020-09-17 20:43:52 ls 3 2020-09-17 20:43:54 ls 4 2020-09-17 20:43:57 cd / 5 2020-09-17 20:43:58 ls 6 2020-09-17 20:50:31 cd / 7 2020-09-17 20:50:33 ls
向上遍历:ctrl+p 方向键向上
向下遍历:ctrl+n 方向键向下
2.光标移动
光标向前移动:ctrl+b 方向键向左
光标向后移动:ctrl+f 方向键向右
光标移动到行首:ctrl+a
光标移动到行尾:ctrl+e
删除光标前面的一个字符:ctrl+h 退格键
删除光标后面的一个字符:ctrl+d
删除光标前面的字符:ctrl+u
3.清屏
清屏:ctrl+l clear
二.目录结构
/bin:存储基本命令的目录
/boot:开机启动项文件,包括一些连接文件和镜像文件
/dev:(device)设备目录,该目录下存放的是linux的外部设备,在linux中访问设备和访问文件是一样的
/etc:存放所有的系统管理所需要的配置文件和子目录
/home:用户的主目录,在linux中每个用户都有一个自己的目录,一般该目录是以用户的账号命名的
/lib:存放着系统最基本的动态连接共享库,类似于windows中的dll文件
/lost+found:一般情况下是空的,当系统非法关机后就存放了一些文件
/media:linux会自动识别一些设备,例如U盘、光驱等,linux会把这些设备挂载在目录中(自动挂载)
/mnt:手动挂载目录
/opt:主机额外安装软件摆放的位置,第三方软件
/proc:虚拟目录,他是系统内存的映射,我们可以通过这个目录来获取系统信息,这个目录不在硬盘上而是在内存里,比如说可以通过下面命令来屏蔽主机的ping命令,使别人无法ping你的机器
[root@centos-master ~]# echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all
/root:系统管理员目录,超级权限者的用户主目录
/sbin:super user的意思,存放的系统管理员使用的系统管理程序
/srv:存放着一些服务启动后需要提取的数据
/tmp:存放一些临时文件的目录
/usr:用户很多程序和文件都放在这个目录,类似于windows中的program files目录
/usr/bin:系统用户使用的应用程序
/usr/sbin:超级用户使用的比较高级的管理程序和系统守护程序
/usr/src:内核源代码默认放置的目录
/var:存放着不断扩展的东西,习惯将经常修改的文件放在这个目录下,包括各种日志文件
三.用户目录
1.绝对路径: cd /usr/src
2.相对路径: cd usr/src
3.当前路径: cd .
4.当前路径的上一级: cd ..
5.邻近的两个路径相互切换:cd -
[root@centos-master ~]# cd / [root@centos-master /]# ls bin boot data dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var [root@centos-master /]# cd etc/ [root@centos-master etc]# ls abrt cron.d environment gshadow- krb5.conf man_db.conf pam.d rc3.d sestatus.conf systemd acpi cron.daily ethertypes gss krb5.conf.d maven passwd rc4.d setuptool.d system-release adjtime cron.deny exports host.conf ld.so.cache mke2fs.conf passwd- rc5.d shadow system-release-cpe aliases cron.hourly favicon.png hostname ld.so.conf modprobe.d pkcs11 rc6.d shadow- terminfo aliases.db cron.monthly filesystems hosts ld.so.conf.d modules-load.d pki rc.d shells tmpfiles.d alternatives crontab firewalld hosts.allow libaudit.conf motd plymouth rc.local skel trusted-key.key anacrontab cron.weekly fonts hosts.deny libibverbs.d mtab pm rdma sos.conf tuned asound.conf crypttab fstab img_version libnl my.cnf polkit-1 redhat-release ssh udev at.deny csh.cshrc gconf infiniband libreport my.cnf.d popt.d resolv.conf ssl updatedb.conf audisp csh.login gcrypt infiniband-diags libuser.conf nanorc postfix rpc statetab usb_modeswitch.conf audit dbus-1 gdbinit init.d locale.conf netconfig ppp rpm statetab.d uuid bash_completion.d default gdbinit.d inittab localtime NetworkManager prelink.conf.d rsyncd.conf subgid vconsole.conf bashrc depmod.d GeoIP.conf inputrc login.defs networks printcap rsyslog.conf subgid- vimrc binfmt.d dhcp glvnd iproute2 login.defs.rpmnew nginx profile rsyslog.d subuid virc centos-release DIR_COLORS gnupg iscsi logrotate.conf nsswitch.conf profile.d rwtab subuid- wgetrc centos-release-upstream DIR_COLORS.256color GREP_COLORS issue logrotate.d nsswitch.conf.bak protocols rwtab.d sudo.conf wpa_supplicant chkconfig.d DIR_COLORS.lightbgcolor groff issue.net lsm nsswitch.conf.rpmnew python sasl2 sudoers X11 chrony.conf docker group java lvm ntp qcloudzone scl sudoers.d xdg chrony.keys dracut.conf group- jvm machine-id ntp.conf qemu-ga securetty sudo-ldap.conf xinetd.d cifs-utils dracut.conf.d grub2.cfg jvm-commmon magic openldap rc0.d security sysconfig yum cloud e2fsck.conf grub.d kdump.conf mail.rc opt rc1.d selinux sysctl.conf yum.conf containerd egl gshadow kernel makedumpfile.conf.sample os-release rc2.d services sysctl.d yum.repos.d [root@centos-master etc]# cd /home/ [root@centos-master home]# cd .. [root@centos-master /]# cd - /home [root@centos-master home]# cd - / [root@centos-master /]#
6.认识[root@centos-master usr]#
root:当前用户
@:at
centos-master:主机名
usr:当前目录
$:代表普通用户
#:代表root用户
7.切换用户:su
[root@centos-master usr]# su robin [robin@centos-master usr]$ su root 密码: su: 鉴定故障 [robin@centos-master usr]$ su root 密码: [root@centos-master usr]#
8.创建目录:mkdir
mdkir dir #创建单级目录
mkdir -p dir1/dir2/dir3 #创建多级目录
[root@centos-master test]# mkdir dir [root@centos-master test]# ls dir [root@centos-master test]# mkdir dir1/dir2/dir3 -p [root@centos-master test]# tree . |-- dir `-- dir1 `-- dir2 `-- dir3 4 directories, 0 files [root@centos-master test]#
9.删除空目录:rmdir
[root@centos-master test]# rmdir --help Usage: rmdir [OPTION]... DIRECTORY... Remove the DIRECTORY(ies), if they are empty. --ignore-fail-on-non-empty ignore each failure that is solely because a directory is non-empty -p, --parents remove DIRECTORY and its ancestors; e.g., 'rmdir -p a/b/c' is similar to 'rmdir a/b/c a/b a' -v, --verbose output a diagnostic for every directory processed --help display this help and exit --version output version information and exit GNU coreutils online help: <http://www.gnu.org/software/coreutils/> For complete documentation, run: info coreutils 'rmdir invocation' [root@centos-master test]# rmdir dir [root@centos-master test]#
10.创建文件:touch
[root@centos-master dir]# touch --help Usage: touch [OPTION]... FILE... Update the access and modification times of each FILE to the current time. A FILE argument that does not exist is created empty, unless -c or -h is supplied. A FILE argument string of - is handled specially and causes touch to change the times of the file associated with standard output. Mandatory arguments to long options are mandatory for short options too. -a change only the access time -c, --no-create do not create any files -d, --date=STRING parse STRING and use it instead of current time -f (ignored) -h, --no-dereference affect each symbolic link instead of any referenced file (useful only on systems that can change the timestamps of a symlink) -m change only the modification time -r, --reference=FILE use this file's times instead of current time -t STAMP use [[CC]YY]MMDDhhmm[.ss] instead of current time --time=WORD change the specified time: WORD is access, atime, or use: equivalent to -a WORD is modify or mtime: equivalent to -m --help display this help and exit --version output version information and exit Note that the -d and -t options accept different time-date formats. GNU coreutils online help: <http://www.gnu.org/software/coreutils/> For complete documentation, run: info coreutils 'touch invocation' [root@centos-master dir]#
11.删除:rm
rm -i #询问是否删除
rm -r #递归删除文件
rm -rf * 删除所有文件
[root@centos-master test]# touch test.txt [root@centos-master test]# ls dir dir1 test.txt [root@centos-master test]# rm --help Usage: rm [OPTION]... FILE... Remove (unlink) the FILE(s). -f, --force ignore nonexistent files and arguments, never prompt -i prompt before every removal -I prompt once before removing more than three files, or when removing recursively; less intrusive than -i, while still giving protection against most mistakes --interactive[=WHEN] prompt according to WHEN: never, once (-I), or always (-i); without WHEN, prompt always --one-file-system when removing a hierarchy recursively, skip any directory that is on a file system different from that of the corresponding command line argument --no-preserve-root do not treat '/' specially --preserve-root do not remove '/' (default) -r, -R, --recursive remove directories and their contents recursively -d, --dir remove empty directories -v, --verbose explain what is being done --help display this help and exit --version output version information and exit By default, rm does not remove directories. Use the --recursive (-r or -R) option to remove each listed directory, too, along with all of its contents. To remove a file whose name starts with a '-', for example '-foo', use one of these commands: rm -- -foo rm ./-foo Note that if you use rm to remove a file, it might be possible to recover some of its contents, given sufficient expertise and/or time. For greater assurance that the contents are truly unrecoverable, consider using shred. GNU coreutils online help: <http://www.gnu.org/software/coreutils/> For complete documentation, run: info coreutils 'rm invocation' [root@centos-master test]# rm -i test.txt rm: remove regular empty file ‘test.txt’? y [root@centos-master test]# tree . |-- dir `-- dir1 `-- dir2 `-- dir3 4 directories, 0 files [root@centos-master test]# rm -ri dir1 rm: descend into directory ‘dir1’? y rm: descend into directory ‘dir1/dir2’? y rm: remove directory ‘dir1/dir2/dir3’? y rm: remove directory ‘dir1/dir2’? y rm: remove directory ‘dir1’? y [root@centos-master test]# rm -rfi * rm: remove directory ‘dir’? y [root@centos-master test]#
12.拷贝:cp
cp a.txt b.txt 如果b不存在就创建 如何b存在就覆盖
cp dir dir2 -r 递归操作 dir2如果不存在 则把dir的文件放入进去 如果存在则存入里面
cp dir/* dir2 -r 拷贝下面的
[root@centos-master test]# touch hello.c [root@centos-master test]# vim hello.c [root@centos-master test]# ls hello.c [root@centos-master test]# cat hello.c hello world! [root@centos-master test]# cp hello.c temp.c [root@centos-master test]# cat temp.c hello world! [root@centos-master test]# vim test.txt [root@centos-master test]# ls hello.c temp.c test.txt [root@centos-master test]# cat test.txt test! [root@centos-master test]# cp test.txt temp.c cp: overwrite ‘temp.c’? y [root@centos-master test]# cat temp.c test!' [root@centos-master test]# mkdir mytest [root@centos-master test]# cd mytest/ [root@centos-master mytest]# touch test.txt [root@centos-master mytest]# cd ../ [root@centos-master test]# ls hello.c mytest temp.c test.txt [root@centos-master test]# cp -r mytest/ newDir [root@centos-master test]# ls hello.c mytest newDir temp.c test.txt [root@centos-master test]# tree newDir/ newDir/ `-- test.txt 0 directories, 1 file [root@centos-master test]# cp -r mytest/ newDir/ [root@centos-master test]# tree newDir/ newDir/ |-- mytest | `-- test.txt `-- test.txt 1 directory, 2 files [root@centos-master test]# cp --help Usage: cp [OPTION]... [-T] SOURCE DEST or: cp [OPTION]... SOURCE... DIRECTORY or: cp [OPTION]... -t DIRECTORY SOURCE... Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY. Mandatory arguments to long options are mandatory for short options too. -a, --archive same as -dR --preserve=all --attributes-only don't copy the file data, just the attributes --backup[=CONTROL] make a backup of each existing destination file -b like --backup but does not accept an argument --copy-contents copy contents of special files when recursive -d same as --no-dereference --preserve=links -f, --force if an existing destination file cannot be opened, remove it and try again (this option is ignored when the -n option is also used) -i, --interactive prompt before overwrite (overrides a previous -n option) -H follow command-line symbolic links in SOURCE -l, --link hard link files instead of copying -L, --dereference always follow symbolic links in SOURCE -n, --no-clobber do not overwrite an existing file (overrides a previous -i option) -P, --no-dereference never follow symbolic links in SOURCE -p same as --preserve=mode,ownership,timestamps --preserve[=ATTR_LIST] preserve the specified attributes (default: mode,ownership,timestamps), if possible additional attributes: context, links, xattr, all -c deprecated, same as --preserve=context --no-preserve=ATTR_LIST don't preserve the specified attributes --parents use full source file name under DIRECTORY -R, -r, --recursive copy directories recursively --reflink[=WHEN] control clone/CoW copies. See below --remove-destination remove each existing destination file before attempting to open it (contrast with --force) --sparse=WHEN control creation of sparse files. See below --strip-trailing-slashes remove any trailing slashes from each SOURCE argument -s, --symbolic-link make symbolic links instead of copying -S, --suffix=SUFFIX override the usual backup suffix -t, --target-directory=DIRECTORY copy all SOURCE arguments into DIRECTORY -T, --no-target-directory treat DEST as a normal file -u, --update copy only when the SOURCE file is newer than the destination file or when the destination file is missing -v, --verbose explain what is being done -x, --one-file-system stay on this file system -Z set SELinux security context of destination file to default type --context[=CTX] like -Z, or if CTX is specified then set the SELinux or SMACK security context to CTX --help display this help and exit --version output version information and exit By default, sparse SOURCE files are detected by a crude heuristic and the corresponding DEST file is made sparse as well. That is the behavior selected by --sparse=auto. Specify --sparse=always to create a sparse DEST file whenever the SOURCE file contains a long enough sequence of zero bytes. Use --sparse=never to inhibit creation of sparse files. When --reflink[=always] is specified, perform a lightweight copy, where the data blocks are copied only when modified. If this is not possible the copy fails, or if --reflink=auto is specified, fall back to a standard copy. The backup suffix is '~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX. The version control method may be selected via the --backup option or through the VERSION_CONTROL environment variable. Here are the values: none, off never make backups (even if --backup is given) numbered, t make numbered backups existing, nil numbered if numbered backups exist, simple otherwise simple, never always make simple backups As a special case, cp makes a backup of SOURCE when the force and backup options are given and SOURCE and DEST are the same name for an existing, regular file. GNU coreutils online help: <http://www.gnu.org/software/coreutils/> For complete documentation, run: info coreutils 'cp invocation' [root@centos-master test]#
12 :查看目录:ls和tree
tree需要安装,yum install tree
ls -a显示所有的文件
ls -l 详细信息
第一个代表的是文件类型 如果是dr代表的是文件夹,如果是-代表的是普通文件 l代表软链接 s代表套接字 b块设备 c字符设备 p管道
后面九个字符:前面三个代表的是文件所有者对文件的操作权限 。中间三个文件所属组,后面三个其他人对文件的操作
数字代表链接数 root:代表文件所有者 后面的root:文件所属组 4096:目录的大小 后面就是文件最后的修改日期 最后是文件的名字
drwxr-xr-x 3 root root 4096 Dec 8 21:04 dir1
drwxr-xr-x 2 root root 4096 Dec 8 21:01 newDir
-rw-r--r-- 1 root root 0 Dec 8 21:01 test.txt
[root@centos-master test]# ls dir1 newDir test.txt [root@centos-master test]# tree . |-- dir1 | `-- dir2 | `-- dir3 |-- newDir `-- test.txt 4 directories, 1 file [root@centos-master test]# ls -l total 8 drwxr-xr-x 3 root root 4096 Dec 8 21:04 dir1 drwxr-xr-x 2 root root 4096 Dec 8 21:01 newDir -rw-r--r-- 1 root root 0 Dec 8 21:01 test.txt [root@centos-master test]# ls --help Usage: ls [OPTION]... [FILE]... List information about the FILEs (the current directory by default). Sort entries alphabetically if none of -cftuvSUX nor --sort is specified. Mandatory arguments to long options are mandatory for short options too. -a, --all do not ignore entries starting with . -A, --almost-all do not list implied . and .. --author with -l, print the author of each file -b, --escape print C-style escapes for nongraphic characters --block-size=SIZE scale sizes by SIZE before printing them; e.g., '--block-size=M' prints sizes in units of 1,048,576 bytes; see SIZE format below -B, --ignore-backups do not list implied entries ending with ~ -c with -lt: sort by, and show, ctime (time of last modification of file status information); with -l: show ctime and sort by name; otherwise: sort by ctime, newest first -C list entries by columns --color[=WHEN] colorize the output; WHEN can be 'never', 'auto', or 'always' (the default); more info below -d, --directory list directories themselves, not their contents -D, --dired generate output designed for Emacs' dired mode -f do not sort, enable -aU, disable -ls --color -F, --classify append indicator (one of */=>@|) to entries --file-type likewise, except do not append '*' --format=WORD across -x, commas -m, horizontal -x, long -l, single-column -1, verbose -l, vertical -C --full-time like -l --time-style=full-iso -g like -l, but do not list owner --group-directories-first group directories before files; can be augmented with a --sort option, but any use of --sort=none (-U) disables grouping -G, --no-group in a long listing, don't print group names -h, --human-readable with -l, print sizes in human readable format (e.g., 1K 234M 2G) --si likewise, but use powers of 1000 not 1024 -H, --dereference-command-line follow symbolic links listed on the command line --dereference-command-line-symlink-to-dir follow each command line symbolic link that points to a directory --hide=PATTERN do not list implied entries matching shell PATTERN (overridden by -a or -A) --indicator-style=WORD append indicator with style WORD to entry names: none (default), slash (-p), file-type (--file-type), classify (-F) -i, --inode print the index number of each file -I, --ignore=PATTERN do not list implied entries matching shell PATTERN -k, --kibibytes default to 1024-byte blocks for disk usage -l use a long listing format -L, --dereference when showing file information for a symbolic link, show information for the file the link references rather than for the link itself -m fill width with a comma separated list of entries -n, --numeric-uid-gid like -l, but list numeric user and group IDs -N, --literal print raw entry names (don't treat e.g. control characters specially) -o like -l, but do not list group information -p, --indicator-style=slash append / indicator to directories -q, --hide-control-chars print ? instead of nongraphic characters --show-control-chars show nongraphic characters as-is (the default, unless program is 'ls' and output is a terminal) -Q, --quote-name enclose entry names in double quotes --quoting-style=WORD use quoting style WORD for entry names: literal, locale, shell, shell-always, c, escape -r, --reverse reverse order while sorting -R, --recursive list subdirectories recursively -s, --size print the allocated size of each file, in blocks -S sort by file size --sort=WORD sort by WORD instead of name: none (-U), size (-S), time (-t), version (-v), extension (-X) --time=WORD with -l, show time as WORD instead of default modification time: atime or access or use (-u) ctime or status (-c); also use specified time as sort key if --sort=time --time-style=STYLE with -l, show times using style STYLE: full-iso, long-iso, iso, locale, or +FORMAT; FORMAT is interpreted like in 'date'; if FORMAT is FORMAT1<newline>FORMAT2, then FORMAT1 applies to non-recent files and FORMAT2 to recent files; if STYLE is prefixed with 'posix-', STYLE takes effect only outside the POSIX locale -t sort by modification time, newest first -T, --tabsize=COLS assume tab stops at each COLS instead of 8 -u with -lt: sort by, and show, access time; with -l: show access time and sort by name; otherwise: sort by access time -U do not sort; list entries in directory order -v natural sort of (version) numbers within text -w, --width=COLS assume screen width instead of current value -x list entries by lines instead of by columns -X sort alphabetically by entry extension -1 list one file per line SELinux options: --lcontext Display security context. Enable -l. Lines will probably be too wide for most displays. -Z, --context Display security context so it fits on most displays. Displays only mode, user, group, security context and file name. --scontext Display only security context and file name. --help display this help and exit --version output version information and exit SIZE is an integer and optional unit (example: 10M is 10*1024*1024). Units are K, M, G, T, P, E, Z, Y (powers of 1024) or KB, MB, ... (powers of 1000). Using color to distinguish file types is disabled both by default and with --color=never. With --color=auto, ls emits color codes only when standard output is connected to a terminal. The LS_COLORS environment variable can change the settings. Use the dircolors command to set it. Exit status: 0 if OK, 1 if minor problems (e.g., cannot access subdirectory), 2 if serious trouble (e.g., cannot access command-line argument). GNU coreutils online help: <http://www.gnu.org/software/coreutils/> For complete documentation, run: info coreutils 'ls invocation' [root@centos-master test]# tree --help usage: tree [-acdfghilnpqrstuvxACDFQNSUX] [-H baseHREF] [-T title ] [-L level [-R]] [-P pattern] [-I pattern] [-o filename] [--version] [--help] [--inodes] [--device] [--noreport] [--nolinks] [--dirsfirst] [--charset charset] [--filelimit[=]#] [--si] [--timefmt[=]<f>] [<directory list>] ------- Listing options ------- -a All files are listed. -d List directories only. -l Follow symbolic links like directories. -f Print the full path prefix for each file. -x Stay on current filesystem only. -L level Descend only level directories deep. -R Rerun tree when max dir level reached. -P pattern List only those files that match the pattern given. -I pattern Do not list files that match the given pattern. --noreport Turn off file/directory count at end of tree listing. --charset X Use charset X for terminal/HTML and indentation line output. --filelimit # Do not descend dirs with more than # files in them. --timefmt <f> Print and format time according to the format <f>. -o filename Output to file instead of stdout. --du Print directory sizes. --prune Prune empty directories from the output. -------- File options --------- -q Print non-printable characters as '?'. -N Print non-printable characters as is. -Q Quote filenames with double quotes. -p Print the protections for each file. -u Displays file owner or UID number. -g Displays file group owner or GID number. -s Print the size in bytes of each file. -h Print the size in a more human readable way. --si Like -h, but use in SI units (powers of 1000). -D Print the date of last modification or (-c) status change. -F Appends '/', '=', '*', '@', '|' or '>' as per ls -F. --inodes Print inode number of each file. --device Print device ID number to which each file belongs. ------- Sorting options ------- -v Sort files alphanumerically by version. -r Sort files in reverse alphanumeric order. -t Sort files by last modification time. -c Sort files by last status change time. -U Leave files unsorted. --dirsfirst List directories before files (-U disables). ------- Graphics options ------ -i Don't print indentation lines. -A Print ANSI lines graphic indentation lines. -S Print with ASCII graphics indentation lines. -n Turn colorization off always (-C overrides). -C Turn colorization on always. ------- XML/HTML options ------- -X Prints out an XML representation of the tree. -H baseHREF Prints out HTML format with baseHREF as top directory. -T string Replace the default HTML title and H1 header with string. --nolinks Turn off hyperlinks in HTML output. ---- Miscellaneous options ---- --version Print version and exit. --help Print usage and this help message and exit. [root@centos-master test]#
微信:17873041739
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?