List all the Grups and users in linux

scmuser created the topic: List all the Grups and users in linux
Hi,

How can we list our all the users in Linux?

How to list all the users created in linuz machine?

rajeshkumar replied the topic: Re: List all the Grups and users in linux

Following command will work for you….

less /etc/passwd
less /etc/group

Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

Tagged :

Command Not Found With Visudo

scmuser created the topic: command not found with visudo
Hi,

I want to edit visudo and include one user for running apache but when i type following command as a user”root”
visudo

i get following error…
command not found..

P.S: I have tried to edit directly /etc/sudoers but it was not allowed.

rajeshkumar replied the topic: Re: command not found with visudo

Try with this options…
su –
visudo
Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

scmuser replied the topic: Re: command not found with visudo
I am getting following error… when login as a normal users… and run following command..
sudo ./apachectl start

i get following error….

USER is not in the sudoers file. This incident will be reported.

rajeshkumar replied the topic: Re: command not found with visudo
Normal users is not having permission to execute “sudo” command..

you will have to do the following…

Login as a root
su root

password: XXXXX

su -

visudo

Add the following line in sudoers file…

# User privilege specification
root ALL=(ALL) ALL
rajesh ALL=(ALL) ALL –
This was added by me…

and then “rajesh” can execute any command with sudo

Regards,
Rajesh
Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

Tagged :

File Copying and Transfer between two machine

rajeshkumar created the topic: File Copying and Transfer between two machine

File Copying and Transfer between two machine or within machine.

Command 1: cp – Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.

