Linux常用命令

1、系统开关及重启
1.1  退出的3种方式   
[root@localhost ~]# logout
[root@localhost ~]# exit
Ctrl+D(相当于exit)

1.2 重启动2种方式
[root@localhost ~]# reboot
[root@localhost ~]# shutdown  -r  <time>        
例:   shutdown  –r  now      现在立刻重启
        shutdown  –r  11:30    等到11:30进行重启

1.3  关机的2种方式
root@localhost ~]# halt
root@localhost ~]# shutdown  -h  <time>   
例:   shutdown  –h  now      现在立刻关闭系统

        shutdown  –h 11:30    等到11:30关闭系统  


2、切换用户

功能:切换用户   注意su  与su - 的区别

[macan@localhost ~]#su - root

普通用户切换到root用户,需要输入root的密码后回车
[root@localhost ~]# su   - macan
root用户切换到普通用户macan,无需输入密码


3、创建目录mkdir  与 删除目录rmdir或rm
3.1 功能:创建目录
格式:mkdir [ 参数 ] [目录名1 ] [ 目录名2 ]
[root@localhost ~]# mkdir      dir2                创建一个目录
[root@localhost ~]# ls                      借助ls命令查看dir2目录是否被创建
[root@localhost ~]#  mkdir  bb  cc  dd           一次性创建多个目录

3.2 功能:删除空目录
格式:rmdir  [目录1] [目录2 ] [目录3]…
[root@localhost ~]# rmdir    dir2        删除一个空目录
[root@localhost ~]# rmdir   bb  cc  dd     删除多个空目录

3.3 功能:删除文件或者删除非空目录
格式:rm  [参数]  文件或者目录
cp  dir1/myfile  dir1/11.txt
cp  dir1/myfile  dir1/22.txt
cp  dir1/myfile  dir1/33.txt    把dir1目录下myfile文件拷贝三次,生成文件名为11.txt,22.txt,33.txt文件      
ls dir1
[root@localhost ~]#  rm    myfile     删除当前目录下myfile文件
[root@localhost ~]#  rm   -r    ./dir1    删除当前目录下dir1目录,有提示
[root@localhost ~]#  rm   -rf    ./dir1    删除当前目录下dir1目录,不提示
[root@localhost ~]#  rm   -r  11.txt  22.txt  33.txt     删除当前目录下多个文件

4、复制文件或目录 cp
功能:拷贝文件或者目录
格式:cp  [ 参数 ]   [ 源文件或者目录 ]   [ 目标文件或者目录 ]
[root@localhost ~]#  ls
[root@localhost ~]# cp    hello   file1       把文件hello拷贝一份,命名file1
[root@localhost ~]#  ls
[root@localhost ~]# cp    ./hello    /home/test/dir1/a_dir/myfile
[root@localhost ~]#  ls  /home/test/dir1/a_dir/      //把当前目录下文件hello拷到绝对路径

5、移动文件或目录 mv
功能:可以对文件或者目录进行移动
格式:mv  [ 参数 ] [源对象][目的对象]
[root@localhost ~]#  pwd
[root@localhost ~]#  mv  ./dir1/a_dir/myfile  ./dir1/newfile    将文件myfile移动到新的目录下并改名为newfile
[root@localhost ~]#  ls  ./dir1
[root@localhost ~]# mv  /home/test/dir1/a_dir   /home/test/dir2   将目录a_dir移动到新的目录下并改名为dir2,也可以不该名
[root@localhost ~]# ls   ./dir1                             看a_dir目录是否被移走
[root@localhost ~]# ls                                         看dir2目录是否生成

6、 pwd
功能描述:查看用户当前所处的绝对路径
root@localhost ~]# pwd    

7、 ls

功能描述:显示指定目录下的内容
格式:ls   [ 参数 ]   [  目录或文件 ]
[root@localhost ~]#  ls        //显示当前目录内容
[root@localhost ~]#  ls   /home/test       显示指定目录/home/test下的内容
[root@localhost ~]#  ls    -l     显示当前目录详细内容

[root@localhost ~]#  ls   -a      显示当前目录下的所有文件,包括隐藏文件

[root@localhost ~]#  ls   -lrt      显示当前目录详细内容,并安装修改日期倒序显示


8、 cd
功能:改变目录
格式: cd 目录
[root@localhost ~]# cd  ..    回退到当前目录的上一级目录
[root@localhost ~]# pwd         (借助pwd命令查看当前处于什么目录)
[root@localhost ~]# cd        回到当前用户的主目录
[root@localhost ~]# pwd
[root@localhost ~]# cd   /home/test/dir1/a_dir    用绝对路径切换到a_dir目录下(假设此目录存在)
[root@localhost ~]# pwd
[root@localhost ~]# cd  ../../    使用相对路径切换到当前目录的上一级的上一级目录下
[root@localhost ~]# pwd


9、grep
功能:从某个文件中查询指定的字符串
格式: grep  [选项]  [查找模式]  [ 文件名1,文件名2…]
[root@localhost ~]# grep ‘bind’   hello           从文件hello中查找字符串bind
[root@localhost ~]# grep    ‘[a-zA-Z0-9]ind’   hello                  按照正则表达式,查找以字符或者数字开头连接ind的行

[root@localhost ~]# ps -ef|grep java  在所有的进程中查找带有java的


10、ps
显示进程信息
[root@localhost ~]# ps  -ef         //显示当前系统中运行的进程
[root@localhost ~]# ps  -ef|grep pid     //查询某个进程


11、 kill
功能:将指定的进程杀死
格式: kill  -n  pid
[root@localhost ~]# kill  -9  pid
通过ps  -ef   查找进程号,然后执行 kill  -9  进程号


12、ifconfig
[root@localhost ~]# ifconfig               功能:查看或者设置网络配置  
[root@localhost ~]#  ifconfig  eth0  192.168.0.200   功能:配置eth0的ip地址
[root@localhost ~]#  ifconfig  eth0  down   功能:禁用eth0网卡
[root@localhost ~]#  ifconfig  eth0  up         功能:启用eth0网卡


13、chmod
功能:修改文件的权限
格式:chmod  [参数]  权限  文件或者目录
[root@localhost ~]# chmod   755   hello   使用数字表示法修改文件myfile的权限
[root@localhost ~]# ls  -l hello                        使用ls命令查看权限修改结果

[root@localhost ~]# chmod   777   hello   使用数字表示法修改文件myfile的权限
[root@localhost ~]# ls  -l hello                        使用ls命令查看权限修改结果

14、打包tar、与压缩gzip
功能:将文件或者目录进行打包
格式: tar  [ 参数 ]  打包后的文件名  文件或目录
[root@localhost ~]# tar  cvf   test.tar    /home/test     把home下test目录打成tar包
[root@localhost ~]# tar     xvf    test.tar          把test.tar 解包

[root@localhost ~]# gzip   test.tar                      把test.tar文件进行压缩
[root@localhost ~]# gzip   –d   test.tar.gz      把test.tar.gz压缩包解压缩


15、echo

功能:在显示屏上回显文字或者用来查看环境变量的值
[root@localhost ~]#  echo “hello,boy”
[root@localhost ~]#  echo  $PATH

[root@localhost ~]#  echo  $JAVA_HOME





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值