Echo command
echo command is not exactly related to users. But it just echoes whatever you type. So if you say echo hello - it will display that
The first echo line just displays hello.
The second echo command displays my home directory. $HOME is an environment variable which stores current user's home directory.
The third echo command displays another environment variable $PATH. PATH indicates path of executable files. Whenever you type some command, the executable file with this command name is searched in the directories given by PATH variable. If the command is not found in any of the paths specified, then we get an error message - command not found.
Now let us put these commands together in a text file and try to run the file. To create a file, we can use vi editor or GUI editor called gedit. Since I am running a web terminal in a windows system, I do not have access to GUI editor.
I use cat command instead.
Cat command
it displays the content of a file. cat without a file name displays what ever you type on screen.
But we do a smart thing. We redirect the output of cat command to a file using redirect operator > so that the contents we type will be saved in a file. (Incidentally cat >> will append the contents to a file.)
OK. Now we have a file which has 3 commands in it. Can we execute these 3 commands by calling this file name - a.sh?
Of course. This is called a shell script. (because all these are shell commands).
Making a file executable
So let us try to run the file.
OK, a little apology here. Being frustrated enough with web terminals of Linux systems and working with them on Windows, I have changed to a Ubuntu system.
I gave chmod u+x a.sh command. So I have added execute permission to a.sh file.
But the idea here is by giving "x" permission to a file making it "executable".
I have given "x" permission only to myself, not to group, not to others.
Note :
OK, a little apology here. Being frustrated enough with web terminals of Linux systems and working with them on Windows, I have changed to a Ubuntu system.
I gave chmod u+x a.sh command. So I have added execute permission to a.sh file.
But the idea here is by giving "x" permission to a file making it "executable".
I have given "x" permission only to myself, not to group, not to others.
Note :
- All executable files are displayed in green color
- Directories are displayed in blue color
Let us get a little bit introspective next. It is needed in this world to keep our sanity :)
We could not run the command as ordinary user. In some Linux systems, to gain root privilege, we should use su command. But in Ubuntu, we have to use sudo command.
So sudo useradd indicates run the command as root. And we will be prompted to provide password of our own account.
We also added a password to Harry's account using sudo passwd. Now let us login as Harry using CTRL+ALT+F1 and giving user name as Harry and password as the password we gave just now. I can not take screen shot of that screen. But I have logged on as Harry in tty1.
tty1 to tty6 are command terminals which can be started using CTRL+ALT+ F1 to F6. When we press CTRL+ALT+F7, we come back to GUI terminals.
Now we have two users logged on to our systems. So what does who tell us?
Who am I
This command will not tell you a you are a human or Mr XYZ. Instead, it tells you your user name.
Those are two pieces of information about your account in the system. whoami gives you your account name. And environment variable $HOME gives you your home directory.
who command
Are you curious as to know, who are the other users logged on to your system? Or are you a home user, having installed Ubuntu in your system?
In any case who gives you the name of users logged on to different terminals.
First let us add another user to make who look interesting.
useradd Harry
adds a user by the name Harry - you need a root privilege for this command.
We could not run the command as ordinary user. In some Linux systems, to gain root privilege, we should use su command. But in Ubuntu, we have to use sudo command.
So sudo useradd indicates run the command as root. And we will be prompted to provide password of our own account.
We also added a password to Harry's account using sudo passwd. Now let us login as Harry using CTRL+ALT+F1 and giving user name as Harry and password as the password we gave just now. I can not take screen shot of that screen. But I have logged on as Harry in tty1.
tty1 to tty6 are command terminals which can be started using CTRL+ALT+ F1 to F6. When we press CTRL+ALT+F7, we come back to GUI terminals.
Now we have two users logged on to our systems. So what does who tell us?
So we see 4 users, 2 of which are pts terminals - terminals in our GUI screen and one is tty1 screen. And tty1 screen has user Harry.
Command userdel
If you want to remove a user you can use userdel comamnd - of course with root privilege.
So let us try this command.
sudo userdel Harry
What is this? We get an error message saying
userdel: user Harry is currently used by process 6745
So let us log out Harry from tty1 and then delete this user.
sudo userdel Harry
And now we have successfully deleted the user.
Comments
Post a Comment