Command 2: ftp – ARPANET file transfer program (put / get

Command 3: rsh – Runs a command on another computer.
Rsh connects to the specified host, and executes the specified command. Rsh copies its standard input to the remote command, the standard output of the remote command to its standard output, and the standard error of the remote command to its standard error. This implementation of rsh will accept any port for the standard error stream. Interrupt, quit and terminate signals are propagated to the remote command; rsh normally terminates when the remote command does.

rsh otherhost cat remotefile >> localfile

Command 4: rlogin

Command 5: kerberos – introduction to the Kerberos system
The Kerberos system authenticates individual users in a network environment. After authenticating yourself to Kerberos, you can use network utilities such as rlogin, rcp, and rsh without having to present passwords to remote hosts and without having to bother with .rhosts files. Note that these utilities will work without passwords only if the remote machines you deal
with support the Kerberos system.

Kerberos is a network authentication protocol. It is designed to provide strong authentication for client/server applications by using secret-key cryptography.

Command 6: rcp
Rcp copies files between machines. Each file or directory argument is either a remote file name of the form “rname@rhost:path”, or a local file name (containing no `:’ characters, or a `/’ before any `:’s).

The command rcp copies files between computer systems. To be able to use the rcp command, both computers need a “.rhosts” file in the user’s home directory, which would contain the names of all the computers that are allowed to access this computer along with the user name. Here is an example of an .rhosts file:
zeus.univ.edu jdoe
athena.comp.com mjohnson

The ftp command can be used to copy files between computers if no .rhosts file is set up.
Examples:
rcp document1 zeus.univ.edu:document1

Copies “document1” from the local machine to the user’s home directory on the computer with URL zeus.univ.edu, assuming that the user names are the same on both systems.
rcp document1 jdoe@:zeus.univ.edu:document1

Copies “document1” from the local machine to the home directory of user “jdoe” on the computer with URL zeus.univ.edu.
rcp -r documents zeus.univ.edu:backups

Copies the directory “documents”, including all subdirectories, from the local machine to the directory “backups” in the user’s home directory on the computer with URL zeus.univ.edu, assuming that the user names are the same on both systems.
rcp -r zeus.univ.edu:backups/documents study

Copies the directory “documents”, including all subdirectories, from the remote machine to the directory “study” on the local machine.

Command 6: scp – secure copy (remote file copy program)

Command 7: cpio – Creates and un-creates archived cpio files. And also is capable of copying files to things other than a hard disk.
Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

rajeshkumar replied the topic: Re: File Copying and Transfer between two machine
Some Quick Notes for this…

Remote machine Login : telnet, rlogin
File Transfer: ftp, rcp, scp
Remote login without Password: rsh
Secure Login with password: ssh
Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

Tagged :

Remove blank line using Grep and sed

scmuser created the topic: Remove blank line using Grep and sed
Hi,

How do you remove blank line using grep and sed in shell scripting?

rajeshkumar replied the topic: Re: Remove blank line using Grep and sed

grep -v "^$" filename > newfilename

The ^$ within the quotes is a regular expression: ^=beginning of line, $=end of line, with no characters between.

To store output to another file use redirection operator:

$ sed ‘/^$/d’ /tmp/data.txt > /tmp/output.txt

Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

rajeshkumar replied the topic: Re: Remove blank line using Grep and sed
The above script will work only if you have no character in the blank line but most of the time it can happen that Tab can be possle in blank line….

so for this situation u should try following..

sed '/^[PRESS TAB]*$/d' filename

Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

Tagged :

Find command return type

scmuser created the topic: Find command return type
I am looking for following answer if anybody can help me out…

How to Return a message when a file is not found using find command? OR
Find command return type OR
when the file is not found i want it to return some value OR

tpatil replied the topic: Re: Find command return type
You can use exit code of find command to return the message.

e..g.

find . -name abc.txt > dev/null

if test $? -eq 0
then
echo "File found"
else
echo "File Not Found"
fi

Hope this helps…

rajeshkumar replied the topic: Re: Find command return type
Hi..

I guess following script will not work. The problem here is find command does always return true value no matter if find is available or not.

this is unique things in find command.

I feel we should go ahead in this way.

find . -name raj.txt > raj.txt
counter= `cat abc.txt | wc -l'

if [$counter -gt 0]
then
echo "File is found"
else
echo "File is not found"
fi

please let us your inputs on this
Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

tpatil replied the topic: Re: Find command return type
Thanks Rajesh…You are right. I tried with my code. Find always retuns 0 though file not found.

Tagged :

Nested for loop in Linux Shell Script

scmuser created the topic: Nested for loop in Linux Shell Script

As you see the if statement can nested, similarly loop statement can be nested. You can nest the for loop. To understand the nesting of for loop see the following shell script.
$ vi nestedfor.sh
for (( i = 1; i <= 5; i++ )) ### Outer for loop ### do for (( j = 1 ; j <= 5; j++ )) ### Inner for loop ### do echo -n "$i " done echo "" #### print the new line ### done Run the above script as follows: $ chmod +x nestedfor.sh $ ./nestefor.sh 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 Here, for each value of i the inner loop is cycled through 5 times, with the varible j taking values from 1 to 5. The inner for loop terminates when the value of j exceeds 5, and the outer loop terminets when the value of i exceeds 5. Following script is quite intresting, it prints the chess board on screen. $ vi chessboard for (( i = 1; i <= 9; i++ )) ### Outer for loop ### do for (( j = 1 ; j <= 9; j++ )) ### Inner for loop ### do tot=`expr $i + $j` tmp=`expr $tot % 2` if [ $tmp -eq 0 ]; then echo -e -n "\033[47m " else echo -e -n "\033[40m " fi done echo -e -n "\033[40m" #### set back background colour to black echo "" #### print the new line ### done Run the above script as follows: $ chmod +x chessboard $ ./chessboard Above shell script cab be explained as follows:

Tagged :

Find a Number of File in Directories Recursively

scmuser created the topic: find a number of file in directories recursively
I have several directories and files underneath…how to find only files from all directories…

any command

rajeshkumar replied the topic: Re: find a number of file in directories recursively
Try following command
find ./ -type f | wc -l

For finding only files from all directories recursively
find ./ – type d | wc -l

For finding only directory om all directories recursively
Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

opendesk replied the topic: Re: find a number of file in directories recursively
From DOS Command prompt, you can do:

dir /A-d /b /s

or in java, you need to do recursion. Here is a java code snippet.

public void visitAllFiles(File dir) {
if (dir.isDirectory()) {
String[] children = dir.list();

for (int i = 0; i < children.length; i++) { visitAllFiles(new File(dir, children)); } } else { processFiles(dir); } } All the best 🙂 rajeshkumar replied the topic: Re: find a number of file in directories recursively
Good Input.. Thanks a lot.

Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

Tagged :

List all the users in linux

rajeshkumar created the topic: List all the users in linux
List all the users in Linux

cat /etc/passwd | cut -d”:” -f1
Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

rajeshkumar replied the topic: Re: List all the users in linux
Some of other options are….

cat /etc/passwd | gawk ‘FS=”:” {print $1}’

ls /home

cat /etc/passwd | cut -d: -f 1,3,6 | grep “[5-9][0-9][0-9]” | grep “/home” | cut -d: -f1
Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

Tagged :

Character values in computer

scmuser created the topic: Character values in computer
Hi,

Every character has a value associated with it. What is it called?

scmjobs replied the topic: Re: Character values in computer

Each alphabet, number or symbol is known as a character, which represents the smallest piece of information that you can deal with. All these characters have unique values assigned to them, called the ASCII value. for instanse, the letter A has the ASCII value 65, while the bang or exclamation mark (!) has the value 21.

Tagged :