Wednesday, May 2, 2012

Super Used (su) Command


The su command, also referred to as super user or set user or switch user. This allows a computer operator to change the current user account associated with the running virtual console. By default, and without any other command line argument, this will elevate the current user to the superuser of the local system.

When run from the command line, su asks for the target user's password, and if authenticated, grants the operator access to that account and the files and directories that account is permitted to access.

user1@localhost:~$ su
Password: 
root@localhost:/home/user1# exit
logout
user1@localhost:~$

Additionally, one can switch to another user who is not the superuser; e.g. su user2.

user1@localhost:~$ su user2
Password:
user2@localhost:/home/user1$ exit
logout
user1@localhost:~$

It should generally be used with a hyphen by administrators (su -, which is identical to su - root), which can be used to start a login shell. This way users can assume the user environment of the target user:


user1@localhost:~$ su - user2
Password:
user2@localhost:~$


Please note that you have to use "-" so that user2 home will be selected when password is given.

Tuesday, October 13, 2009

Command to see the memory information in the Fedora

There is the command to see the memory information in the Fedora as
1. free -m -tThis will show the memory in the MB and along with the total memory.
2. cat /proc/meminfo
This is the file which stores the information related to the memory usage.
3. grep 'MemTotal:' /proc/meminfo
This is the command if you want to check the total memory

So these commands are sufficient for getting the information about the memory.

Tuesday, September 1, 2009

How to install the rpm package in Fedora or RHEL

Originally standing for "Red Hat Package Manager", RPM now stands for "RPM Package Manager," which is a recursive acronym.We don't have to worry about these things,We are concentrating on the installing the rpm in our Linux [RHEL or Fedora]

1. Install the package
rpm -ivh packageName
2. Upgrade the existing package
rpm -Uvh packageName
3. Query for installed package
rpm -qa packageName
if you don't know exact package name [Say hotrod-1.0-1.i386.rpm ],you can use command as
rpm -qa | grep hotrod
if you try
rpm -qa
this will list out all the installed rpm packages.

These commands are enough for installing the rpm packages.

Monday, June 22, 2009


If we are using the Linux operating system first think we will do with the command line console apart from the Simple operation is Searching the File So We first Start with the various commands we can use and Finally end with the combination of the Different Commands.So lets Starts and be loaded with the powerful commands.

Command for Powerful Searching


1. FIND COMMAND
-------------------------------------------------------------------------------------
find / -name game
Looks for a file named "game" starting at the root directory (searching all directories including mounted filesystems).
The `-name' option makes the search case sensitive.
You can use the `-iname' option to find something regardless of case.

find /usr -name *stat
Find every file under the directory /usr ending in "stat".

find /tmp -name core -type f -print | xargs /bin/rm -f
Find files named core in or below the directory /tmp and delete them. Note that this will work incorrectly if there are any filenames containing newlines, single or double quotes, or spaces.

find /var/spool -mtime +60
Find every file under the directory /var/spool that was modified more than 60 days ago.

find /home -user joe
Find every file under the directory /home owned by the user joe.

find /tmp -name core -type f -print0 | xargs -0 /bin/rm -f
Find files named core in or below the directory /tmp and delete them, processing filenames in such a way that file or directory names containing single or double quotes, spaces or newlines are correctly handled. The -name test comes before the -type test in order to avoid having to call stat(2) on every file.

find . -type f -exec file '{}' \;
Runs `file' on every file in or below the current directory. Notice that the braces are enclosed in single quote marks to protect them from interpretation as shell script punctuation. The semicolon is similarly protected by the use of a backslash, though ';' could have been used in that case also.

find / \( -perm -4000 -fprintf /root/suid.txt '%#m %u %p\n' \), \
\( -size +100M -fprintf /root/big.txt '%-10s %p\n' \)
Traverse the filesystem just once, listing setuid files and directories into /root/suid.txt and large files into /root/big.txt.

find $HOME -mtime 0
Search for files in your home directory which have been modified in the last twenty-four hours. This command works this way because the time since each file was last modified is divided by 24 hours and any remainder is discarded. That means that to match -mtime 0, a file will have to have a modification in the past which is less than 24 hours ago.
find . -perm 664
Search for files which have read and write permission for their owner, and group, but which other users can read but not write to. Files which meet these criteria but have other permissions bits set (for example if someone can execute the file) will not be matched.

find . -perm -664
Search for files which have read and write permission for their owner and group, and which other users can read, without regard to the presence of any extra permission bits (for example the executable bit). This will match a file which has mode 0777, for example.

find . -perm /222
Search for files which are writable by somebody (their owner, or their group, or anybody else).

find . -perm /220

find . -perm /u+w,g+w
find . -perm /u=w,g=w
All three of these commands do the same thing, but the first one uses the octal representation of the file mode, and the other two use the symbolic form. These commands all search for files which are writable by either their owner or their group. The files don't have to be writable by both the owner and group to be matched; either will do.

find . -perm -220
find . -perm -g+w,u+w
Both these commands do the same thing; search for files which are writable by both their owner and their group.

find . -perm -444 -perm /222 ! -perm /111
find . -perm -a+r -perm /a+w ! -perm /a+x
These two commands both search for files that are readable for everybody (-perm -444 or -perm -a+r), have at least on write bit set (-perm /222 or -perm /a+w) but are not executable for anybody (! -perm /111 and ! -perm /a+x respectively)


2. GREP COMMAND
-----------------------------------------------------------------------------
Small Introduction
grep searches the input files for lines containing a match to a given pattern list. When it finds a match in a line, it copies the line to standard output (by default), or whatever other sort of output you have requested with options.

grep "keyword" filename

search for the Keyword in the filename

grep "keyword" filename | grep -v "non-keyword"

the ‘-v’ here will display those keyword which don’t match with “non-keyword”.

For example, if you have a file, abc.txt, with this contents:

testing, 12345
#testing , this the wrong code
testing 3456
testing, 452345
testing, 652345
ates, 953645
btest 452345
#testing , this wrong code
#testing , this wrong code
#testing , this the wrong code

and you want to grep a “testing” keyword but not those staring with “#”:


grep testing abc.txt | grep -v #testing
and the result will be:
testing, 12345
testing 3456
testing, 452345
testing, 652345


grep -R "192.168.1.5" *
Use grep recursively You can search recursively i.e. read all files under each directory for a string "192.168.1.5"

grep -in test abc.txt
-i for ignore case while searching
-n for how the line number in the output
So in combination we can write as -in

3. COMBINATION OF TWO COMMANDS
---------------------------------------------------------------------------------------------
find . -type f -exec grep -qi “foo” {} \; -print
As an addition a very handy combination of find and grep I use almost every day: find a string inside a filename.


find . -type f -iname “*foo*”
where you can use patterns with wildcards vs. more complicated but more powerful

find . -type f -exec grep -qi “…regexp…” {} \; -print
as people often do not need regular expressions and the first is more easy to remember and type.

find . -type f -exec grep -il 'foo' {} \;

Blog Archive