Archive

Archive for the ‘unix / linux’ Category

Easily find or search files or directories

February 26th, 2010 admin No comments

To search the current directory and all subdirectories for a folder or file, use the following command:

find . -name filename

Source: http://www.tech-recipes.com/rx/976/unixlinux-easily-find-or-search-files-or-directories/

Categories: unix / linux Tags:

Grep UID in Plesk from Qmail log

December 4th, 2009 admin No comments

Click on the header link in the mail server queue:

Received: (qmail 30501 invoked by uid 10077); 3 Dec 2009 21:47:42 -0500
Date: 3 Dec 2009 21:47:42 -0500
Message-ID: <20091204024742.30498.qmail@hostserver.com>
To: email@domain.com
Subject: This is a test.
MIME-Version: 1.0
Content-type: text/html; charset=iso-8859-1
From: <user@domain.com>

It says its invoked by uid 10077 which corresponds to the account on the /etc/password file:

-bash-3.2# more /etc/passwd | grep 10077
username:x:10077:2522::/var/www/vhosts/domain.com:/bin/false

Categories: plesk, unix / linux Tags:

How to search for a string in a selection of files

November 30th, 2009 admin No comments
find . -exec grep "www.athabasca" '{}' \; -print

This command will search in the current directory and all sub directories. All files that contain the string will have their path printed to standard output.

Source: http://www.athabascau.ca/html/depts/compserv/webunit/HOWTO/find.htm

Categories: unix / linux Tags:

kill do_backup process for 4PSA Total Plesk Backup

November 22nd, 2009 admin No comments

To debug kill the do_backup process:

killall -9 do_backup

and run it with debugging:

/usr/local/tbackup/do_backup -d

You should see exactly what happens.

Categories: unix / linux Tags:

How to grep a mail log to see if a message bounced

May 22nd, 2009 admin No comments

Command:

tail /usr/local/psa/var/log/maillog -n10000 | grep "user@example.com"

Notes:

Better to tail than cat (in case its a big log)

-n10000 is going back 10000 lines

Add -f if you want to see a live feed of the log

tail -f /usr/local/psa/var/log/maillog | grep "user@example.com"

Source: http://www.woyano.com/view/578/How-to-grep-a-mail-log-to-see-if-a-message-bounced

Categories: plesk, unix / linux Tags:

Shell du command tip – estimate file space usage and exclude particular files

May 22nd, 2009 admin No comments

The du command estimate file space usage and summarize disk usage of each FILE, recursively for directories.

It displays the file system block usage for each file argument and for each directory in the file hierarchy rooted in each direc tory argument. If no file is specified it will use current directory.

du command Examples

Type du to display usage in current directory :

$ du

Pass -h option to display output in Byte, Kilobyte, Megabyte, Gigabyte, Terabyte and Petabyte (Human-readable output)

$ du -h

Display the name and size of each png file in the /ramdisk/figs/ directory as well as a total for all of the pngs:

$ du -hc /ramdisk/figs/*.png

Another useful option is -c which produce a grand total:

$ du -c

Show the disk usage of the /home/vivek subdirectory:

$ du /home/vivek

Show only a summary of the disk usage of the /home/vivek

$ du -hs /home/vivek

Exclude files that match PATTERN. For example do not count *.obj or *.jpg files:

$ du -h --exclude='*.obj'
$ du -h --exclude='*.jpg'

A PATTERN is a shell pattern (not a regular perl or other expression). The pattern ? matches any one character, whereas * matches any string.

Pipes and filters with du

Now display everything sorted by filesize:

$ du -sk .[A-z]* *| sort -n

Display screenful output at a time as du generate more output than can fit on the console / screen:

$ du -h | less

To find top 3 directories, enter :

$ du -sk * | sort -nr | head -3
4620348 var
651972  home
27896   usr
21384   lib64

Working without du

Finally here is one liner (without du command) that prints top 10 filesize in Mb (thanks to dreyser for submitting idea):

# find /var -type f | xargs ls -s | sort -rn | awk '{size=$1/1024; printf("%dMb %s\n", size,$2);}' | head

Output:

31Mb /var/crash/_usr_lib_firefox_firefox-bin.1000.crash
22Mb /var/cache/apt/archives/linux-image-2.6.20-16-generic_2.6.20-16.28_i386.deb
16Mb /var/lib/apt/lists/in.archive.ubuntu.com_ubuntu_dists_feisty_universe_binary-i386_Packages
15Mb /var/cache/apt/archives/linux-restricted-modules-2.6.20-16-generic_2.6.20.5-16.28_i386.deb
9Mb /var/cache/apt/srcpkgcache.bin
9Mb /var/cache/apt/pkgcache.bin
8Mb /var/cache/apt/archives/firefox_2.0.0.4+1-0ubuntu1_i386.deb
7Mb /var/cache/apt/archives/linux-headers-2.6.20-16_2.6.20-16.28_i386.deb
5Mb /var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_feisty_main_binary-i386_Packages
5Mb /var/lib/apt/lists/in.archive.ubuntu.com_ubuntu_dists_feisty_universe_source_Sources

Categories: unix / linux Tags:

Disable suexec

April 23rd, 2009 admin No comments

To find suexec type in

whereis suexec

Result

suexec: /usr/sbin/suexec /usr/sbin/suexec.saved_by_psa /usr/share/man/man8/suexec.8.gz

Now move the file to a backup

mv /usr/sbin/suexec /usr/sbin/suexec_old

Restart apache

/etc/init.d/httpd  restart

Categories: apache, unix / linux Tags:

Transfer files from one server to another using scp

April 17th, 2009 admin No comments

Type this command on the command line to move files from one server to another

scp bkp.tar username@name_of_the_server:/emplacement_to_put_the_file

Source: http://www.webmaster-talk.com/php-forum/119073-transfer-files-from-one-server-another.html

Categories: unix / linux Tags:

How do I create a symbolic link?

April 9th, 2009 admin No comments
ln -s [TARGET DIRECTORY OR FILE] ./[SHORTCUT]

For example:

ln -s /usr/local/apache/logs ./logs

This points a symbolic link “./logs” to “/usr/local/apache/logs”

Source: http://help.hardhathosting.com/question.php/95

Categories: unix / linux Tags:

unzip – list, test and extract compressed files in a ZIP archive

April 8th, 2009 admin No comments

Synopsis

unzip filename.zip

Description

Unzip will list, test, or extract files from a ZIP archive, commonly found on MS-DOS systems. The default behavior (with no options) is to extract into the current directory (and subdirectories below it) all files from the specified ZIP archive. A companion program, zip(1L), creates ZIP archives; both programs are compatible with archives created by PKWARE’s PKZIP and PKUNZIP for MS-DOS, but in many cases the program options or default behaviors differ.

Source: http://linux.die.net/man/1/unzip

Categories: unix / linux Tags: