Linux or UNIX – Find and remove file syntax

3 06 2009

To remove multiple files such as *.jpg or *.sh with one command find, use

find . -name "FILE-TO-FIND"-exec rm -rf {} \;

OR

find . -type f -name "FILE-TO-FIND" -exec rm -f {} \;

The only difference between above two syntax is that first command can remove directories as well where second command only removes files.

More Examples of find command

(a) Find all files having .bak (*.bak) extension in current directory and remove them:
$ find . -type f -name "*.bak" -exec rm -f {} \;

(b) Find all core files and remove them:
# find / -name core -exec rm -f {} \;

(c) Find all *.bak files in current directory and removes them with confirmation from user:
$ find . -type f -name "*.bak" -exec rm -i {} \;





Mount Manual

19 05 2009

Mount Manual

Mounting samba bisa dilakukan secara manual menggunakan konsole. Meski terbilang primitif :-D , cara ini kadang diperlukan untuk memastikan apakah ada suatu kesalahan pada baris perintah yang kita lakukan.

Mount pada folder yang hanya bisa diakses oleh user tertentu (butuh user name dan password)
mount -t cifs //NamaServerSamba-AtauIPAddressSamba/NamaShare /FolderUntukMount/NamaFolder -o username=UserSamba,password=PasswordSamba,iocharset=utf8,file_mode=0777,dir_mode=0777

Contoh :
mount -t cifs //192.168.0.1/Warehouse /home/vavai/Desktop/whs2 -o username=vavai,password=passwordvavai,iocharset=utf8,file_mode=0777,dir_mode=0777

Penjelasan :
- mount -t cifs adalah perintah untuk mount folder Samba. Jika menggunakan distro lain bisa diganti dengan perintah mount -t smbfs

- 192.168.0.1 adalah IP Address Server Samba. Jika menggunakan Nama HostName / Netbios, kita perlu melakukan setting pada file /etc/nsswitch.conf. Ini belum saya bahas pada panduan ini

- Warehouse adalah nama folder share. Nama folder share pada suatu komputer dapat dicheck dengan perintah smb://ip-address-server-samba pada Konqueror

- /home/vavai/Desktop/whs2 adalah nama folder tujuan untuk proses mounting. Folder ini harus sudah ada. Jika belum ada ya harus dibuat.

- -o username=vavai,password=passwordvavai, adalah nama dan password user samba

- iocharset=utf8, untuk memastikan proses konversi huruf / font. Pada komputer dengan font non latin, ada masalah jika opsi ini tidak didefinisikan.

- file_mode=0777,dir_mode=0777, perintah untuk memastikan bahwa folder atau file yang dibuat pada hasil mount bisa diakses dengan modus read dan write.

Cara ini memiliki kekurangan karena username dan password samba dibuat secara plaintext yang artinya bisa dilihat oleh orang lain dengan mudah. Untuk melindunginya, kita bisa menggunakan opsi file credentials, yang menyimpan user name dan password pada suatu file teks yang diletakkan difolder tertentu dan hanya bisa diakses oleh user tertentu.

Caranya adalah dengan membuat file teks, misalnya root/.filecredentials. Tanda titik pada file menunjukkan bahwa file ini berjenis hidden file. Buatlah file tersebut dengan text editor non GUI, misalnya dengan vi. Kenapa tidak dengan GUI Editor, karena file ini harus berisi perintah teks murni tanpa format macam-macam. Isilah file tersebut dengan isi sebagai berikut

username=UserSamba
password=PasswordSamba

Lakukan chmod pada file tersebut agar hanya root yang bisa mengaksesnya, chmod 700 /root/.smbcredentials

Mount pada folder tanpa user name dan password :
mount -t cifs //NamaServerSamba-AtauIPAddressSamba/NamaShare /FolderUntukMount/NamaFolder -o guest,rw,iocharset=utf8,file_mode=0777,dir_mode=0777
Mount dengan akses read only
mount -t cifs //NamaServerSamba-AtauIPAddressSamba/NamaShare /FolderUntukMount/NamaFolder -o guest,iocharset=utf8





Mail command

22 02 2009

Simple way for using command line mail program on Linux:

Syntax:
mail -s “Subject” -a attach_file.txt -r sender@domain -S smtp=ip-of-smtp-address destination@domain < file_of_message_body

Sample:
/usr/bin/mail -s “List logs today” -a /root/logs/listlogs.txt -r backup@domain.net -S smtp=192.168.169.5 adinda@domain.co.id < /root/logs/listlogs.txt

OR The other way is:

Simple Email Message:

echo “Message Body” | mail -s “Subject” receiver@emailaddress.com

Sending File using Linux mail command:

mail -s “Subject” receiver@emailaddress.com < file_to_send.txt

Sending Binary Files with Linux mail command:
Sometimes sending binary files does not work well the command line. We can use uuencode formatting for sending such files:

uuencode myimage.jpeg | mail -s “Subject” receiver@emailaddress.com

Few command line options for Linux mail command:

-s subject ~ Use subject for the e-mail title
-r reply email address ~ email address if you reply to
-c cc email address ~ Send copy of the mail to the specified address
-b bcc emailaddress ~ Send blind carbon copy to specified address
-a attachment file ~ I try just only text file
-S (capital S) for smtp address ~ you could change to other smtp address





Backup with Rsync

19 01 2009

http://rsync.samba.org/ftp/rsync/rsync.html

http://rsync.samba.org/examples.html

http://everythinglinux.org/rsync/

http://www.linux.com/feature/117236

http://www.scrounge.org/linux/rsync.html

http://www.stearns.org/rsync-backup/

http://www.enterprisenetworkingplanet.com/netos/article.php/10951_1573881_3





Wget option for copy site

30 11 2008

To download an entire site, try “wget -rp http://www.indalcorp.com/”.





SQuid – check squid with command line

25 10 2008

Alternatively, you can use the squidclient program that comes with Squid:

% squidclient http://www.squid-cache.org/




SQuid – check configuration file

25 10 2008

Before trying to start Squid, you should verify that your squid.conf file makes sense. This is easy to do. Just run the following command:

% squid -k parse




SQuid – reinit cache with progress

25 10 2008

Cache directory initialization may take a couple of minutes, depending on the size and number of cache directories, and the speed of your disk drives. If you want to watch the progress, use the -X option:

% squid -zX




Example config Squid for ACL

13 10 2008

(1) To allow http_access for only one machine with MAC Address 00:08:c7:9f:34:41

To use MAC address in ACL rules. Configure with option -enable-arp-acl.

Read the rest of this entry »





SQuid – For limit download and upload

13 10 2008

Tag Name request_body_max_size
Usage request_body_max_size (KB)

Read the rest of this entry »