Monday, March 17, 2008

Membuang file .src di Flashdisk dengan command line Linux

saya ingin mencari semua file .scr di flashdisk kemudian membuangnya. ini terjadi karena flashdisk kena VIRUS tatik.exe.

berikut cuplikannya

lakukan pencarian dulu supaya tidak salah pilih

#/media/disk# find ./  -name *.scr

kalo sudah pasti kemudian buang langsung

#/media/disk# find ./  -name *.scr -print -exec rm -r {} -f \;

ini ada ti[s yang lain yang bisa dipelajari


show libraries a binary uses

Sometimes its necessary to see what libraries a binary is using. For example, if you wanted to know what libraries MySQL is using, just issue this command:

ldd /usr/bin/mysql

substitutes for Netcraft

If you want to find out what operating system a server is using, you can go to and use their 'What's that site running' service. But there are alternatives. With tools available for Linux, you can do it yourself. It requires curl and/or Lynx to be installed.

lynx -mime_header | grep Server

curl -sI | grep Server

show files changed on a certain date

If you need to find a file you changed on a certain date, this handy one liner will do it

ls -lt * | grep 'May 8' | awk '{print $9}'

change default editor

The default editor on some Linux machines may not be to your liking. This is particularly important for remote logins. If you wanted to change the editor to 'vim', an improved version of vi, you would do this:

export VISUAL=/usr/bin/vim

sort directories from smallest to biggest

Sometimes you check available space on your hard disk and you're surprised to find that you've recently occupied a lot more. If you're curious as to what's taking up the space, you can find out this way:

du -s -k * | sort -n


If you've got some files that were created by proprietary software that's not longer supported and you need to get data out of them, you might try the 'strings' utility. It will find plain text in binary or other types of non-text formatted files.

strings file > newfile

date in YYYY-MM-DD

This comes in handy for shell scripts, especially if you're making backups. This date format is easily understood by all.

date +%Y-%m-%e

Here's an example of it in use:

tar -zcvpf backup_`date +%Y-%m-%e`.tar.gz *.*

change time stamp of a file

For some reason, you may need to timestamp a file. To simply change the date of a file to the current date and time, do this:

touch file

To change the timestamp to some time in the pass, issue this command:

touch -t YYYYMMDDHHMM file

Where YYYY = year, MM = month, DD = day, HH = hour and MM = minutes.

list all files except

This will list all the files in a directory except the wildcard you specify.

ls -I '*.html'

what's using memory

You may find that your computer is running a bit slower. You can easily find out what's using up your memory:

ps -aux | awk '{print $5,$6,$11}' | sort +1n

complete memory information

To see complete information about the memory your machine is using:

cat /proc/meminfo

change text colors

You can change the color of text in an xterm. This can come in handy it you're writing shell scripts. Try this example:

echo -e "\033[42;1m Pretty colors \033"

Erase the contents of a file

This will erase the contents of a file without eliminating the file

cat /dev/null > some.file

'shred' a file

Just like destroying documents with a paper shredder, computer files with sensitive information in them should also be 'shredded'. To do this, there is a command line utility on Linux systems called 'shred'. What this does is to overwrite the file multiple times with random output. This is secure, because if you simply erase a file with 'rm', all this does is to tell the operating system that this part of your hard disk is free to use, but the information still exists until that space is used. Special tools can be used to recover information from a file that's simply been deleted, but if you've 'shred' it, it would be nearly impossible to get that information back. So shred would be especially useful if you're going to sell or give your computer away to somebody.

The following command will shred a file, "zero" it (to hide shredding) and then remove it.

shred -zuv some.file

You could also 'manually' shred a file by doing the following:

cat /dev/urandom > some.file

This procedure also writes random information to a file. Unlike shred, you'll need to stop this process after a few seconds or some.file will begin to grow until it takes up all available space. When you've finished, simply erase (rm) the file.

delete files with 'bad' names

If you've ever had to delete a file you inadvertantly made, starting with a dash, for example, as you might have found out, it's not as easy as rm -file. You can delete it though - like this:

rm -- -file


rm ./-file

pop-up a reminder

You can pop up a message on your Linux desktop with this command:

(sleep 60; xmessage -near One Minute has gone by) &

This will pop up the message 'One Minute has gone by' after 60 seconds. Adjust to your needs accordingly.

Using 'find'

find files bigger than 1mb

This will find files in your home directory that are bigger than 1 megabyte

find /tmp -size +1000k -print

find recently modified files

This will show files that were modified within the last 24 hours in your home directory (if your name is mike)

find ./ -ctime -1 -user mike -print

find with size and access time

You can combine file size and access time with find

find ./ -size +1000k -and -atime +7 -print

Finds files larger than 1 MB that haven't been accessed in more than 7 days.

find and copy into multiple dirs

If you ever need to copy the same file into multiple directories and you can't use a symbolic link, then this trick will work:

find . -type d -name "2004*" -exec cp /file.html {} \;

remove unwanted dirs

Using a modification of the above example, you can remove directories. The following example will remove the temporary directories that the GIMP leaves behind.

find . -type d -name .xvpics -print -exec rm -r {} -f \;

Using 'grep'

Grep is a command line utility that's used mostly to find words in files. It is very powerful. After getting up to speed with it, you'll find that you can't work without it. The basic syntax is:

grep word file, or to use a real example, grep kiwi fruits.txt. This will show the line where the word appears in the file.

You don't have to restrict this to one word. You can search for entire sentences if you like. Just put more than one word inside single quotes.

Show only file name

The following will only show the names of the files where a given word appears

grep -wl 'word' *.*

grep file in a directory

This will search for a given word in an entire directory, including subdirectories

grep -r kiwi ~/my_files/*.rtf

You've got mail!

You can use grep to keep track of recently arrived mail. This one-liner will show you who's sent you mail

grep -c '^From:' /var/spool/mail/bob

The caret '^' tells grep to look for any line beginning with what you specify after.

End of the line

Here's an example of the reverse of the previous example. We can look for lines that end with a particular word or words. The following will show us the users on a Linux system that aren't real people

grep nologin$ /etc/passwd

Accounts for programs and daemons will normally end with 'nologin'.

grep this and this and this

Grep will also let you look for words that appear separately in a file. The following will look for the information for users bob, ted and joe in the /etc/passwd file:

grep "\(bob\|ted\|joe\)" /etc/passwd

Directory Assistance

If you have entered telephone numbers in files, you can use grep to look for them. The following will show you all of the telephone numbers in a given file:

grep '[0-9]\{3\}-[0-9]\{4\}' members.txt

This takes for granted that you've entered them in 000-000-0000 format. Different cultures write down telephone numbers in different ways, so you may have to substitute the the number of digits in the curly braces {2\} instead of {3\} ,for example, or subsitute the separating dash '-' with the character that's more common in your locale (a period '.', for example)

grep and grep

You can use grep more than once if you want to apply different options to two different things that you're looking for. The following pipes the Apache webserver log file to two different instances of grep. We're looking to see who's logged in at a page that are outside of our local network.

cat access | grep login.php | grep -v 192.168