Linux强制下线已登录用户

因为在用tmux的原因,使用lish登陆或者使用小窗口登陆终端后不下线,导致新开的全屏终端只能显示小小的一块,非常碍眼。所以这种时候需要强制让已登录的这些用户下线。

使用w或者last查看机器中登陆的用户

# w

16:29:02 up 2 days, 2:35, 5 users, load average: 0.03, 0.05, 0.01

USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT

root pts/1 :0.0 Tue15 2days 1:44 0.04s -bash

root pts/2 :0.0 Tue15 46:42m 0.05s 0.05s bash

把pts/1踢掉(只有root才能去踢掉用户)

# pkill -kill -t pts/1

查看是不是踢掉

# w

一个有趣的现象是,root出了可以踢掉其他用户,还可以踢掉当前正在登陆的自己。


Linux命令之find (1) - 查找

最近用到find的下面命令,简单记录一下。主要是与时间有关的find命令。

atime、ctime与mtime

先说说时间参数atime、ctime与mtime。

  • atime指access time,即文件新建或者执行的时间,修改文件是不会改变access time的。

  • ctime即change time文件状态改变时间,指文件的i结点被修改的时间,如通过chmod修改文件属性,ctime就会被修改。

  • mtime即modify time,指文件内容被修改的时间。

使用touch可以改变这三个时间。使用stat可以查看文件的信息。

# stat kelubksys.sh
  File: `kelubksys.sh'
  Size: 1063            Blocks: 8          IO Block: 4096   regular file
Device: ca00h/51712d    Inode: 99421       Links: 1
Access: (0755/-rwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2015-02-02 10:20:37.392697633 +0800
Modify: 2015-02-21 16:18:54.787485938 +0800
Change: 2015-02-21 16:18:54.787485938 +0800
 Birth: - 

也可以使用ls查看文件的atime、ctime、mtime。

ls -l		// modefiy
ls -lu	// access
ls -lc	// change

一些例子

# find /home -size +10M 		// /home目录下大小超过10MB的文件
# find . -mtime +120 			// 120天以前被修改过的文件
# find /var \! -atime -90 	// /var目录下90天之内未被访问过的文件
# find / -name core -exec rm {} \; //在整个目录树下查找文件core,如发现则无需提示直接删除它们。

Mac下使用命令行登陆ftp

最近使用forklift下载服务器pureftp上的东西,总是断断续续的,经常下载到99%然后显示下载失败,非常不舒服!原以为是forklift的问题,换了transmit发现同样有这样的现象。看来是ftp服务器搭的有问题~~不过因为用的不多,目前懒的解决了,暂时用Mac的终端命令来用着。其实效率也是蛮高的哦=。=

默认的本地目录是home。 输入help即可获得所有命令的帮助。

  1. 连接ftp服务器

man ftp 可以看到有这些信息。

NAME ftp – Internet file transfer program SYNOPSIS ftp [-46AadefginpRtvV] [-N netrc] [-o output] [-P port] [-q quittime] [-s srcaddr] [-r retry] [-T dir,max[,inc]] [[user@]host [port]] [[user@]host:[path][/]] [file:///path] [ftp://[user[:password]@]host[:port]/path[/][;type=X]] [http://[user[:password]@]host[:port]/path] […] ftp -u URL file […]

连接服务器的话基本上就用到上面的讯息了。原本没有看man手册,一直使用

ftp user@xxx.com port

每次都要输入密码。后来还是用了下面这个更加简单的

ftp ftp://user:passwd@xxx.com:port
  1. 浏览文件

    命令和Windows、Linux的命令基本相同

     ftp> cd Documents
     ftp> ls		
     ftp> dir
    
  2. 下载上传文件

     put filename - Upload a file to the server
    	
     get filename - Download a file from the server
    	
     mput filename - Put multiple files on the server
    	
     mget filename - Get multiple files on the server
    
  3. 断开连接

    bye:中断与服务器的连接。

     ftp> bye
    
  4. 大部分的命令如下,可敲入man ftp获得

     ls – list the contents of a directory on the FTP server
     cd – change the working directory on the FTP server
     pwd – show the current directory on the FTP server
     get – download files from the FTP server
     put – upload files to the FTP server
     account – include a password with your login information
     bye – terminate an ftp session and close ftp (or use disconnect to simply terminate a session)
     bell – make a cute sound after each file transfer is done
     chmod – change permissions
     delete – your guess is as good as mine (OK, you got me, it’s to delete a file off the server)
     glob – enable globbing
     hash – only functional in Amsterdam
     help – get help
     lpwd – print the local working directory for transfers
     mkdir – create folders on the FTP server
     rmdir – delete folders from the FTP server
     newer – only get a file if it’s newer (great for scripting synchronizations)
     nmap – use positional parameters to set filenames
     passive – use FTP passive mode
     prompt – allows the use of letters to automate answers to prompts
     rate – limit the speed of an upload or download
    

关于ftp,你甚至还可以写脚本进行文件操作,比如

	#!/bin/bash
	ftp -d krypted.com << ftpEnd
	prompt
	cd /Library/WebServer/Documents
	put “*.html”
	put “*.php”
	cd /Library/WebServer/Documents
	put “*.png”
	quit
	ftpEnd

	#!/bin/bash
	ftp -d krypted.com << ftpEnd
	prompt
	cd /My/Documents
	get “*.doc”
	quit
	ftpEnd

在你的脚本中,可以使用以下几个字符获取一些特定的变量:

%/ – the current working directory of the FTP server
%M – the hostname of the FTP server
%m – the hostname only up to the .
%n – the username used for the FTP server

最后有一个问题,为什么老是有不明的人/机器想登陆我的FTP?= =不过自己也是只有使用的时候才会开。

ftp-log


快捷键之tmux

这份常用快捷键是基于Maximum-Awesome的,最主要的区别是把 Ctrl + b (这是 tmux 的默认前缀键)改为了Ctrl + c ,不全面但足够日常使用。如果你还没有安装,参考我的上一篇文章使用Maximum Awesome

具体的配置可以查看 Home 目录下的 .tmux.conf 文件,还比较易懂。

窗口

C-a c		新建窗口
C-a space 下一个窗口
C-a bspace 上一个窗口
C-a v 纵向切割窗口
C-a s 横向切割窗口
C-a w 以菜单方式列出所有会话,显示及选择窗口
C-a & 关闭窗口
C-a , 重命名窗口
C-a d 将当前会话放到后台,但不关闭
C-a f	搜索pane的名字

面板操作

C-a h/j/k/l 选择面板
C-a a 上一个面板
C-a ; 上一个面板
C-a q 显示面板编号
C-a x 关闭面板
C-a z 当前panel最大化
C-a m mark颜色当前panel

面板布局

C-a enter 面板下一种布局(均分、全纵向、全横向、主横向、主纵向)
C-a C-o 逆时针旋转面板
C-a + 主面板 - 横向
C-a = 主面板 - 纵向
C-a(按住不放) 方向键 上下左右扩展边界

操作

C-a : 输入命令
	这个很有趣,你看到的.tmux.conf里的命令,都可以直接这样敲
C-a r 重载配置文件
C-a L 清除历史
C-a d 退出tumx,并保存当前会话

C-a [ 复制模式,(可以使用方向键滚动查看历史记录)
C-a ] 粘贴模式

其它

由于是在服务器上设置的tmux,默认的复制粘贴有问题,修改成了vim的经典模式:v选择,y复制,如下:

bind-key -t vi-copy v begin-selection
bind -t vi-copy y copy-selection

参考资料