收集整理的Linux下的小技巧(一)


1.设置文本方式下的分辩率
在grub的启动参数中加入vga=xxx
value mode video ram
769 640 x 480 x 8 bit (1M)
785 640 x 480 x 16 bit (1M)
786 640 x 480 x 24 bit (1M)


771 800 x 600 x 8 bit (1M)
788 800 x 600 x 16 bit (1M)
789 800 x 600 x 24 bit (2M)
773 1024 x 768 x 8 bit (1M)
791 1024 x 768 x 16 bit (2M)
792 1024 x 768 x 24 bit (4M)
775 1280 x 1024 x 8 bit (2M)
794 1280 x 1024 x 16 bit (4M)
795 1280 x 1024 x 24 bit (8M
796 1600 x 1200 x 8 bit (2M)
798 1600 x 1200 x 16 bit (4M)
799 1600 x 1200 x 24 bit (4M)

2.更改桌面分辨率到1024x768(有时无效,不知道为何)
修改/etc/X11/xorg.conf文件,修改前先备分此文件,以防万一.
注释掉设置行频的这一行(必须)
#HorizSync 31.5 - 37.9
在Section "Screen"的Subsection "Dispaley"中把Modes一行改成
Modes "1024x768"

3.启动多个X桌面
用别名
alias X1='startx -- :1 -bpp 32 -quiet&'
alias X2='startx -- :2 -bpp 32 -quiet&'
或者直接用命令
startx -- :1 -bpp 32 -quiet&
startx -- :2 -bpp 32 -quiet&
然后可用CTRL+ALT+F8,CTRL+ALT+F9切换,依此类推到CTRL+ALT+F12
最简单的方法
startx -- :1

4.调整显示器
xvidtune

5.给文件输出加上行号
nl /etc/passwd
nl /etc/passwd -s '.'
在vi中
:%!nl

6.大小写转换
cat filename | tr "[a-z]" "[A-Z]"

7.统计文件的行数
wc -l filename # line
wc -c filename # char
wc -w filename # word

8.找回root帐号密码
进入单用户模式,对于用grub的用户,在启动参数后的kernel一行后加single,
然后可不用密码进入单用心模式,再在单用户模式下修改你的密码.

9.设置grub密码
如上8所述,实际上只要能够接触到机器,如果grub没有密码,就可以轻易地进入机器.
生成md5码
输入命令
grub-md5-crypt
然后输入法你要设置的密码,grub-md5-crypt就会生成一个字符串xxxxxxxx.
加入到你在grub配置文件/boot/grub/grub.conf(有的可能用在的/boot/grub/menu.lst)
在title的下一行加入
password --md5 xxxxxxxx

10.用命令弹出光驱
eject # 弹出
eject -t # 弹回
很有意思

11.反转文件在内容
tac /etc/passwd
在vi中
%!tac in vi

12.输出文件前n行的几种方法
head -5 filename
awk 'NR==1,NR==5 {print {GetProperty(Content)}}' filename
sed -n '1,5p' filename
此法可变通到输出文件的其它行
sed -n '5,$p' filename

13.改变grub背景
grub背景用的是xpm文件在图片格式,因此你需要把你在图片转换成xpm格式,可用gimp
在X Window下,输入
gimp filename
修改图片的颜色数为14
right click on image-> image->mode->indexed->color number 14
然后保存为xpm文件/yourpath/yourimage.xpm
也可以用命令
convert yourimage.jpg -colors 14 -geometry 640x480! yourimage.xpm
修改grub
在grub中添加
splashimage (hd0,0)/yourpath/yourimage.xpm
有的可能是
splashimage=(hd0,0)/yourpath/yourimae.xpm
分区(hdx,y),根据你的具体情况而定.另外也可以把图片压缩为.gz格式.

14.ssh技巧
(1)不用login远程执行命令
格式:
ssh hostname command
如:
ssh hostname ls /usr/share/doc
(2)远程文件拷贝scp,windows下用pscp
scp localfile username@hostname:/newfilename

15.Linux下使用NFS QuickStart
修改/etc/exports就可.如果不考虑安全问题,可在该文件中加入
/ master(rw) trusty(rw,no_root_squash)
再执行
service nfs restart
然后就可在远程主机上mount它了
mount hostname:/ /media

16.ftp自动登陆下载shell脚本
SRC_FTP_SERVER=hostname
SRC_FTP_USER=anonymous
SRC_FTP_PASSWD=user@xxx.com
SRC_FTP_DIR=/diskimages/
echo "open $SRC_FTP_SERVER
user $SRC_FTP_USER $SRC_FTP_PASSWD
lcd ${TMP_DIR}
cd $SRC_FTP_DIR
binary
get $SRC_FTP_DIR/filename " | ftp -n 1>/dev/null 2>&1


17.命令下发送邮件
cat "mail content" | mail yourname@domain.com -s "mail title"
cat /dir/file_conent | mail yourname@domain.com -s "mail title"
带附件,用mutt
cat "mail content" | mutt yourname@domain.com -s "mail title" -a attach_file
cat /dir/file_conent | mutt yourname@domain.com -s "mail title" -a attach_file

18.tar打包时去掉某些目录或文件
cd /
tar cvf usr.tar usr --exclude usr/share --exclude /usr/bin/unzip
添加排队目录时不要加/根符号

19.显示xx天前/后的日期
date -d "now" #同date
date -d "today" #同date
date -d "45 days ago" # 45天前
date -d "45 days" # 45天后

20.Linux使用*.rar文件
安装rar软件包(google一下就知道了)
压缩
rar a usr_share.rar usr/share
解开
rar x usr_share.rar /root

21.用命令截屏
import -window root hello.jpg

22.非交互方式文本转html
vim -c ":TOhtml" -c ":wq %" -c ":q" filename

23.其它
监视文件的变化
tail -f /var/log/messages  
命令行下HTML相关命令
wget www.xxxx.com/filename.tar.gz #下载文件
lynx www.163.com #命令行看网页
htmlview www.163.com #命令行看网页

 

本文作者:
« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3