January 2009
The Archives
-
01.31.09Tracing an already existing process$ strace -p pid Attaches to the process with PID=pid and shows the utilization of system calls. Very useful when a process seems to be stuck and you want to know what is going on.
-
01.29.09sdf, public Unix shell accessI have mentioned it several times before, but I have been told it deserves an entry on its own. The Super Dimension Fortress (known also as freeshell) is a public Unix system: that is a Unix system (actually Netbsd running on an Alpha-64) to which everyone (each person in the world having a network connection) can log in and which anyone can use. From its main page: Our mission is to provide remotely accessible computing facilities for the advancement of public education, cultural enrichment, scientific research and recreation. Members can interact electronically with each other regardless of their location using passive or interactive forums. Further purposes include ...
-
01.27.09Tracing system calls$ strace ls Traces all the system calls invoked by the process "ls" Let's say we are in directory dir and we execute ls $ ls file1 file2 And now, let's see what the command actually does: $ strace ls open(".", O_RDONLY|O_NONBLOCK|O_DIRECTORY|0x80000) = 3 getdents(3, /* 4 entries */, 4096) = 112 write(1, "file1 file2\n", 13file1 file2 ) = 13 It opens the current directory, reads the number of entries (4, this is: our two files, plus "." plus "..") and writes the result using write You should keep in mind that strace traces system ...
-
01.25.09Locking a user account# passwd -l user Locks user's account, that is, prevents user from logging in. Note: This option is available in Linux and Solaris. In Mac OS X, -l option means something different: # passwd -l location user Here, -l changes the password in location. Valid values are: file: a filename. Default is /etc/master.passwd netinfo: a domain name or server/tag pair nis: an NIS domain name opendirectory: a directory node name
-
01.23.09Space forSo your friend sent you a batch of tiffs to be converted into jpg's (using ImageMagick's convert command). However your friend (who is not so geeky as you) uses spaces in filenames (which is a deadly sin), like in First photo of birthday.tiff Second photo.tiff You wanted to use a shell for loop, but the obvious $ for i in `find . -name *tiff` ; do convert "$i" "${i%tiff}jpg" ; done produces garbage (try it). This is just one of the consequences of your friend's carelessness. But there is a solution. IFS (Internal Field Separator) is a shell variable controlling what character(s) delimit a 'field' in ...
-
01.21.09Perl autoflush$ perl -e '$|=1; while(<>){print "you entered: $_";}' Even though in the above code it is irrelevant, the $|=1 assignment makes all the output be unbuffered (auto-flushed). This is quite useful in sockets, network protocols and IPC.
-
01.19.09Extract a tar file in a specific directorytar zxvf file.tar.gz -C /path/to/directory Extract gzipped file.tar.gz in the directory /path/to/directory instead of in '.' (the present working directory).
-
01.17.09Less can do more…... more than you think ;) less is a command that allows you to view and move forward and backwards in a file among other things. But the interesting thing is that less allows you to define a preprocessor. You can set it as the form of a shell script specified in the LESSOPEN environment variable. $ echo $LESSOPEN lessopen.sh %s This is the script that will be invoked before the actual less command (located in /usr/bin/less) is executed. The result of the script must be something readable. If you take a look at the script you will find what kind of files can ...
-
01.15.09Where is an executable?# which cat /bin/cat The which command shows the first instance of an executable file with the specified name found following your $PATH variable.
-
01.13.09An Arbitrary Precision Calculator Languagebc is a language that supports arbitrary precision numbers with interactive execution of statements. There are some similarities in the syntax to the C programming language. A standard math library is available with a command line option. bc starts by processing code from all the files listed on the command line in the listed order. After these have been processed, bc reads from standard input. At this time lines are executed as they are read, in usual interactive fashion. bc accepts the following command line options: -h, --help Print the usage and exit. -l, --mathlib Define ...