linux常见指令1

pwd 查看当前光标所在的目录

[root@bigdata10 ~]# pwd
/root

ls 查看光标所在的目录下面

[root@bigdata10 ~]# ls
anaconda-ks.cfg  bigdata  initial-setup-ks.cfg

ls -l 显示额外的信息【权限、用户用户组 大小 时间】

[root@bigdata10 ~]# ls -l
总用量 12
-rw-------. 1 root root 1841 1031 10:21 anaconda-ks.cfg
drwxr-xr-x. 5 root root 4096 1031 17:24 bigdata
-rw-r--r--. 1 root root 1889 1031 10:32 initial-setup-ks.cfg

ls -l -a 显示以.开头的文件和文件夹 以.开头的文件和文件夹 隐藏文件

root@bigdata10 ~]# ls -l -a
总用量 60
dr-xr-x---.  6 root root 4096 1031 17:29 .
dr-xr-xr-x. 19 root root 4096 1031 14:19 ..
-rw-------.  1 root root 1841 1031 10:21 anaconda-ks.cfg
-rw-------.  1 root root 1683 1031 17:29 .bash_history
-rw-r--r--.  1 root root   18 1229 2013 .bash_logout
-rw-r--r--.  1 root root  176 1229 2013 .bash_profile
-rw-r--r--.  1 root root  176 1229 2013 .bashrc
drwxr-xr-x.  5 root root 4096 1031 17:24 bigdata
drwx------.  4 root root 4096 1031 10:41 .cache
drwx------.  4 root root 4096 1031 10:41 .config
-rw-r--r--.  1 root root  100 1229 2013 .cshrc
drwx------.  3 root root 4096 1031 10:31 .dbus
-rw-r--r--.  1 root root 1889 1031 10:32 initial-setup-ks.cfg
-rw-r--r--.  1 root root  129 1229 2013 .tcshrc
-rw-------.  1 root root 2296 1031 17:29 .viminfo

ls -l -h 查看文件的大小

[root@bigdata10 ~]# ls -l -h
总用量 12K
-rw-------. 1 root root 1.8K 1031 10:21 anaconda-ks.cfg
drwxr-xr-x. 5 root root 4.0K 1031 17:24 bigdata
-rw-r--r--. 1 root root 1.9K 1031 10:32 initial-setup-ks.cfg

命令帮助:命令 --help

[root@bigdata10 ~]# ls --help
用法:ls [选项]... [文件]...
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			不隐藏任何以. 开始的项目
  -A, --almost-all		列出除... 以外的任何项目
      --author			与-l 同时使用时列出每个文件的作者
  -b, --escape			以八进制溢出序列表示不可打印的字符
      --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				类似-l,但不列出所有者
      --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		以一个长列表的形式,不输出组名
  -h, --human-readable		与-l 一起,以易于阅读的格式输出文件大小
				(例如 1K 234M 2G)
      --si			同上面类似,但是使用1000 为基底而非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				使用较长格式列出信息
  -L, --dereference		当显示符号链接的文件信息时,显示符号链接所指示
				的对象而并非符号链接本身的信息
  -m				所有项目以逗号分隔,并填满整行行宽
  -n, --numeric-uid-gid		类似 -l,但列出UID 及GID 号
  -N, --literal			输出未经处理的项目名称 (如不特别处理控制字符)
  -o				类似 -l,但不列出有关组的信息
  -p,  --indicator-style=slash	对目录加上表示符号"/"
  -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			逆序排列
  -R, --recursive		递归显示子目录
  -s, --size			以块数形式显示每个文件分配的尺寸
  -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

ls -l => ll 等价 别名

查找最新更改的文件 ll -r -t => ll -rt

[root@bigdata10 ~]# ll -r -t
总用量 12
-rw-------. 1 root root 1841 1031 10:21 anaconda-ks.cfg
-rw-r--r--. 1 root root 1889 1031 10:32 initial-setup-ks.cfg
drwxr-xr-x. 5 root root 4096 1031 17:24 bigdata
[root@bigdata10 ~]# ll -rt
总用量 12
-rw-------. 1 root root 1841 1031 10:21 anaconda-ks.cfg
-rw-r--r--. 1 root root 1889 1031 10:32 initial-setup-ks.cfg
drwxr-xr-x. 5 root root 4096 1031 17:24 bigdata

mkdir 创建文件夹

[root@bigdata10 bigdata]# mkdir dir3

1.并级

	[root@bigdata22 ~]# mkdir dir1 dir2 dir3

2.串级

	[root@bigdata22 ~]# mkdir -p dir4/dir5/dir6

cd 切换目录、路径、文件夹

[root@bigdata22 ~]# cd bigdata/

绝对路径:光标从 根目录开始的 cd /root/dir2
相对路径:光标从 当前开始 cd ./dir2/

cd …/ 退回到上一层级目录

./ 当前目录 cd ./bigdata=cd bigdata/

cd - 回到上一次操作的目录

~ 当前用户的 家目录
root 家目录 /root
其他用户 xx 家目录 /home/xx

快速回到家目录

  1. cd /root
  2. cd 回车 ==>推荐
  3. cd ~

创建文件

1.touch 1.log

2.vi/vim 2.log

3.echo “bigdata” > 3.log

echo “bigdata” 打印

创建或者覆盖一个文件

追加

编辑文件 vi/vim

1.命令行模式 vim xx.log
2.编辑模式 按键盘 i键
按键盘 esc键
3.尾行模式 :wq
w 保存 q 退出 ! 强制

查看文件

cat 查看文件所有内容 输出到控制台

[root@bigdata10 bigdata]# vim 1.log
[root@bigdata10 bigdata]# cat 1.log
111111
222222
333333

more 文件内容 一页一页的 按空格 往下翻 q退出

less 文件内容 一页一页的 按上下键 q退出

tail实时查看文件新产生的内容

tail -f 2.log

在第二个会话加echo “00000000” >> 2.log 时,第一个会话会显示上第二个会话加上的东西,但是当第二个会话删除tail -f 2.log时,不会显示已被删除,第二个会话再次建立vim 2.log时第一个会话也不会显示

tail -F 2.log

在第二个会话加echo “11111111” >> 2.log 时,第一个会话会显示上第二个会话加上的东西,当第二个会话删除tail -f 2.log时,会显示已被删除,第二个会话再次建立vim 2.log时,第一个会话会显示已连接,第二个会话再次加东西时,第一个会话还会显示

ctrl +c / ctrl +z 中断命令

如何定位 error信息

第一步vim xxx.log
第二步:/要找的词
n 查找下一个词 N 找上一个词
cat 2.log | grep -A 3 error > error.log =》 过滤含有error和 后3行
cat 2.log | grep -B 3 error > error.log =》 过滤含有error 和前3行
cat 2.log | grep -C 3 error > ~/error.log =》 过滤含有error和 前后各3行
cat 2.log | grep error > error.log 过滤只含有error的
| 管道符 =》上一个命令的结果 作为下一个命令的输入 grep 过滤 文本所在的一行

tab自动补全

按一次 匹配的东西 就一个 自动补全
按两次 把匹配东西全部匹配出来

清屏

clear ctrl +l

查看历史命令 history

mv 移动 始终是一份 cp 复制 两份

mv dir1 bigdata
cp -r dir2 bigdata
改名字:mv dir1 dir1_idk
cp -r dir2 dir2_idk

rm 删除文件或者文件夹

有删除提示: 删除文件:rm error.log
删除文件夹: rm -r dir3
强制删除:没有提示 删除文件 rm -f 2.log
删除文件夹 rm -r -f dir2
rm -r -f xxx => rm -rf xxx

用户样式缺失问题
[root@bigdata10 bigdata]# su - uzi
上一次登录:四 113 12:18:44 CST 2022pts/0[uzi@bigdata10 ~]$ rm -rf ./.*
rm: refusing to remove "." or ".." directory: skipping "./."
rm: refusing to remove "." or ".." directory: skipping "./.."
[uzi@bigdata10 ~]$ exit
登出
[root@bigdata10 bigdata]# su - uzi
上一次登录:四 113 12:25:19 CST 2022pts/0-bash-4.2$ cp /etc/skel/.* ./
cp: 略过目录"/etc/skel/."
cp: 略过目录"/etc/skel/.."
cp: 略过目录"/etc/skel/.mozilla"
-bash-4.2$ exit
登出
[root@bigdata10 bigdata]# su - uzi
上一次登录:四 113 12:31:45 CST 2022pts/0[uzi@bigdata10 ~]$
切换用户有提示错误
 [root@bigdata10 bigdata]# vim /etc/passwd
uzi:x:1001:1001::/home/uzi:/sbin/nologin
[root@bigdata10 bigdata]# su - uzi
上一次登录:四 113 12:43:08 CST 2022pts/0This account is currently not available.
[root@bigdata10 bigdata]# vim /etc/passwd
uzi:x:1001:1001::/home/uzi:/bin/bash
[root@bigdata10 bigdata]# su - uzi
上一次登录:四 113 12:50:27 CST 2022pts/0[uzi@bigdata10 ~]$
切换用户无提示错误
 [root@bigdata10 bigdata]# vim /etc/passwd
uzi:x:1001:1001::/home/uzi:/usr/bin/false
[root@bigdata10 bigdata]# su - uzi
上一次登录:四 113 12:51:35 CST 2022pts/0[root@bigdata10 bigdata]#
[root@bigdata10 bigdata]# vim /etc/passwd
uzi:x:1001:1001::/home/uzi:/bin/bash
[root@bigdata10 bigdata]# su - uzi
上一次登录:四 113 12:53:17 CST 2022pts/0[uzi@bigdata10 ~]$

别名 alias

仅仅是当前会话生效

[root@bigdata12 shell]# cd ../
[root@bigdata12 ~]# alias aa='cd shell/'
[root@bigdata12 ~]# aa

环境变量

环境变量路径:[root@bigdata22 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
1.全局环境变量
vim /etc/profile 所有用户都可以使用
2.个人环境变量 只能当前用户使用 其他用户 不能使用
vim ~/.bashrc 【建议】
vim ~/.bash_profile
3.生效环境变量
1.source /etc/profile
source ~/.bashrc
2.重新打开一个会话

全局变量
[root@bigdata10 bigdata]# vim /etc/profile
alias bb='cd ./dir2'
alias cc='cd ./dir3'
[root@bigdata10 bigdata]# source /etc/profile
[root@bigdata10 bigdata]# bb
[root@bigdata10 dir2]# cd ../
[root@bigdata10 bigdata]# su - uzi
上一次登录:四 113 12:11:08 CST 2022pts/0[uzi@bigdata10 ~]$ source /etc/profile
[uzi@bigdata10 ~]$ bb
[uzi@bigdata10 dir2]$
局部变量
[root@bigdata10 bigdata]# vim ~/.bashrc
alias ff='cd ./dir1
[root@bigdata10 bigdata]# source ~/.bashrc
[root@bigdata10 bigdata]# ff
[root@bigdata10 dir1]# cd ../
[root@bigdata10 bigdata]# su - uzi
上一次登录:四 113 12:18:44 CST 2022pts/0[uzi@bigdata10 ~]$ source ~/.bashrc
[uzi@bigdata10 ~]$ ff
bash: ff: 未找到命令...
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值