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. 使用SetUnhandledExceptionFilter转储程序崩溃时内存DMP注意事项

    使用代码手工生成dmp文件 SetUnhandledExceptionFilter 为每个线程设置SetUnhandledExceptionFilter(MyCallBack),(必须在每个线程中启动 ...

  2. operator= 复制操作符的意外

    首先,看以下的代码的输出时什么: 上述代码做了最理所当然的事.就是将Derived的两个对象进行了交换.可是通过指针进行的赋值输出却不是预期的: 居然调用的是Base的operator=,也就意味着我 ...

  3. dokcer 运行和进入容器

    <pre name="code" class="html">docker:/root# docker run -itd --name zjtest8 ...

  4. C#实现树的双亲表示法

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbHVja3k1MTIyMg==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...

  5. uva live-2322 - Wooden Sticks

    首先排个序,然后找一次0花费,然后再找一次0花费,然后再找一次0花费,然后再找一次0花费......... 最后看找了几次,+1就是答案 #include<iostream> #inclu ...

  6. expdp时遇到ORA-31693&amp;ORA-02354&amp;ORA-01466

    expdp时遇到ORA-31693&ORA-02354&ORA-01466 对一个schema运行expdp导出,expdp命令: nohup expdp HQ_X1/HQ_X1 DU ...

  7. android greenDao SQLite数据库操作使用的工具

    关于如何建立类生成一个演示project.今天介绍如何使用. 这是ExampleDaoGeneratorproject代码,做了一些改动 /* * Copyright (C) 2011 Markus ...

  8. hdu1069(dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069 分析: 每种石头有六种方法,那么等效为:有6*n种石头. 根据x和y排序(要保证相应的x.y总有 ...

  9. Flex中的DataGrid报错(二)

    1.错误描写叙述 此行的多个标记: -holeNum -1067: String 类型值的隐式强制指令的目标是非相关类型 mx.controls:Text. 2.错误原因  将字符串类型赋值给Text ...

  10. dsbskrhkme看么哦么

    http://pan.baidu.com/share/link?shareid=3011665141&uk=338692646&third=15                http ...