Saturday, September 29, 2012

Tenth session of Some of basic UNIX commands that are useful very frequently


Today we will discuss about some more useful commands in UNIX/LINUX based operating systems.

Top is a command used to display and update information like PID, username, cpu, and time etc. about top CPU processes. By default, it displays about top 30 processes and periodically update information about them. Its some what like task manager in WINDOWS based systems where processes tab will dynamically update information about process like how much memory and cpu consumed... Below is sample snapshot of top command in UNIX.




As shown above it displays information and update it periodically of top running processes. If you want to kill any process, then you can simply press 'k' and then corresponding PID of the process. If you want to come back to your terminal, you can simply press 'q' to quit from top command i.e. displaying and updating information about top running processes. You can see the video which explains very clearly usage of this command.

One more important command that we are discussing today is su command which is very useful in executing any commands with respect to another user. It creates a shell(new terminal)with the user id of another user.

su root

Above command will opens a new shell(like new cmd prompt) with 'root' user which is real administrator in UNIX based systems. As UNIX is very secured, for some operations to execute, you need to be real administrator. In such cases this command will be very useful.

This command has many more uses that you can know by using 'man su' as we described in previous posts...

Will discuss about some more useful commands in UNIX/LINUX systems in next posts. Please feel free to post any suggestions/queries.


Wednesday, September 26, 2012

Ninth session of Some of basic UNIX commands that are useful very frequently


Today we are going to discuss about one more important command in UNIX/LINUX based operating system that is used to kill processes that are running currently. It is some what like Task Manager in our windows based systems where task manager can be used to view/kill processes that are running currently instead this command is used only to kill processes.

kill -9 1234

Above command will kills process with process ID(PID) '1234'. You can get to know currently running process's PIDs by using 'ps' command that we discussed in our previous post. Below is sample output that a 'ps' command will show:



In above output, IDs that are present under heading 'PID' like '2660, 5796 and 4484'are PIDs similar to '1234' in out above kill example.

In our above example command '-9' that we used to kill process is signal that we are sending to kill process. There are several signals that we can send to kill process are below:




kill 4242

Above command will kill PID 4242 and exit gracefully.

kill -s SIGKILL 1414
kill -s KILL 1414
kill -s 9 1414
kill -SIGKILL 1414
kill -KILL 1414


All above commands are similar equal to above explained first example's -9 SIGKIL (i.e. forcefully kill 1414 process).

Please feel free to post your valuable comments. We will discuss about some more commands in our next posts.


Tuesday, September 25, 2012

Eighth session of Some of basic UNIX commands that are useful very frequently


Today we will discuss about some more useful commands in UNIX/LINUX based operating system.

If you want to see quickly what is the content of a file, then you can use below command to see the content of file in the same terminal you are working currently.

cat filename

Above command will display content of file named 'filename' present in current working directory in the terminal.

cat filename > /x/y.txt

Above command will copies content of file named 'filename' present in current working directory into file named 'y.txt' present in path '/x'.

cat filename1 filename2 > /x/y.txt

Above command will concatenate content of files named 'filename1'and 'filename2' present in current working directory into file named 'y.txt' present in path '/x'.

cat filename1 filename2

Above command will concatenate content of files and displays in the terminal. It doesn't modify original files instead it display both files content into terminal by concatenating.

One more important command that we are going to discuss today is 'ps'.

ps

Above command will display current processes which are running. This command is some what like a 'Task Manager' in windows where as the difference is in task manager we can kill process which we don't want to run but, here we can know process IDs by which we can delete the process using 'kill' command that we can discuss in our next post. This command will display lot of information about processes that are currently running.

ps -u

Above command will display current processes that are running in current log-in.

Please feel free to post your comments/queries. We can discuss some more useful UNIX/LINUX commands in our next post.

Tuesday, September 18, 2012

Seventh session of Some of basic UNIX commands that are useful very frequently


Today we are going to discuss about one more useful command which will be very important in security aspect i.e. When ever you have file/folder which is very important and you don't want others to read your content then this post is very very helpful in making your content private.

chmod is a command by which you can modify permission of a file/folder according to your wish.

chmod -R 777 /home/x/y.java

