watch is an amazing program that implements a program periodically and outputs the contents on a full screen. On placing the command inside quotes, you can even run more than on commands:
watch -n 1 'ls -la ; echo ; vmstat ; echo ; df'
This command implements a file listing, outputs memory statistics and disk space, all differentiated by empty lines and duplicates it every second.
9: curl
Majority of (PHP) developers must have used the cURL php extension, but this tool is also available on your command line. Rather than writing an additional php-program and doing some ‘curly-things’, you can use the command line tool. All needed options are available. Just release “man curl” and identify all the possibilities.
8: logsave
logsave is an effective tool that gets hold of the output of a program and transmits it to a log-file. It’s somewhat like what “tee” does, by adding a begin time stamp and an end time stamp:
jthijssen@guybrush$ logsave -a output.log echo "hello world"
hello world
jthijssen@guybrush$ cat output.log
Log of echo Hello world
Wed Nov 24 16:51:24 2010
Hello world
Wed Nov 24 16:51:24 2010
---------------
The -a parameter will allow you add on to the log-file.
7: lsof
lsof represents “list open files” and displays all the files that your system has opened. It’s quite helpful to decipher which processes use a specific file, or to display all the files for a single process:
lsof output
Sample output of "lsof" for a apache httpd process
6: strace
Strace is a favourite of many. It spots all system calls made by a program makes to the linux kernel. This means it allows you to actually “see” what a program opens, closes, reads, write, access files but certainly, there are several more calls that you can spot. It’s like running a program without its cover.
strace -ff -e trace=open /usr/sbin/apache2
This will strace the program “apache2″ and outputs all the open-calls. Another used version:
strace -ff -p
traces the presently running process
One of the key reasons to strace a process is when something is not going right. Either it’s extremely slow, doesn’t do what it is expected to or similar. It’s a marvelous piece that can save you hours and hours of debugging.
5: z* tools
Often you need to grep, diff or cat files that are packed together. Instead of unpacked files, it’s possible to threat the files as if they were unpacked already by using “zgrep” rather than grep, “zdiff” rather than diff, “zcat” rather than cat etc..
[root@guybrush /]# echo "hello world" | gzip > test.zip
[root@guybrush /]# file test.zip
test.zip: gzip compressed data, from Unix, last modified: Wed Nov 24 17:02:18 2010
[root@guybrush /]# zcat test.zip
hello world
4: od
This tool allows you to dump a file into different types of formats.
[root@guybrush /]# echo "hello world" > test.txt
[root@guybrush /]# od test.txt
0000000 062550 066154 020157 067567 066162 005144
0000014
[root@guybrush /]# od -t xa test.txt
0000000 6c6c6568 6f77206f 0a646c72
h e l l o sp w o r l d nl
0000014
[root@guybrush /]# od -t x1u1a test.txt
0000000 68 65 6c 6c 6f 20 77 6f 72 6c 64 0a
104 101 108 108 111 32 119 111 114 108 100 10
h e l l o sp w o r l d nl
0000014
3: iconv
iconv is a striking tool when you need to convert an encoded file into another format. For example, a latin-1 dump of a MySQL database is required to be imported into UTF-8 encoded database. In this case, Iconv can auto-detect the current format.
2: nc
netcat (nc) is the tcp/ip swish army knife. It can do anything including checking service requests (such as soap-clients) to identify if they actually release the correct headers.
setup a “listening server”:
nc -l 12345
point your soap-client to send data to http://127.0.0.1:12345 and check the data that is being send from your client.
1: whiptail
On installing ubuntu, centos, debian, or basically any linux flavor around that doesn’t generate a graphical shell, you finish up in a kind of textual interface.
Examples:
It’s quite easy to generate a little display box: You just need to add the text, the height and width and also a title..
whiptail --msgbox "Hello world" 5 60 --title "Test dialog" --backtitle "A simple sample.."
Ask a user any question and it will return the status code 1 for “no” and status code 0 for “yes”.
whiptail --yesno "Are you sure you want to continue with deployment?" \
10 60 --title "New deployment" --defaultno
No comments:
Post a Comment