Linux实用命令

来源:互联网 发布:苏州迈科网络 编辑:程序博客网 时间:2024/06/05 15:28

pwd: 显示当前用户的所在的目录

cd: 切换目录
   cd : 切换到当前用户的家目录
   cd ~ : 切换到当前用户的家目录
   cd /xxx : 切换到指定xxx目录 
   cd - : 切换到上一次的目录
   cd ../  : 退到上一层的目录
clear: 清空桌面

ls: 打印出当前目录的所有文件夹和文件的名称
   ls -l :打印出当前目录的所有文件夹和文件的名称、权限、日期
   ls -l -a或者 -la : 打印隐藏文件,隐藏文件的标识是以 .开头
ls -l -a、ls -la、ll -a 三种写法都可以

   ls -lh : 主要查看文件的大小
   ls -lrt :时间排序

怎样查看命令帮助?
man ls   -->Crtl+z 退出详细介绍
ls --help

mkdir : 创建文件夹
    mkdir xxx  创建xxx文件夹
    cd xxx , mkdir 001   xxx/001,进入xxx再创建的001

    等价于:
    mkdir -p rzdata01/001  级联创建

touch: 创建空文件
touch filename

查看文件内容:
cat filename  打印出所有的内容(内容太多的话建议使用more)
more filename 一页一页的翻   按空格键 一页页翻 有显示百分比

vi:命令
vi filename
i键-->编辑模式,增加删除修改文件内容
esc键 ,再按Shift+冒号键-->尾行模式, 按wq键保存退出

wq:保存退出
q!:强制退出,修改失效

查看IP:
 ifconfig
 hostname -i

实时查看文件内容  

 tail -f xxx.log
 tail -F xxx.log
 -F 是--follow=name --retry的缩写, --follow=name是按照文件名跟踪文件, 可以定期去重新打开文件检查文件是否被其它程序删除并重新建立. --retry这个参数, 保证文件重新建立后,可以继续被跟踪.

 -F参数区别:==》-f --retry

重命名: mv xxx1 xxx2  只存在一个文件
> :覆盖  (慎用)
>> : 追加

复制:
cp xxx1 xxx2 以前文件不动,产生新的文件

输出打印:
echo "123"

别名: alias (*)
alias 查看有哪些别名
临时:
alias xx='cd /home/xxx' 设置jh别名  注意:=前后没有空格

永久:
alias jh='cd /home/jepson' 配置到环境变量文件,执行生效命令

环境变量配置:配置软件的home目录
全局:
/etc/profile 
个人:
~/.bash_profile 或者 ~/.bashrc

生效命令: source /etc/profile
 . .bash_profile 或者 source .bash_profile


删除:
 rm 删除时询问
 rm -f 强制删除文件
  rm -r -f 强制删除文件夹
慎用: rm -rf /  

怎样查看历史命令?
history 查看
!142 执行142行的命令,142为history结果中命令的序号

怎样过滤出?
history  | grep xxx

用户、用户组的常用命令:

# ll /usr/sbin/user*

-rwxr-x---. 1 root root 103096 Dec  8  2011 /usr/sbin/useradd
-rwxr-x---. 1 root root  69560 Dec  8  2011 /usr/sbin/userdel
-rws--x--x. 1 root root  42384 Aug 23  2010 /usr/sbin/userhelper
-rwxr-x---. 1 root root  98680 Dec  8  2011 /usr/sbin/usermod
-rwsr-xr-x. 1 root root   9000 Nov 23  2013 /usr/sbin/usernetctl

# ll /usr/sbin/group*

-rwxr-x---. 1 root root 54968 Dec  8  2011 /usr/sbin/groupadd
-rwxr-x---. 1 root root 46512 Dec  8  2011 /usr/sbin/groupdel
-rwxr-x---. 1 root root 50800 Dec  8  2011 /usr/sbin/groupmems
-rwxr-x---. 1 root root 61360 Dec  8  2011 /usr/sbin/groupmod