Above command will give permissions to read, write and execute for the file 'y.java' present in path '/home/x' so that 'y.java' can be accessed (read, write and execute) by anyone.

In the above command main important part is 3 '7's which decide up to what level one can access corresponding file.

First digit: First '7' is used to give permissions to corresponding user. And one can assign '0-7' We can discuss what is the meaning of each digit from '0-7'.

Second digit: Second '7'is used to give permissions to group to which corresponding user belongs too. And one can assign '0-7' for this digit too.

Third digit: Third '7'is used to give permissions to others. Similar to above 2 digits one can assign '0-7' for this digit too. And you can also refer previous post which contains same explanation.

Regarding assigning '0-7' to each user/group/others please read below table for clear explanation.

# Permission rwx
7 full 111
6 read and write 110
5 read and execute 101
4 read only 100
3 write and execute 011
2 write only 010
1 execute only 001
0 none 000

So, as per above table if you don't want to give neither of read,write and execute permission to user, group and others then you can use '000' to assign permissions to corresponding file.

chmod -R 700 /home/x/y.java

Yes, as per your guess, above command will give read,write and execute permission to user and gives no permission to group and others. So, that we can restrict 'y.java' file to corresponding user only.

Like this you can use different combinations in the above table to give/restrict permissions to corresponding user, group and others.

One more important point to remember to use this command is, file to which you are going to modify permissions should be closed and you should be owner of the file. You can also get more information about this command by hitting 'man chmod' in the terminal.

Please feel free to post any help/suggestion. Will discuss some more in next posts.....

Monday, September 17, 2012

Sixth session of Some of basic UNIX commands that are useful very frequently


Today we will discuss about some more useful commands that are used very frequently when you work with UNIX/LINUX based Operating Systems.

mkdir is a command which created new directory in your file system.

mkdir NewDirectory

Above command will create new folder named 'NewDirectory' in present working directory. You can fetch your present working directory by hitting 'pwd' in your terminal. For suppose you are in directory '/home/x/y' then new directory named 'NewDirectory' will be created in ' /home/x/y'.

mkdir /x/y/z NewDirecotory

Above command will create new folder named 'NewDirecotry' in the path '/x/y/z'.

Similarly you can remove a folder and its contents by using command rmdir.

rmdir NewDirectory

Above command will deletes/removes a folder named 'NewDirectory' from current working directory. If that directory contains any sub folders/files then will confirm from user before deleting each file/folder with 'Y/N ?'. So, you can remove/delete each file/folder by pressing 'y'.

rmdir -f NewDirectory

Above command will deletes/removes 'NewDirectory' and its contents without asking confirmation to delete.

