shell常用汇总

/ shell / 0 条评论 / 981浏览
1. sshpass
sshpass -p wj770826 scp -r tag_UEM5.1 [email protected]:/home/  
ps -ef | grep tomcat | awk -F '[ ]+' '{print $2}' | xargs kill 9  多个空格分隔
备份job: sshpass -p 'wj770826'  rsync -av -e ssh --exclude="archive" --exclude="log" /root/.jenkins/jobs/  [email protected]:/home/jenkinsJobBak/`date "+%Y-%m-%d"
sed -i 's|`cat\ /mdmconfig/Daily/GitPath`|"/home/EMMServerBemail"|g' grep -rl "\`cat /mdmconfig/Daily/GitPath\`" *.sh

2. 查看文件夹大小
du -h --max-depth=0 lost+found  //文件夹大小
du -h --max-depth=1  #mac: du -hd1

3. 查找近期文件
find ./ -mtime +5  -exec rm -rf {} \;
+ 以前
-  之内
无  包括这一天以前


4.结束进程
ps -ef | grep gradle | cut -c 9-15| xargs kill -9
find . -name ".git" | xargs rm -Rf
ls | grep '^[A-Z]*[A-Z1-9]$' | xargs ls
$?    --上一个命令返回值

5. IDLE
1.Python增加缩进快捷键:Ctrl+Alt+] 或tab键或shift+tab键
2.Python减少缩进快捷键:Ctrl+Alt+[ 

6. FTP 550 Failed to change directory
https://blog.csdn.net/coreyC/article/details/80866533
getsebool -a | grep ftp
setsebool -P allow_ftpd_full_access on
setsebool -P ftp_home_dir on

7. expect + spawn
expect -c "set timeout -1
           #spawn scp -r /var/www/tag/$Tag_new [email protected]:/home/tag_master
           spawn scp -r /var/www/tag/$Tag_new [email protected]:/home/tag_UEM5.3
           expect {
            \"*yes/no*\" {send \"yes\r\";exp_continue}
             \"password:\" {send \"yhl1234\r\";exp_continue}
     }
     "

8. rpm相关
rpm打包禁止检测jar
 %define __jar_repack 0  ----spec文件修改
===========view and extract rpmfile===========================
rpm2cpio mdm-5.0.0.69-0.x86_64.rpm | cpio -idmv
rpm2cpio xxx.rpm | cpio -div //解压
rpmbuild -bb nginx-1.15.8.spec

rpm -qa | grep NQClient  //查询
rpm -e NQClientUpdate-5.3.0.153-0.x86_64  //卸载
rpm -ivh NQClientUpdate-5.3.0.153-0.x86_64.rpm //安装
service tomcat restart  //重启
yum provides */nslookup  //查找库中的
$yum install rpmbuild
$yum install rpmdevtools
免注册方式下载jdk:wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz


9.查找文件夹中某文件包含内容
find ./ -name "*.*" | xargs grep bemailconfig
4528182F7AB3CED2

10. ftp登录上传
ftp -n<<!
        open 192.168.33.170
        user yjy yjyyjy
        prompt
        cd 标准产品/UEM.5.3.0_201906272256
        binary
        mput *
        close
        bye
!

11.  git操作
丢弃本地修改:
git checkout .
checkout远程分支:
git checkout -b UEM5.0 origin/UEM5.0.0
git branch -d <BranchName>  //删除本地分支
git push origin --delete <BranchName> //删除远程分支
git branch     //本地分支
git branch -a  //所有分支

12.  文件夹git remote地址更新
function getdir(){
    cd /home
    dirs=`ls | grep '^[A-Z]*[A-Z1-9]$'`
    for element in $dirs
    do 
        dir_or_file="/home/"$element
        module_of_dir=`ls $dir_or_file`
        for mod in $module_of_dir
        do
            #if [[ "$mod" != "Packages" ]] && [[ "$mod" != "Package" ]] && [[ "$mod" != "client" ]] && [[ "$mod" != "package" ]]
            #then
                moudle_path=$dir_or_file"/"$mod
                #echo $moudle_path
                if [ -d $moudle_path ]
                then
                    cd $moudle_path
                    if [ -d $moudle_path"/.git" ]
                    then
                        res=`git remote -v | head -1 | awk '{sub(/.{8}$/,"")}1'`
                        if [[ $res == *yanghailong@* ]] ||  [[ $res == *//192.168* ]] #|| [[ $res == *Not\ a\ git\ repository* ]]
                        then
                            continue
                        else
                            echo $moudle_path
                            res2=${res/http:\/\/*@/http:\/\/}
                            `git remote set-url $res2`
                            echo "git remote set-url $res2"
                        fi
                    fi
                fi
            #fi
        done 
    done
}

13. gradle assemble
https://segmentfault.com/a/1190000012730220
gardle : assembleRelease task
export ANDROID_NDK_HOME=/home/myself/bin/android-ndk-r10e

14.解决Ubuntu下编译.sh文件报错 “[: XXXX: unexpected operator”
https://yangfannie.com/1428.html
sudo dpkg-reconfigure dash

ubuntu16.04 关闭3d【Compiz:Ubuntu的3D效果
sudo apt-get install gnome-session-flashback
sudo apt-get autoremove compiz compiz-gnome compiz-core compiz-plugins-default
重新登录系统,在用户名的右侧,会有个按钮,选择 GNOME Flashback(Metacity)选项,就进入了另一个风格的界面


ubuntu菜单栏被禁用:
 unity –reset-icons &disown 
进入经典gnome桌面
 sudo apt-get install gnome-session-flashback

chkconfig
如何增加一个服务:
1.服务脚本必须存放在/etc/ini.d/目录下;
2.chkconfig –add servicename
在chkconfig工具服务列表中增加此服务,此时服务会被在/etc/rc.d/rcN.d中赋予K/S入口了;
3.chkconfig –level 35 mysqld on
修改服务的默认启动等级。

crontab

评论已关闭.