Other useful commands contd...
The best and fastest way to know the location of a program that will execute is to use this command. It finds the command for you and tells you the location.
% type mkdir mkdir is /bin/mkdir
However, if you try to search an internal command, it will just tell you that this is an internal command. Try this,
% type echo echo is a shell builtin
Similar to the VER command in MS-DOS and Windows, the uname command tells you the information about the machine, its version (kernel version in case of Linux) and so on. To know the machine name, type
% uname -n
To get the version (or kernel version in Linux), type
% uname -r
cal stands for calendar. You can get the calendar of a month, current month or an year. Any calendar from 1 to 9999 can be displayed with this command. Try these
% cal 2008 % cal 10 2007 % cal aug
The last one (cal aug) will work only with UNIX
This command controls the cursor. To position the cursor at 10th row and 10th column, type
% tput cup 10 10
To clear the contents of the screen, type
% tput clear
To boldface the text, we can use smso and rmso arguments of this command. The former starts the bold sequence while the latter turns it off. Type this and have fun,
% tput smso % echo "This is in boldface" % tput rmso % echo "Boldface ended"
The passwd command is used to change passwords. The behavior of this command is heavily system dependent. Type,
This will first ask the old password and then the new password to be set. Whatever you enter on the screen as a password will not be displayed on the screen.
With this command, we can view the date and time of the system. The operating system keeps an internal clock, by which date and time is provided. Type,
% date Fri Mar 26 17:45:06 EDT 2008
The command can also be used with suitable format specifiers as arguments. Each format is preceded by a + symbol, followed by a
and a single character describing the format. Try these,
% date +%h Mar % date +%Y 2008 % date +"%h %Y" Mar 2008
Simple Files Manipulation
This command displays data in ASCII octal format (numbering system of base 8). It stands for "Octal Dump" (OD). This helps in understanding the non-printable characters as its octal value is got. Try these,
% od filename % od -b filename % od -bc filename
This command breaks up its inputs into several equi-line segments. All these segments are created as separate files in the current directory. By default, it breaks up a file into 1000-line pieces. Type,
% split filename
This will create files name xaa, xab, xac, and so on from the filename supplied to the command. Thus we can have 676 (26X26) files from this command. To change the default size of file to 150 lines, use,
% split -150 filename
We can also set our own primary name of the output files. The following will create splitted files from filename to the files chunksaa, chunksab, chunksac, and so on.
% split filename
chunks To join these files, simply use redirection utility and cat,
% cat x* > myfile
This will create the joined file as myfile. If you used your own primary name of iles as specified above, use,
% cat chunks* > myfile
This command compares two files to check if they are identical. Type,
% cmp file1 file2 file1 and file2 differ: char 11, line 2
Files are compared byte by byte and the location of the first mismatch is echoed on the screen. To get the details list of the byte number and the differing bytes in octal for each character that differs, use
% cmp -l file3 file4 4 111 125 6 122 181 9 101 102
If the files are identical, the command gives no output.
This command finds whatever is common in two files. Type,
% comm file1 file2
This is another command which is used to display the file differences. This command also tells which lines in one file have to be changed to make the two files identical. Type,
% diff file1 file2
If the files are identical, the command gives detailed output.
So far we have been using commands separately. However we can combine these commands too. Thereby, specifying more than one command in the same command line. Each command is separated from the other by a ; (semicolon): Type,
% ls -a ; type ls
And as we earlier learned, we can also redirect the output of any command which is true in this case also. Type
% ( ls -a ; type ls ) > mylist
Thus, the combined output of the two commands are now sent to the file mylist.
Related Online Articles:
No comment yet. Be the first to post a comment.