歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux服務器 >> 收集整理的Linux下的小技巧(一)

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

日期:2017/3/2 16:54:13   编辑: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
[email protected]
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 [email protected] -s "mail title"
cat /dir/file_conent | mail [email protected] -s "mail title"
帶附件,用mutt
cat "mail content" | mutt [email protected] -s "mail title" -a attach_file
cat /dir/file_conent | mutt [email protected] -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 © Linux教程網 All Rights Reserved