1   ps  -ef    显示正在执行的进程,pid 等信息

 UID PID PPID C STIME TTY TIME CMD
root 1 0 0 03:45 ? 00:00:02 init [5]
root 2 1 0 03:45 ?

00:00:00 [migration/0]

root 3 1 0 03:45 ? 00:00:00 [ksoftirqd/0]
root 4 1 0 03:45 ? 00:00:00 [events/0]
root 5 1 0 03:45 ?

00:00:00 [khelper]

root 6 1 0 03:45 ? 00:00:00 [kthread]
root 9 6 0 03:45 ?

00:00:00 [kblockd/0]

root 10 6 0 03:45 ? 00:00:00 [kacpid]


2   df    -h    可读显示磁盘空间   M是兆
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 18G 5.0G 12G 31% /
/dev/sda1 289M 16M 258M 6% /boot
tmpfs 506M 0 506M 0% /dev/shm

3  借助df命令,能够方便地了解磁盘是否已空间不足,系统管理员须要了解空间不足时该怎么办。

 我们能够使用du命令 ,du命令显示特定文件夹的磁盘使用情况,这是推断系统是否存在磁盘
占用大户的快捷方法。
du    ,   du  -h(显示M。G单位)  ,du  -c (汇总),du  -s(汇总全部。仅仅显示一个)
du [ -a | -s ] [ -k ] [ -m ] [ -g ][ -l ] [ -r ] [ -x ] [ -H | -L ][ File ... ] 

8.0K ./test_flume/.flumespool
24K ./test_flume
8.0K ./mnt
58M ./awk
28K ./shell
18M ./spark
76M .

4   sort  (排序)  sort  file.txt

默认按字符排序
数字排序   sort -n  file.txt
sort -n file2
0
2
3
5
6
7
9
17

sort  -M  file3.txt  (依照月份排序)

sort -t ':' -k 3 -n /etc/passwd  按指定分隔符':" 第三个字段进行排序  按数字排序的

du -sh * | sort -nr  按空间占用从大到小 排序  包含目录和文件    r是指降序排列

5   gzip :用于压缩文件

gzip  2.sh
gzip  file*
gzip -r  test1  test2  压缩2个文件


tar  -cvf  my.tar  my.sh    tar压缩
tar -xvf  my。

tar      tar解压


tar  -zxvf filename.tgz

7 打印环境变量
  printenv 

bash
test=testing
echo $test

7  finger  llisc

/usr/sbin/groupadd shared

/usr/sbin/usermod -G shared test

文件权限表    755 




chmod o+r  newfile 
将条目读取加入到不论什么人

chmod u-x newfile 
将条目山下湖用户拥有的运行权限
chmod u+x newfile 

chown  改动用户文件拥有者 和所在组


9 shell  

rpm  -qa | sort  | more 

echo $?






if   表达式  返回0  运行成功
then
fi


if   test [ condition ]


for  var  in Li72 Alibaba taobao Newbatilr
do
  echo the state $test
done


使用转移字符反斜杠符合来转移单引號
使用双引號来定义单引號的值


