Linux Unit II
Linux Unit II
The default prompt for the root user is a pound sign (also called a number sign
or a hash tag):
#
About Shells and Terminal Windows
Most Linux distributions make it easy for you to get to a shell from the GUI.
Here are two common ways to launch a Terminal window from a Linux
desktop:
• In the context menu that appears, if you see Open in Terminal, Shells, New
Terminal, Terminal Window, Xterm.
• Many Linux desktops include a panel at the top or bottom of the screen
from which you can launch applications.
About Shells and Terminal Windows
• The GUI is typically located on one of the first two virtual consoles, and the
other six virtual consoles are typically text-based virtual consoles.
• You can switch between virtual consoles by holding the Ctrl and Alt keys and
pressing a function key between F1 and F6.
• You can return to the GUI (if one is running) by pressing Ctrl+Alt+F1. On some
systems, the GUI may run on a different virtual console.
• Try it right now. Hold down the Ctrl+Alt keys and press F3. You should see a
plain-text login prompt. Log in using your username and password.
Gaining Access
$ su
Password: ******
#
Gaining Access
To enable full sudo access for the user user01, you could create /etc/sudoers.d/user01
with the following content:
• Environment variables are variables that are exported to any new shells opened
from the current shell.
You can refer to the value of any of those variables by preceding it with a dollar sign
($) and placing it anywhere on a command line.
For example:
$ echo $USER
Chris
This command prints the value of the USER variable, which holds your username
(chris). Substitute any other value for USER to print its value instead.
Shell Variables
• Using the alias command, you can effectively create a shortcut to any
command and options that you want to run later.
• You can add and list aliases with the alias command.
Help:
• Use the help command. Some commands are built into the shell, so they do not
appear in a directory.
• The help command lists those commands and shows options available with each
of them.
• Use --help with the command. Many commands include a --help option that you
can use to get information about how the command is used.
Man:
Man pages are the most common means of getting information about
commands as well as other basic components of a Linux system.
$ man passwd
14.MANAGING USER
ACCOUNTS IN UBUNTU
Content:
• User Management
• Group Management
User Management
Creating User Accounts
• The useradd --help command displays the basic options that can be used
to override the defaults.
• Some defaults, such as the range of valid UID numbers and default
password aging rules, are read from the /etc/login.defs file.
• The useradd command determines the default values for new accounts by
reading the /etc/login.defs and /etc/default/useradd files.
User Management
UID_MIN 1000
UID_MAX 60000
SYS_UID_MIN 200
SYS_UID_MAX 999
GID_MIN 1000
GID_MAX 60000
SYS_GID_MIN 201
SYS_GID_MAX 999
CREATE_HOME yes
User Management
• A group is a collection of users that need to share access to files and other system
resources.
• Groups can be used to grant access to files to a set of users instead of just a single user.
• Like users, groups have group names to make them easier to work with.
Group Management
• Internally, the system distinguishes groups by the unique identification number assigned
to them, the group ID or GID.
• By default, systems use the /etc/group file to store information about local groups.
Group Management
• Each line in the /etc/group file contains information about one group.
Without options the groupadd command uses the next available GID from the
range specified in the /etc/login.defs file while creating the groups.
The -r option creates a system group using a GID from the range of valid system
GIDs listed in the /etc/login.defs file.
To change a group later, use the groupmod command, as in the following example:
1. Listing commands:
1.1. Using ls commands to list all files and directories in current directory.
BASIC SHELL MANAGEMENT
1. Listing commands:
1.3. Using ls –l to long listing the files and directory information in a current directory
BASIC SHELL MANAGEMENT
1.4. Using ls –la for long listing the hidden files also.
BASIC SHELL MANAGEMENT
1.5. Using the ls –sh & ls –sha to listing the files and directory with size.
BASIC SHELL MANAGEMENT
1.6. To classify the files and directories, you can use ls –aF command
BASIC SHELL MANAGEMENT
2. Changing Directory:
2.1. Using cd command and followed by the directory path to changing the working
directory and you can verify by using the pwd command to check the present working
directory.
BASIC SHELL MANAGEMENT
2. Changing Directory:
2.2. Using cd command alone to get back to the user’s home directory.
BASIC SHELL MANAGEMENT
3.1. Use the date command to display the current time and date.
3.3. Use lsblk command to check the hard disk and partition informations
BASIC SHELL MANAGEMENT
3.5. Use cal, cal -3, cal –y (year) to list all the information of calendar in monthly
BASIC SHELL MANAGEMENT
3.6. Use bc command is for opening the basic calculator (use ctrl+c or ctrl+d to close)
BASIC SHELL MANAGEMENT
1.1. Create a file “perm” and adding executes(x) permission for user section to the file ‘perm’
Permission Management
1.2. Adding write (w) permission for group section and executes (x) permission for
other section to the file ‘perm’
Permission Management
1.3. Remove the execute (x) permission for user, write (w) permission for group and
execute (x) for other to the file ‘perm’
Permission Management
1.4. Changing the permission by using exactly (=) for the user section to the file ‘perm’
Permission Management
1.5. Adding write (w)permission to all the section for the file ‘perm’
Permission Management
1.6. Modifying the permission read, write, executes by using exactly (=) for the all section
to the file ‘perm’
Permission Management
3.2. Changing the group ownership permission for the directory ‘dir2’
3.3. Using ‘chown’ command to change both ownership and group ownership
14. WORKING WITH
TEXT FILES IN UBUNTU
Content:
• File Manipulation
File Manipulation
• The vi editor is difficult to learn at first, but after you know it, you never
have to use a mouse or a function key.
• You can edit and move around quickly and efficiently within files just by
using the keyboard.
File Manipulation
Starting with vi
Most often, you start vi to open a particular file. For example, to open a file called
/tmp/test, enter the following command:
$ vi /tmp/test
If this is a new file, you should see something similar to the following:
□
~
~
~
~
~
"/tmp/test" [New File]
File Manipulation
a: The add command. With this command, you can input text that
starts to the right of the cursor.
A: The add at end command. With this command, you can input text
starting at the end of the current line.
i: The insert command. With this command, you can input text that
starts to the left of the cursor.
File Manipulation
I: The insert at beginning command. With this command, you can input
text that starts at the beginning of the current line.
o: The open below command. This command opens a line below the
current line and puts you in insert mode.
O: The open above command. This command opens a line above the
current line and puts you in insert mode.
File Manipulation
Arrow keys: Move the cursor up, down, left, or right in the file one character
at a time. To move left and right.
H: Moves the cursor to the upper-left corner of the screen (first line on the
screen).
M: Moves the cursor to the first character of the middle line on the screen.
L: Moves the cursor to the lower-left corner of the screen (last line on the
screen).
EDITING FILES USING EDITORS
2.3. In insert mode all the keys are input, just insert some message
EDITING FILES USING EDITORS
2.6. In command mode use ‘dd’ for cut a single line or (n)dd for cut a multi lines
[‘n’ denotes the number of lines you want to cut] and use ‘p’ on before line to
paste the line.
EDITING FILES USING EDITORS
2.7. Use ‘u’ for undo the changes
EDITING FILES USING EDITORS
2.9 Use / and type any string the find the word in these file.
EDITING FILES USING EDITORS
2.10. Use ‘w’ for save, ‘q’ is for quit and ‘!’ for force
You can use these above values combine or you can use identically
EDITING FILES USING EDITORS
2.11. Using ‘cat’ command to verify the ouput.
Finding Files
The locate database is automatically updated every day. However, at any time the
root user can issue the updatedb command to force an immediate update.
[root@host ~]# updated
Finding Files
The locate command restricts results for unprivileged users. In order to see the resulting
file name, the user must have search permission on the directory in which the file resides.
Search for files with passwd in the name or path in directory trees readable by user on
host.
The first argument to the find command is the directory to search. If the directory
argument is omitted, find starts the search in the current directory and looks for matches
in any subdirectory.