顯示具有 UNIX Command 標籤的文章。 顯示所有文章
顯示具有 UNIX Command 標籤的文章。 顯示所有文章

2012年9月15日 星期六

(find) 找目錄下副檔名是txt的檔案



[UserC@localhost test]$ find . -name "*.txt" -print
./test2.txt
./test.txt
[UserC@localhost test]$ find . -type d -name "*.txt" -print
./test2.txt =>它是資料夾

[UserC@localhost test]$ find . -type f -name "*.txt" -print
./test.txt


(find+xargs)找出檔案權限是775的資料夾和檔案,並將權限改成700

目錄下所有檔案權限改成775
[UserC@localhost test]$ find . -type f -print0 | xargs -0 chmod 775

目錄下所有目錄權限改成775
[UserC@localhost test]$ find . -type d -print0 | xargs -0 chmod 775

找出檔案權限是755的資料夾和檔案,並將權限改成700

[UserC@localhost test]$ find . -perm -775 -print | xargs chmod 700
[UserC@localhost test]$ ls -al
total 16
drwx------. 3 UserC UserC 4096 Sep 15 14:02 .
drwx------. 5 UserC UserC 4096 Sep 15 13:52 ..
-rwx------. 1 UserC UserC    2 Sep 15 13:51 777.sh
drwx------. 2 UserC UserC 4096 Sep 15 14:02 testdir

(find) 找目錄下是755的檔案



[UserC@localhost ~]$ ls -al
total 40
drwx------. 4 UserC UserC 4096 Sep 15 13:47 .
drwxr-xr-x. 7 root  root  4096 Sep 15 13:46 ..
-rw-r--r--. 1 UserC UserC    4 Sep 15 13:47 644.txt
-rwxr-xr-x. 1 UserC UserC    4 Sep 15 13:47 755.txt
-rw-r--r--. 1 UserC UserC   18 May 11 02:31 .bash_logout
-rw-r--r--. 1 UserC UserC  176 May 11 02:31 .bash_profile
-rw-r--r--. 1 UserC UserC  124 May 11 02:31 .bashrc
drwxr-xr-x. 2 UserC UserC 4096 Nov 12  2010 .gnome2
drwxr-xr-x. 4 UserC UserC 4096 Sep 13 22:20 .mozilla
-rw-------. 1 UserC UserC  694 Sep 15 13:47 .viminfo
[UserC@localhost ~]$ find . -type f -perm 755 -exec ls -l {} \;
-rwxr-xr-x. 1 UserC UserC 4 Sep 15 13:47 ./755.txt
[UserC@localhost ~]$  find . -type f -perm 644 -exec ls -l {} \;
-rw-r--r--. 1 UserC UserC 4 Sep 15 13:47 ./644.txt
-rw-r--r--. 1 UserC UserC 18 May 11 02:31 ./.bash_logout
-rw-r--r--. 1 UserC UserC 176 May 11 02:31 ./.bash_profile
-rw-r--r--. 1 UserC UserC 124 May 11 02:31 ./.bashrc
[UserC@localhost ~]$


2012年1月3日 星期二

將檔案從DOS格式轉成UNIX格式

不同檔名:
tr -d '\r' < TEST.sh > TEST2.sh

TEST.sh是來源檔,TEST2.sh是目地檔

同檔名:
perl -pi -e 's/\r\n/\n/g' TEST.sh

p.s.1.如果檔案是DOS格式,用vi編輯會看到^M的換行符號
p.s.2.用WinSCP傳檔會自動改格式,需參考 http://winscp.net/eng/docs/ui_pref_transfer,將
   傳輸模式改成Binary

出處:
http://www.cyberciti.biz/faq/howto-unix-linux-convert-dos-newlines-cr-lf-unix-text-format/