#!/bin/bash
for file in /home/bigdata/test/*  /home/li75/
do
  if [ -d "$file" ]
then
  echo "$file is a directory "
elif [ -f "$file" ]
then
  echo "$file is a file "
fi
done




#!/bin/bash
for(( i=1; i<= 10; i++))
do
 echo " The next number is $i"
done


#!/bin/bash
 var1=10
while [ $var1 -gt 0 ]
do
  echo $var1
  var1=$[ $var1 - 1 ]
done


#!/bin/bash
var1=100
until [ $var1 -eq 0 ]
do
 echo $var1
  var1 =$[ $var1 -25 ]
done


#!/bin/bash
for((a =1; a<=3; a++))
do
  echo "starting loop $a:"
for((b=1;b<=3;b++))
  do
  echo " inside loop: $a*$b "
done
done


break
contince


#!/bin/bash
for(( a=1; a<4 ;a++))
do
  echo "Outer loop :$a"
 for((b=1;b<100;b++))
do
 if [ $b -gt 4 ]
then
  break 2
fi
echo "Inner loop :$b"
done
done > test.txt   重定向到一个文件
        |  sort   排序


參数
 位置參数
$0 为为程序名称
 $1 为第一个參数
$2 为第二个參数
$3 为第三个參数


#!/bin/bash
factorial=1
for((number =1;number<= $1;number++))
do
  factorial=$[ $factorial * $number ]
done
echo  The factorial of $1 is  $factorial



name =` basename $0`
获取执行shell 脚本名称



if   [ -n "$1" ]
推断有没有传入參数

if  [ $# <5 ]
推断传入參数个数

 获取最后一个參数的值
 params =$#

echo  parm : $params
或者
The  last   paramer ${!#}   


  $* 把全部的參数当作一个參数
  $@ 把全部參数当作字符串  分开处理


#!/bin/bash
while [ -n "$1" ]
 do
    case  "$1" in
-a) echo "Found the -a  option" ;;
-b) echo "Found the -b option" ;;
-c) echo "Found the -c option";;
*) echo "$1 is not an option";;
  esac
 shift
done





#!/bin/bash
echo -n 'Enter your name :"
read name
echo "Hello $name,  welcome to my prorram ."


#!/bin/bash
read -p "Please enter your age :" age
days =$[ $age * 365 ]
echo " That makes you over $days days old !"

ls -al test test22 test3 badtest &>test7

#!/bin/bash
echo "This is an error " >&2
echo "This is normal output "

#!/bin/bash
exec 1>testout
echo "This is a test of redirting all output"
echo "without having to redirect every line "

#!/bin/bash
exec 2>testerror

echo "This is the start of the script"
echo "now reidirecting all output to another "
exec 1>testout2

echo "This putput should go to the "
echo "but shis should go to testerror file >&2



#!/bin/bash
exec 0<testfile2
count=1
while read line
do
   echo "Line #$count :$line"
  count=$[ $count +1 ]
done

lsof -a -p $$ -d 0,1,2

重定向到空文件  
ls -al >/dev/null

cat /dev/null > testfile 

同一时候记录文件和打印到屏幕

date | tee testfile

追加数据

date | tee -a testfile

kill -9   进程id



#!/bin/bash
trap "echo HaHa " SIGINT SIGTEERM
echo "THis is a test program "
count=1
while [ $count -le 10 ]
do
  echo "Loop #$count"
sleep 10
count=$[ $count +1  ]
done
 echo "This is the end of test program "


把命令在后台执行用  &

sh 37.sh &

ps  au

有时须要从终端启动会话,然后让脚本在结束之前以后台模式执行,即使退出终端会话有时如此
能够用nohup

jobs
jobs -r
jobs -s
jobs -l

nice  设置优先级

nice -n 10 sh 38.sh >test4out &



at  命令
batch  命令
cron  表格


#!/bin/bash
time=`date +%T`
echo "This script ran at $time "
echo "This is the end of the script">&2


corn   表格使用特殊格式制定作业的时间。


15 10 * * * command

查看登陆用户配置的定时任务

crontab -l 

编辑任务
corntab -e 


#!/bin/bash
function func1 {
  echo 'This is an example of a function"
  }
count=1
while [ $count -le 5 ]
do
 func1
 count=$[ $count +1 ]
done
 echo "This is the end of the loop"
func1
 echo "Now  this is the end of the script "

函数的返回值
$?

#!/bin/bash
func1(){
echo "trying to display a non"
ls -ls 41.sh
}
echo "testing the function:"
func1
echo "The exit status is :$?

"


#!/bin/bash
function db1 {
read -p "Enter a value :" value
 echo "doubling the value "
 return $[ $value * 2 ]
}
db1 
echo "The new value is $?"


函数返回值

#!/bin/bash
function db1{
read -p "Enter a value :" value
echo $ [ $value *2 ]
}

result='db1'
echo 'The new value is $result"


提供函数文件
   能够用source  命令或称(点操作符)将现有的库函数引进.bashrc中

source   /home/li72/libraries/myfuncs
.    /home/li72/libraries/myfuncs


function addem   {
echo $[ $1 +$2 ]
}

function multem {
  echo $[ $1 * $2 ]
}

function divem {
  if [ $2 -ne 0 ]
  then 
   echo $[ $1 /$2 ]
else 
   echo -1
fi
}


#!/bin/bash
. ./myfuncs

result=`addem 10 16`
echo "The result is $result"

.bashrc  每次启动shell 都会检查该文件  ,在已有文件的末尾加入自己定义函数

.  /home/bigdata/test/shell/myfuncs

文本处理
sed    luinx 编辑替换

gawk


echo "This is a test " | sed 's/test/big test/'

cat>dog.txt
The  quick brown fox jumps over the lazy dog .
The  quick brown fox jumps over the lazy dog .
The  quick brown fox jumps over the lazy dog .
The  quick brown fox jumps over the lazy dog .
The  quick brown fox jumps over the lazy dog .

sed 's/dog/cat/' dog.txt    
The quick brown fox jumps over the lazy cat .
The quick brown fox jumps over the lazy cat .
The quick brown fox jumps over the lazy cat .
The quick brown fox jumps over the lazy cat .
The quick brown fox jumps over the lazy cat .


sed -e '
> s/brown/green/
> s/fox/elephant/
> s/dog/cat/' dog.txt

The quick green elephant jumps over the lazy cat .
The quick green elephant jumps over the lazy cat .
The quick green elephant jumps over the lazy cat .
The quick green elephant jumps over the lazy cat .
The quick green elephant jumps over the lazy cat .

从文件读取编辑器命令
 cat>script
s/brown/green/
s/fox/elephant/
s/dog/cat/


sed -f script dog.txt

The quick green elephant jumps over the lazy cat .
The quick green elephant jumps over the lazy cat .
The quick green elephant jumps over the lazy cat .
The quick green elephant jumps over the lazy cat .
The quick green elephant jumps over the lazy cat .


cat>script2
{print $5 "'s userid is " $1 }

加入用户

useradd xuhui
改动password
usermod  -p xuhui xuhui

查看password文件
tail -l /etc/shadow


cd -  返回上一个訪问的文件夹

查找文件命令

find  [路径]  [选项]  [操作]




find . -name 'test*'    查找 文件名为 test开头的


find . -mtime -90 -print  查找更改时间在90天内的文件

grep  [选项]  [模式]  [文件]



在wodl.txt  找World单词
grep -w  'World' wodl.txt



















lunix shell 基础经常使用整理的更多相关文章

  1. Linux 究级基础入门命令整理

    Linux 究级基础入门命令整理 条条框框,三三两两,怎讷个这么多,哈哈!no zuo no die. 纯粹个人菜鸟笔记,望大神笑纳! 后续,未完!! 查看系统信息 uname -a - 查看内核/操 ...

  2. Shell基础学习小结

    0 shell基础概念 Shell是解释性语言,使用脚本编程语言的好处是,它们多半运行在比编译型语言还高的层级,能够轻易处理文件与目录之类的对象:缺点是它们的效率通常不如编译型语言.Shell命令有本 ...

  3. Shell基础-环境变量配置文件

    Shell基础-环境变量配置文件 source 配置文件 或者 . 配置文件: 把环境变量写入配置文件后,需要用户重新登陆才能生效,而是用source命令,则能直接生效 主要的配置文件: /etc/p ...

  4. shell基础二十篇 一些笔记

    shell基础二十篇 转自 http://bbs.chinaunix.net/thread-452942-1-1.html 研讨:Bash 内建命令 read (read命令更具体的说明见博客收藏的一 ...

  5. shell基础(转)

    shell基础1:文件安全与权限 http://bbs.chinaunix.net/forum/viewtopic.php?t=434579&highlight=wingger 附:Linux ...

  6. Linux实战教学笔记17:精简shell基础

    第十七节 精简shell基础 标签(空格分隔): Linux实战教学笔记 1,前言 1.1 为什么学习shell编程 Shell脚本语言是实现Linux/UNIX系统管理及自动化运维所必备的重要工具, ...

  7. CU社区shell板块awk十三问整理

    CU社区shell板块awk十三问整理 一.RS="" 当 RS="" 时,会将\n强制加入到FS变量中,因为RS为空时,是将连续多空行作为分隔符,近似于\n\ ...

  8. shell基础及变量

    一 Shell概述 1.Shell的作用——命令解释器,“翻译官” shell作为一个人机接口,用于解释用户输入的命令,将命令解释为Linux内核可以执行的2进制代码,并将执行的结果返回在标准终端上. ...

  9. Shell 基础教程

    一个比较好的shell基础教程: http://www.runoob.com/linux/linux-shell.html

随机推荐

  1. Common lisp菜鸟指南(译)

    Common lisp菜鸟指南(译) Common lisp菜鸟指南(译)

  2. Hibernate(六)——多对多关联映射

    前面几篇文章已经较讲解了三大种关联映射,多对多映射就非常简单了,不过出于对关联映射完整性的考虑,本文还是会简要介绍下多对多关联映射. 1.单向多对多关联映射 情景:一个用户可以有多个角色,比如数据录入 ...

  3. js错误 SyntaxError: missing : after property id

    在用jquery的post方法时 $.post('adminCheckTpmisPlans.do',{'test',str},function(f){ ... }) 报如下错误 SyntaxError ...

  4. 深度学习系列之CNN核心内容

    导读 怎么样来理解近期异常火热的深度学习网络?深度学习有什么亮点呢?答案事实上非常简答.今年十月份有幸參加了深圳高交会的中科院院士论坛.IEEE fellow汤晓欧做了一场精彩的报告,这个问题被汤大神 ...

  5. Note:This element neither has attached source nor attached Javadoc

    在用Eclipse编写程序时,发现把鼠标放到类名上时出现标题的提示 解决方法: 右击项目,选择 properties –> Java Build Path –> Libraries,如图 ...

  6. linux内核基础(系统调用,简明)

    内核基础(系统调用) 在说系统调用之前.先来说说内核是怎么和我们交互的.或者说是怎么和我们产生交集的. 首先,内核是用来控制硬件的仅仅有内核才干直接控制硬件,所以说内核非常重要,假设内核被控制那么电脑 ...

  7. ubuntu install mysql server method

         recently try to install mysql in my computer so that  I can practise some sql statement on seve ...

  8. ZOJ 1171 Sorting the Photos

    1. 题目描述 给你一叠照片,有的正面朝上,有的反面朝上,朝上的用字母U,朝下的用字母D 可以从一个位置开始到最顶端,把这一叠拿出来,反转,然后再放回那一叠照片上面. 试求出最少的翻转次数,使所有的照 ...

  9. 管理工具 Kafka Manager

    管理工具 Kafka Manager   一.概述 Kafka在雅虎内部被很多团队使用,媒体团队用它做实时分析流水线,可以处理高达20Gbps(压缩数据)的峰值带宽. 为了简化开发者和服务工程师维护K ...

  10. CString的部分实现剖析

    一.CString初探: 在CString的实现中,其最基础的类结构如下: CString其实只有一个数据成员m_pszData,这个成员指向了字符串的首地址.但在MFC的具体实现中, m_pszDa ...