rmdir -f /home/x/y/*

Above command will deletes/removes content (files/sub folders) in the path '/home/x/y' without asking confirmation to delete. Like '*', we can use patterns to delete files. Below is small example:

rmdir -f /home/x/y/a*.java

Above command will deletes/removes files whose names starts with 'a' and extension '.java' in the path '/home/x/y/'.

Don't hesitate to try these when you are free.. If you already had a chance to try these, then don't hesitate to write your valuable comments. Will discuss some more in next post....

Tuesday, September 11, 2012

Fifth session of Some of basic UNIX commands that are useful very frequently

Today we will discuss about some more useful commands that are used frequently when you use UNIX/LINUX based system.

Whenever you are running your application in UNIX/LINUX based server, then you may get to view log files for debugging purpose. In that case below command will be useful.

more filename

Above command will display content in the file named 'filename' that fits according to screen. If you want next content in that file to display, then you can simply press 'space' to scroll file content. If you want to quit to view the file then you can simply press 'q' to quit that view. In the displayed content of file if you want to search for some string, then you can use '/pattern' for searching that string.

For example, above file name displayed below content:

Hi My Name is John.

And in that if you want to search for 'John' then you can simply press '/John' and enter will highlight the word 'John'. If there are more 'John's in the displayed content then all will be highlighted. You can traverse one by one.

There is one more way to view file content but not whole content instead just last few lines in that file, then you can use below command.

tail -f filename

Above command will display last few lines of file according to screen fit. If that file is getting modified then it will display accordingly.

For example you are viewing 'catalina.log' file in the tomcat server, then it will be modified frequently based up on the hits to your application. In that case this command will display last few lines accordingly. 

If you want to rename one file to another, then you can use below command.

mv filename1 filename2

Above command renames 'filename1' to 'filename2' . I.e. moves content from 'filename1' to 'filename2'. If you want to move 'filename1' to different directory then also you can use same command but in different manner.

mv filename1 dir2

Above command will move 'filename1'from current directory to 'dir2'. If your file is not present in current directory, then you need to give 'filename1'with full path.

As specified in my previous post, you can get more uses of this command by hitting 'man mv' in your terminal.

Like 'mv' command that we use for renaming or moving files, there is one more command that you may used very frequently in windows if you are get familiar with command prompt. i.e. copy command. Below is its usage:

cp filename1 filename2

Above command will copy 'filename1'into 'filename2'. As specified above with 'mv' command, you can use all similar patterns with this command.

To delete a file you can use below command.

rm filename

Above command will removes file named 'filename' from the system. You can use option ' -i  ' for asking confirmation to delete. 

For all these three commands, you can use patterns for handling set of files. Below is one small example.

mv /dir1/* /dir2

Above command will moves all files present in '/dir1' to '/dir2'. Here '*' is one patten that we discussed in our previous post.

Will discuss some more useful commands in next post...

Monday, September 10, 2012

Fourth session of Some of basic UNIX commands that are useful very frequently


Today we are going to have some useful information on very useful command 'find' in UNIX systems. find is a command used to search any set of directories that you specified for searching files that matched your search criteria. It is useful to locate the path of files on a UNIX/LINUX system. Below is sample syntax:

 find where-to-look criteria  

  find . -name "*.java" 

Above command will display all the files that have file name extension as '.java'in the current directory.  

find . -mtime 1 

Above command will display all the files that are modified exactly one day in the current directory.  

find .. -mtime -1 

Above command will display all the files that are modified less than one day in the parent directory i.e. suppose if you are in directory '/x/y' then above command will display all files that are modified less than one day in 'x' directory. It will also include 'y' directory in searching.

 find . -perm 444 'perm' 

sub-option is used to search files based up on permissions. I.e. Above command will display all the files that have permission to read for owner,group and others in the current directory. Here in '444', first '4'indicates read permission to current user. Second '4'indicates read permission to current group that current user belongs to. Third '4'indicates read permission to other users that are in current system.

 find . -iname "string" 

If you want to search with case insensitive then you can use option '-i' preceding 'name'. I.e. Above command will display all files that have word 'string' irrespective of case. 

As specified in my previous post, you can also get more information about this command by hitting 'man find' in your terminal.

Sunday, September 9, 2012

Third session of Some of basic UNIX commands that are useful very frequently

Hey Folks,

Am back for continuing on posting some more of UNIX commands that are useful whenever you are using any UNIX based operating System.

Grep is a command which is useful for searching any word/name of file/partial name of file in a working directory or any path mentioned. This will display with both case sensitive and case-insensitive results based on the command specified..

grep -i "searchword" FILE

Above command will search for 'searchword' in file named 'FILE' and display matching lines in that file as a result.

We can also use regular expressions to search as per our requirements.

grep "string.*string1" file

Above command will display any line that has 'string' starting with and 'string1'ending with and anything in between... in the file named 'file'.

A regular expression may be followed with one of the following operators.

? The preceding item is matched with at most one time.
* The preceding item is matched with zero or more times.
+ The preceding item is matched with one or more times.
{n,m} The preceding item is matched with minimum 'n' times and maximum 'm' times.

Like this you can use of regular expression for searching your patterns.

In this way 'grep' is useful for searching purpose. There are many more uses of this command that you can know by hitting command 'man grep' in your unix/linux based operating system's terminal(you can call it as cmd prmpt in terms of windows).

shutdown is a command in unix that is useful for letting your system down. You can shutdown your machine immediately or after a specified time..

shutdown -t 2

Above command will shutdown the system securely after 2 seconds.

shutdown -r

Above command will reboot your machine securely..

shutdown -c

Above command will cancel shutdown job that is already running..

As specified above there are many more uses of this command that u can get to know by hitting 'man shutdown' in your terminal..

Will specify some more in next post...