Tuesday, August 2, 2011

Fuser command

fuser is a UNIX command used to show which processes are using a specified file, file system, or socket.

# To list the process numbers of local processes using the /etc/passwd file, enter:

fuser /etc/passwd

# To list the process numbers and user login names of processes using the /etc/filesystems file, enter:

fuser -u /etc/filesystems

# To terminate all of the processes using a given file system, enter:

fuser -k -x -u -c /dev/hd1

or

fuser -kxuc /home

List the content of a tar file

if You need to list the contents of a tar or tar.gz file on screen before extracting the all files.

List the contents of a tar file
$ tar -tvf file.tar

List the contents of a tar.gz file
$ tar -ztvf file.tar.gz

List the contents of a tar.bz2 file
$ tar -jtvf file.tar.bz2

Setup Password protect file via shell

1. Create a file name .htaccess in the folder that you want to password protect with the content below.

AuthType Basic
AuthUserFile /home/username/pass
AuthName "Members Area"
require valid-user

2. In shell, type

/usr/local/apache/bin/htpasswd -c /home/username/pass your_desire_username

You will be prompt for a new password.

3. Enter the password and confirm it.

Once you enter your password, file with name .htpasswd will be created at /home/username directory and now the website folder has been password protected.

4. To add additional users,

/usr/local/apache/bin/htpasswd /home/username/pass your_desire_username

5. To remove users edit /home/username/pass and remove the line contains the username.

More information: http://blog.dreamhosters.com/kbase/index.cgi?area=834

A memory testing tool

cd /usr/local/src

wget http://pyropus.ca/software/memtester/memtester-4.0.5.tar.gz

tar -zxf memtester-4.0.5.tar.gz

cd memtester-4.0.5

make

./memtester 1024 5 for 1gb(1024 mb) RAM .



The test will be run 5 times.

To list only directories

If you want to list only directories you can use this.

ls -d */.

cut command

I have a large text file (its a log file actually) and I need to truncate each line to about 16 characters.

cut -c1-16 /path/to/filename > /path/to/output_filename

output_filename will contain the result.

Some useful sed commands

to remove the first line of a file from our output stream

$ sed -e '1d' filename | more

to delete lines 1-10 of the output

$ sed -e '1,10d' filename | more

to delete lines that start with a "#" from files

$ sed -e '/^#/d' filename | more

to print only virtualHosts in apache conf

$ sed -n '/^ /path/to/httpd.conf