添加一个用户到一个新的用户组

# usermod -a -G bigdata faker

# id faker

uid=501(faker) gid=501(faker) groups=501(faker),502(bigdata)

# usermod -g bigdata faker

# id faker

uid=501(faker) gid=502(bigdata) groups=502(bigdata)


修改密码:
# passwd jepson

怎样切换jepson用户

# su jepson

 执行切换用户的环境变量且 进入家目录
$ vi .bash_profile 
PATH=$PATH:$HOME/bin
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs
alias print='ls /tmp'
.......
.......
.......


临时获取root的最大权限sudo

修改/etc/sudoers,为一个用户加sudo权限,添加一行  
# vi /etc/sudoers
jepson  ALL=(root)      NOPASSWD:ALL

怎样查看进程?(*****)   
# ps -ef | grep ntp

ntp :进程运行user
1393 :pid  
1: 父进程id


杀死
# kill -9  1393 杀死1393进程

怎样查看端口号?(*****)
# netstat -nlp |grep ntp
      
# ps -ef|grep ntpd

打开某个xxx服务的web页面:ip+port  http://ip:port  

ps -ef|grep xxx -->pid  --->netstat -nlp|grep pid
等价于 
netstat -nlp|grep xxx


0.0.0.0 代表当前机器的ip   https://zhidao.baidu.com/question/68336330.html


权限(*****)
读 r 4
写 w 2
执行 x 1

第一位: -文件 d文件夹 l连接
第一组: rw-  root这个用户对这个文件只有读写权限
第二组: r--  root这个组的所有用户对这个文件只有读权限
第三组: r--  其他用户组的所有用户组对这个文件只有读权限

- 无权限,占位

chown: 修改文件夹或文件的所属的用户及用户组
chown -R jepson:jepson /0001
chown  jepson:jepson /root/xxx.log

chmod: 修改文件夹或文件的权限
chmod -R 777 /0001
chmod  777 /root/xxx.log
chmod  +x /root/xxx.log

文件夹 : -R 递归--》文件夹


安装rpm: yum 
yum install httpd
yum -y install httpd
service httpd status|start|stop|restart


搜索、卸载rpm:
# rpm -qa |grep http
httpd-tools-2.2.15-60.el6.centos.6.x86_64
httpd-2.2.15-60.el6.centos.6.x86_64


# rpm --nodeps -e httpd-2.2.15-60.el6.centos.6.x86_64
# rpm --nodeps -e  httpd-tools-2.2.15-60.el6.centos.6.x86_64 
# rpm -qa |grep http
# service httpd status
httpd: unrecognized service


--nodeps 不验证包的依赖关系 强行卸载

命令或某个文件在哪? --》搜索
which xxx
locate xxx
# find /root -name log
# find /root -name "*log*"    (**)

硬盘、内存、系统情况查看
df -h
free -m
top


怎样下载软件包:
wget  http://www.apache.org/dyn/closer.cgi/hadoop/common/hadoop-2.9.0/hadoop-2.9.0.tar.gz


压缩解压:
https://jingyan.baidu.com/article/6d704a13f9981a28da51ca70.html
tar 压缩解压
zip 压缩
unzip 解压

解压(***)
tar -xzvf hadoop-2.9.0.tar.gz    最常用的 频率最高的 
unzip xxx.zip

文件压缩
tar –czf jpg.tar.gz *.jpg  
zip xxx.zip  *.log

windows与linux交互: 
上传下载: yum install -y lrzsz
上传: rz
下载: sz 文件名

查看当前用户下哪些作业: crontab -l
添加、编辑:crontab -e
禁用:  加#

后台执行命令:
&
nohup
screen(yum install -y screen)

screen:
screen -list 查看会话
screen -S xxx 建立一个后台的会话
screen -r xxx/id 进入会话
退出会话: ctrl+a+d   分离

原创粉丝点击