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. LeetCode——Populating Next Right Pointers in Each Node II

    Follow up for problem "Populating Next Right Pointers in Each Node". What if the given tre ...

  2. opencv 边缘羽化,边缘过渡

    原地址:http://blog.csdn.net/sogarme/article/details/12942971 当把前景和背景分开时,黑色代表背景,白色代表前景,如下图1—记作img1 为了平滑过 ...

  3. YUV格式具体解释

    YUV是指亮度參量和色度參量分开表示的像素格式,而这样分开的优点就是不但能够避免相互干扰,还能够减少色度的採样率而不会对图像质量影响太大.YUV是一个比較笼统地说法,针对它的详细排列方式,能够分为非常 ...

  4. wkhtmtopdf--高分辨率转HTML成PDF--目录篇

    原文:wkhtmtopdf--高分辨率转HTML成PDF--目录篇 wkhtmtopdf--高分辨率转HTML成PDF(一):简述wkhtmtopdf的简介和安装 wkhtmtopdf--高分辨率转H ...

  5. python语言学习9——使用list和tuple

    list Python内置的一种数据类型是列表:list.list是一种有序的集合,可以随时添加和删除其中的元素. 位置 用索引来访问list中每一个位置的元素,记得索引是从0开始的,到 len-1结 ...

  6. php学习之道:php中soap的使用实例以及生成WSDL文件,提供自己主动生成WSDL文件的类库——SoapDiscovery.class.php类

    1. web service普及: Webservice soap wsdl差别之个人见解 Web Service实现业务诉求:  Web Service是真正"办事"的那个,提供 ...

  7. poj2411(状压dp)

    题目链接:http://poj.org/problem?id=2411 题意:由1*2 的矩形通过组合拼成大矩形,求拼成指定的大矩形有几种拼法. 分析:如果是横着的就定义11,如果竖着的定义为竖着的0 ...

  8. Mysql怎样删除以“#sql-”开头的暂时表

    author:skate time:2014/09/28 Mysql怎样删除以"#sql-"开头的暂时表 现象:在重建索引后,发现Mysqlserver的磁盘空间快满了 在用例如以 ...

  9. Python 类继承,__bases__, __mro__, super

    Python是面向对象的编程语言,也支持类继承. >>> class Base: ... pass ... >>> class Derived(Base): ... ...

  10. Linux好书、经典书籍推荐

    Linux好书.经典书籍推荐 思想篇 <Linux/Unix设计思想> 图书将Unix与Linux的原理有效地结合起来,总结了Unix/Linux软件开发中的原则.在保留了第1版中Unix ...