Read the article to learn more.
Labels
- news (101)
- Linux (72)
- tips (36)
- ubuntu (32)
- hardware (24)
- videos (24)
- howtos (21)
- kde (20)
- open source (20)
- solaris (18)
- solaris interview questions (18)
- external links (10)
- fedora (10)
- windows (10)
- debian (8)
- kernel (8)
- solaris interview questions and answers (8)
- MCSE Videos (6)
- commands (6)
- sun (6)
- linus torvalds (5)
- Sun Solaris 10 CBT (4)
- network administration (4)
- web design (4)
- solaris-express (3)
- backup (2)
- virtualization (1)
Showing posts with label commands. Show all posts
Showing posts with label commands. Show all posts
Linux Commands - 10 Useful tricks for Admins
I have heard a saying - the one thing which sets apart a Linux administrator Guru from a Novice is how much more the former is able to accomplish with so few keystrokes. I do not know the veracity of that saying. But IBM Developerworks has - as usual, put together a collection of tricks which will help raise the efficiency of any system administrator by a notch or two. I am no Guru, nor am I a novice. I guess I fall somewhere in the grey areas between the two extremes, which makes reading the tricks really informative for me.
Among the tricks described are Linux commands which we seldom use such as - fuser, reset, screen, as well as invaluable tips like - resetting the root password, SSH back door entry, using VNC to SSH tunnel to a remote machine, checking your bandwidth, a couple of command line tricks, spying on the console and finally Random system information collection.
Read the article to learn more.
Linux Screen Command Revisited
Screen is a command line tool which allows you to manage several interactive shell instances within the same window. Put in simpler terms, screen command allows you to have the same functionality of tabs - but in a console. Red Hat magazine is running a very useful and informative article to installing and using GNU screen on Linux. The article is written by Steve ‘Ashcrow’ Milner and Anderson Silva. Read the article.
Power sessions with Screen
Screen is a full-screen window manager for the console, that comes with every flavour of Linux and UNIX. It is best known for multiplexing a physical terminal across several processes. By using it, you can run any number of console-based applications within a single terminal.
For example, suppose I want to run the 'top' program to keep track of the system load, edit my programming code and check my mail at the same time ... Usually, I have to open at least 3 terminals to do all this. But by using the screen utility, I can run all these programs at the same time in the same physical terminal. Another great feature of this wonderful utility is its ability to decouple the terminal emulator from the running program, which ensures your job is running even if you accidentally close your window, or in case you log out. After detaching, you can reconnect once again to the same session and regain control over the running jobs.
Here I will explain how to use this utility.1) First open a terminal (eg: xterm if you are in X windows) and type :
$ screen
2) Screen starts and creates a new single window with a shell, pretty much like what you had before. The path name of the shell is taken from the $SHELL variable. New windows can be created within the same physical terminal using the screen commands.
3) Now that you have started screen in a terminal, suppose you want to run the 'top' program to check the System load and at the same time you want to compile a program too - Also you would like to switch between the two to see the progress made by both.
For that, first execute the first program to be run (say 'top'). now 'top' will start in the terminal.Now open a new window in screen by pressing the '[Ctrl + a] c' - which I will state as 'C-a c' . This will create a new window in the same terminal. Here, you can give commands to compile your program.
In screen, each window is given a unique identifier. The first window is numbered 0, the next window is 1 and so on. Now to switch between your 'top' and the compiling program, you can use the key 'C-a 0' and 'C-a 1' respectively.
You can also associate names with each running window - use 'C-a A' to give a name to the current window.
Here are a few other commands that might come in handy while toggling between various running windows :
- 'C-a p' and 'C-a n' can be used to switch to the next or previous window respectively.
- 'C-a N' - where N is the number from 0 to 9, that can be used to jump to the corresponding window.
- 'C-a w' displays a list of all windows. The unique ID of each window with its name and running process is displayed, for each window. The current window is marked with an asterisk(*).
- 'C-a k' - can be used to kill the current window. You can also type 'exit' to kill the current window. If no more windows are open, then screen exits. 'C-a \' also does the same thing.
- 'C-a d' - detaches the present screen session. You can also detach by closing the terminal running your screen utility. Though, this appears to close your terminal session, in reality this does not happen. It only unbinds your session from the current terminal. All the programs started under screen will still keep running.
You can also log out from the machine and re-login. Then start any terminal session and type 'screen -r' to once again be connected from where you left.
In case, there were more than one screen sessions running on the machine, Screen prompts for a host.tty.pid.
For example, say I have two screen sessions. So when I type 'screen -r' command, it gives the following message:
$ screen -r
There are several suitable screens on:
2999.pts-6.localhost (Detached)
1920.PTS-6.localhost (Detached)
Type "screen [-d] -r [pid].tty.host" to resume one of them.
Choose the proper tty.host to connect to and you are controlling your program again. You can also share your screen session with others like using VNC . Imagine you are having a problem with your code and want to share it with your boss who is located in another office. You can use screen to share your session with your boss, and he can see what you are referring to. The first user starts his screen in a normal fashion and executes the following commands ...
User1:The second user starts a new screen session and connects it to the first session using ...
[Ctrl-A]:multiuser on [RET]
[Ctrl-A]:acladd
User2:
screen -x
There are lots and lots of features in Screen other than those that were described here. To know more about Screen, visit the Official Screen Home Page. You can also find a very good introductory tutorial at Kuro5hin.org.
Two repositories of Linux and Unix commands and example dot files
Does your job involve writing complex bash commands ? Or perhaps you are interested in learning tips and tricks on writing versatile dotfiles. Well, here are two sites which are dedicated to collecting useful tips so as to help Linux users better.
Shell-fu - Is a great site with a growing collection of command line goodies. What makes it interesting is that there are multiple combinations of commands which achieve different tasks. And users can submit and vote for their favorite commands.
Dot files - If you precede a file with a dot, it is considered as a hidden file in Linux. There are numerous hidden files in Linux. The standard ones being .bashrc, .profile, .Xdefaults, .xinitrc and so on. But it doesn't limit to these files. Many applications create hidden files too.
Enter the following command in your terminal to see the hidden files in your home directory.
$ ls -a
This site is a repository of collections of dot files. The files are contributed by its visitors and are divided into different sections namely .vimrc, .screenrc, .bashrc, .zshrc, .Xdefaults, .conkyrc, .irbrc, .bash_profile, .xinitrc and .emacs.
Labels: bash shell, commands
10 seldom or never used GNU/Linux commands
Guess how many commands are there in GNU/Linux ? My estimate is somewhere between 1000 and 2000. And how did I arrive at this conclusion ? In my bare bones Linux installation alone, there are 1151 commands. I got this figure by running the following command :
$ ls /usr/bin /bin /sbin /usr/sbin |wc -l
1151
And each of these commands or a majority of them can be combined together to perform complex tasks, in which case, these combinations can be considered to be whole commands in their own right. Naturally, it is a humongous task to master all the 1000s of commands available in GNU/Linux. More importantly, it is easier to ignore many commands which make very good replacements of some of the commonly used commands at least for certain functions.
Brock Noland has compiled a collection of 10 commands on his site *cough* "bash cures cancer", which are seldom used by a majority of GNU/Linux users but which in his opinion are a boon for all Linux users if only they knew about them. The commands are
pgrep
, pstree
, bc
, split
, nl
, mkfifo
, ldd
, col
, xmlwf
and lsof
. He claims that his favorite of the 10 commands is surely mkfifo
. But to know why, you should read his article. He has also provided a number of examples of usage of the commands which makes it an informative read.
Labels: commands
strace - A very powerful troubleshooting tool for all Linux users
Many times I have come across seemingly hopeless situations where a program when compiled and installed in GNU/Linux just fails to run. In such situations after I have tried every trick in the book like searching on the net and posting questions to Linux forums, and still failed to resolve the problem, I turn to the last resort which is trace the output of the misbehaving program. Tracing the output of a program throws up a lot of data which is not usually available when the program is run normally. And in many instances, sifting through this volume of data has proved fruitful in pin pointing the cause of error.
For tracing the system calls of a program, we have a very good tool in strace. What is unique about strace is that, when it is run in conjunction with a program, it outputs all the calls made to the kernel by the program. In many cases, a program may fail because it is unable to open a file or because of insufficient memory. And tracing the output of the program will clearly show the cause of either problem.
The use of strace is quite simple and takes the following form:
$ strace <name of the program>
For example, I can run a trace on 'ls' as follows :$ strace ls
And this will output a great amount of data on to the screen. If it is hard to keep track of the scrolling mass of data, then there is an option to write the output of strace to a file instead which is done using the -o option. For example,$ strace -o strace_ls_output.txt ls
... will write all the tracing output of 'ls' to the 'strace_ls_output.txt' file. Now all it requires is to open the file in a text editor and analyze the output to get the necessary clues.
It is common to find a lot of system function calls in the strace output. The most common of them being open(),write(),read(),close() and so on. But the function calls are not limited to these four as you will find many others too.
For example, if you look in the strace output of ls, you will find the following line:
open("/lib/libselinux.so.1", O_RDONLY) = 3
This means that some aspect of ls requires the library module libselinux.so.1 to be present in the /lib folder. And if the library is missing or in a different path, then that aspect of ls which depends on this library will fail to function. The line of code signifies that the opening of the library libselinux.so.1 is successful.
Here I will share my experience in using strace to solve a particular problem I faced. I had installed all the multimedia codecs including the libdvdcss which allowed me to play encrypted DVDs in Ubuntu Linux which I use on a daily basis. But after installing all the necessary codecs, when I tried playing a DVD movie, totem gave me an error saying that it was unable to play the movie (see the picture below). But since I knew that I had already installed libdvdcss on my machine, I was at a loss what to do.
Then I ran strace on totem as follows :
$ strace -o strace.totem totem
... and then opened the file strace.totem in a text editor and searched for the string libdvdcss . And not surprisingly I came across this line of output as shown in the listing below.
# Output of strace on totem
open("/etc/ld.so.cache", O_RDONLY) = 26
fstat64(26, {st_mode=S_IFREG|0644, st_size=58317, ...}) = 0
old_mmap(NULL, 58317, PROT_READ, MAP_PRIVATE, 26, 0) = 0xb645e000
close(26)
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
...
open("/lib/tls/i686/cmov/libdvdcss.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/lib/tls/i686/cmov", {st_mode=S_IFDIR|0755, st_size=1560, ...}) = 0
...
stat64("/lib/i486-linux-gnu", 0xbfab4770) = -1 ENOENT (No such file or directory)
munmap(0xb645e000, 58317) = 0
open("/usr/lib/xine/plugins/1.1.1/xineplug_inp_mms.so", O_RDONLY) = 26
read(26, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\320\27"..., 512) = 512
fstat64(26, {st_mode=S_IFREG|0644, st_size=40412, ...}) = 0
In the above listing which I have truncated for clarity, the line in bold clearly shows that totem is trying to find the library in, among other places, the '/lib/tls/i686/cmov/' directory and the return value of -1 shows that it has failed to find it. So I realized that for totem to correctly play the encrypted DVD, it has to find the libdvdcss.so.2 file in the path it is searching.
Then I used the find command to locate the library and then copy it to the directory /lib/tls/i686/cmov/. Once I accomplished this, I tried playing the DVD again in totem and it started playing without a hitch.
Just to make sure, I took another trace of totem and it showed that the error was rectified as shown by the bold line of output below.
# Output of the second strace on totem
open("/etc/ld.so.cache", O_RDONLY) = 26
fstat64(26, {st_mode=S_IFREG|0644, st_size=58317, ...}) = 0
old_mmap(NULL, 58317, PROT_READ, MAP_PRIVATE, 26, 0) = 0xb644d000
close(26) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
...
open("/lib/tls/i686/cmov/libdvdcss.so.2", O_RDONLY) = 26
...
stat64("/lib/tls/i686/sse2", 0xbffa4020) = -1 ENOENT (No such file or directory)
munmap(0xb645e000, 58317) = 0
open("/usr/lib/xine/plugins/1.1.1/xineplug_inp_mms.so", O_RDONLY) = 26
read(26, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\360\20"..., 512) = 512
fstat64(26, {st_mode=S_IFREG|0644, st_size=28736, ...}) = 0
Opening the man page of strace, one will find scores of options. For example, if you use the option -t, then strace will prefix each line of the trace with the time of day. One can even specify the system call functions to trace using the -e option. For example, to trace only open() and close() function system calls, one can use the command as follows:
$ strace -o strace.totem -e trace=open,close totem
The ubiquitous strace should not be confused with DTrace that ships with Sun Solaris. strace is just a single tool which takes care of a small part which is tracing a single program. Where as Sun's DTrace toolkit is much more powerful and consists of a collection of scripts which can track, tune and aid the user in troubleshooting ones system in real time. More over, dtrace is a scripting language with close semblance to C/C++ and awk. Put another way, strace tool in GNU/Linux provides only one of the many functions provided by DTrace in Sun Solaris. That being said, strace plays an important part in aiding the user to troubleshoot ones programs by providing a view of the system calls that the program makes to the Linux kernel.
PS: If you are wondering which movie I was intent on watching, it is "For a Few Dollars More" - an all time classic western starring Clint Eastwood. I really like this movie.
Labels: commands, howtos, system administration
Subscribe to:
Posts (Atom)