第一周实习总结

linux用法

如何进入带空格文件夹

有时候需要创建带有空格的文件夹,虽然这不是一个好的习惯,但是偶尔会遇到。用的最多的是很多时候需要进入带有空格的文件夹,如"a b"是一个文件夹名。

创建:

mkdir "a b"
mkdir 'a b'
mkdir a\ b

进入:

cd "a b"
cd 'a b'
cd a\ b

由上可见,需要在带有空格的文件夹名前面加上引号(单引号或者双引号),另一种方法是在空格前面加\,\的意思是后面还有字符的意思。

切记,直接输名字是无法操作成功的,如已经创建了文件夹"a b",直接终端输入cd a b会出现没有a文件夹的错误。而如果没有创建"a b"文件夹,使用mkdir a b,会创建两个文件夹,一个名字为a,一个为b。

上传文件至服务器/从服务器下载文件:scp

  • 上传本地文件到服务器
    scp local_file remote_username@remote_ip:remote_folder
    scp local_file remote_username@remote_ip:remote_file

  • 上传目录到服务器
    scp -r local_folder remote_username@remote_ip:remote_folder

  • 从服务器下载文件
    scp remote_username@remote_ip:remote_file local_file

  • 从服务器下载整个目录
    scp -r local_folder remote_username@remote_ip:remote_folder

nohup

Linux 技巧:让进程在后台可靠运行的几种方法
我们经常会碰到这样的问题,用 telnet/ssh 登录了远程的 Linux 服务器,运行了一些耗时较长的任务, 结果却由于网络的不稳定导致任务中途失败。如何让命令提交后不受本地关闭终端窗口/网络断开连接的干扰呢?

场景:
如果只是临时有一个命令需要长时间运行,什么方法能最简便的保证它在后台稳定运行呢?

hangup 名称的来由
在 Unix 的早期版本中,每个终端都会通过 modem 和系统通讯。当用户 logout 时,modem 就会挂断(hang up)电话。 同理,当 modem 断开连接时,就会给终端发送 hangup 信号来通知其关闭所有子进程。

解决方法:
我们知道,当用户注销(logout)或者网络断开时,终端会收到 HUP(hangup)信号从而关闭其所有子进程。因此,我们的解决办法就有两种途径:要么让进程忽略 HUP 信号,要么让进程运行在新的会话里从而成为不属于此终端的子进程

nohup 的用途就是让提交的命令忽略 hangup 信号。让我们先来看一下 nohup 的帮助信息:

NOHUP(1)                        User Commands                        NOHUP(1)
 
NAME
       nohup - run a command immune to hangups, with output to a non-tty
 
SYNOPSIS
       nohup COMMAND [ARG]...
       nohup OPTION
 
DESCRIPTION
       Run COMMAND, ignoring hangup signals.
 
       --help display this help and exit
 
       --version
              output version information and exit
可见,nohup 的使用是十分方便的,只需在要处理的命令前加上 nohup 即可,标准输出和标准错误缺省会被重定向到 nohup.out 文件中。一般我们可在结尾加上"&"来将命令同时放入后台运行,也可用">filename 2>&1"来更改缺省的重定向文件名。

nohup 示例

[root@pvcent107 ~]# nohup ping www.ibm.com &
[1] 3059
nohup: appending output to `nohup.out'
[root@pvcent107 ~]# ps -ef |grep 3059
root      3059   984  0 21:06 pts/3    00:00:00 ping www.ibm.com
root      3067   984  0 21:06 pts/3    00:00:00 grep 3059
[root@pvcent107 ~]#
nohup ./*.sh parameters > test.log 2>&1 &

tail命令

每天一个Linux命令:tail
tail 命令从指定点开始将文件写到标准输出.使用tail命令的-f选项可以方便的查阅正在改变的日志文件,tail -f filename会把filename里最尾部的内容显示在屏幕上,并且不断刷新,使你看到最新的文件内容.。

>命令

linux >和>>的区别
>> 是追加内容

> 是覆盖原有内容

示例:

bogon:Desktop wenxuechao$ echo 'abc' > test.txt
bogon:Desktop wenxuechao$ echo '123' >> test.txt

执行效果,第一句命令会在桌面创建个test.txt的文件,并且将abc写到文件中。
第二句命令,会在文件下方,再次写入内容。

shell

while循环

#!/bin/bash
startDate=$1 #2018-12-01
period=$2 #19
endDate=`date -d "$startDate $period days" +"%Y-%m-%d"`
echo "runing period: $startDate -- $endDate"
runDate=$startDate

while(( $period>=0 )) 
do         
	echo "-----------------------start running $runDate----------------------"  
	echo -e "\n"	
	#pig -p logdate=$runDate smartBanner.pig	
	echo "------------------------finish running $runDate------------------------"
	echo -e "\n\n"
	runDate=`date -d "$runDate 1 days" +"%Y-%m-%d"`
	let "period--"
done 

shell脚本运行

chmod +x ./*.sh
./*.sh

文件格式改为linux格式

sh脚本运行报错:/bin/sh^M:bad interpreter: No such file or directory
解决方案: https://www.cnblogs.com/pipelone/archive/2009/04/17/1437879.html
关于shell脚本提示No such file or directory的解决办法和原因
Linux运行shell脚本提示No such file or directory错误的解决办法

vim filename
:set fileencoding #查看文件编码
:set fileformat=unix #在vim命令模式下改变文件格式
:x! #保存文档

Hadoop

hadoop fs -ls
hadoop fs -text */part* > local file

Pig

https://www.codelast.com/原创apache-pig的一些基础概念及用法总结(2)/
“scalar has more than one row in the output”错误的一个原因
遇到了这个错误?我来演示一下如何复现这个错误。
假设有两个文件:

[root@localhost ~]$ cat a.txt 
1 2
3 4
[root@localhost ~]$ cat b.txt 
3 4
5 6

现在我们来做一个JOIN:

A = LOAD 'a.txt' AS (col1: int, col2: int);
B = LOAD 'b.txt' AS (col1: int, col2: int);
C = JOIN A BY col1, B BY col1;
D = FOREACH C GENERATE A.col1;
DUMP D;

这段代码是必然会fail的,错误提示为:

org.apache.pig.backend.executionengine.ExecException: ERROR 0: Scalar has more than one row in the output. 1st : (1,2), 2nd :(3,4)

乍一看,似乎代码简单得一点问题都没有啊?其实仔细一看,“A.col1”的写法根本就是错误的,应该写成“A::col1”才对,因为你只要 DESCRIBE 一下 C 的schema就明白了:

C: {A::col1: int,A::col2: int,B::col1: int,B::col2: int}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值