Thursday, July 17, 2014

Road to RHCE - Day 8

Day 8

Network Configuration

IP classes

Class          Range           Default subnet mask        Prefix

Class A  -> 1 to 126     -> 255.0.0.0                      -> 8
Class B  -> 128 to 191 -> 255.255.0.0                  -> 16
Class C  -> 192 to 223 -> 255.255.255.0              -> 24
Class D  -> 224 to 235
Class E  -> 236 to 254

255 -> broadcast address

127 -> loopback address


Subnetting -> dividing a large network into small networks
Subnet Mask -> unique id for such small networks


To configure network using TUI client

system-config-network

[! there are 2 options available - device & dns configuration]

Device configuration


Name                             : eth0
Device                            : eth0
Use DHCP                      : None
Static IP                         : 192.168.0.109
Netmask                        : 255.255.255.0
Default gateway IP         : 192.168.0.254
Primary DNS server        : 192.168.0.254
Secondary DNS server    : 192.168.0.254

[! this is a sample setup that uses static IP]


To update the changes

service network restart


To check the IP of the system

ifconfig
ip addr show


Associated config files

1. /etc/sysconfig/network-scripts/ifcfg-eth0
[! to configure the ip]

2. /etc/sysconfig/network
[! contains the hostname of the system]

3. /etc/resolv.conf
[! contains the DNS info]



To get the current hostname of the system

hostname


To know the status of all configured devices

service network status



-- End of Day 8 --

-- End of SA1 --

Wednesday, July 16, 2014

Road to RHCE - Day 7

Day 7



Backup and Compression


To check the directory size

du -sh /etc/


To create an archive

tar -cvf [archive_name] [list_of_files]


To know the type of a file

file [filename]


To extract the contents of a tar file to a different path

tar -xvf [archive_name] -C [destination_path]


To compress an archive (or file)

zip [zip_filename] [source_filename]


To decompress a compressed file

unzip [zip_filename]


Using gzip (only for archives)

gzip [archive_filename]

[! gunzip [filename] to decompress]


Using bzip2 (more compression than gzip)

bzip2 [archive_filename]

[! bunzip2 [filename] to decompress]


To compress while archiving

tar -cvfz [archive.tar.gz] [list_of_files]

[! z -> gzip; j -> bzip2]


Process Management

To monitor the processes via gui

gnome-system-monitor


To list the processes running in current session

ps

[! ps -a for all active processes across sessions; ps a for all processes (including inactive ones) across sessions]


To list the parent proces id and the owner info

ps -f


To list the processes in a tree format

ps af


To list all processes including system ones

ps x


To know the session detail

w


To know users login info

lastlog


To run a process in background

[process/service_name] &


To list the background processes started by users

jobs


kill

To list all the available options with kill command

kill -l


Below are few of the important options

9   -> kill
15 -> terminate
18 -> continue
19 -> stop (temporarily)


To stop a job/process temporarily

kill -19 %[job_id | proces_id]



To resume the stopped job/process

kill -18 %[job_id | process_id]


To make a background process run in the foreground

fg %[job_id]

[! Ctrl+z -> to stop temporarily; bg %[job_id] to take that to background]


To terminate a process

kill %[job_id]
kill [process_id]

[! kill command defaults to option 15, if nothing else is specified]


To force kill a process

kill -9 [process_id]


To kill using the process name

pkill -9 [process_name]


top

To list the running processes

top

[! the display gets refreshed every 3 sec; top -d 1 to refresh the display every 1 sec]


To kill the process based on id

k


To sort top output based on memory utilised

Shift+M


To sort based on CPU usage

Shift+C


To sort based on user

U



-- End of Day 7 --

Tuesday, July 15, 2014

Road to RHCE - Day 6

Day 6


bash configuration

bash is one of the login shells available for users in linux & the most commonly used shell as well.

Below are the important configuration files for bash. These files are present under every user's home directory -

.bashrc                           - contains the session configuration of the user
.bash_profile                  - contains the profile info of the user
.bash_logout                  - contains the commands/actions to be executed at end of the session (logout)
.bash_history                 - history of commands used by the user (this file will be populated only during the first successful logout)


There are also global shell configuration that can be set for all users via below file -

/etc/bashrc
/etc/profile


inode

inode -> index node


To check the inode of a file or directory

ls -i [filename]


Links

There are two types of links -

hard link
soft link

hard link

  • points directly the memory location of the file
  • same inode as that of the physical file
  • can be accessible even if the actual file is deleted
  • not possible to create hard links for directories
  • like a backup for the physical file
  • occupies the same space as that of the file


soft link

  • points to the file
  • different inode than the physical file
  • can not be accessible if the physical file is deleted
  • it is possible to create soft link for directories
  • does not occupy additional disk space


To create a hard link

ln [filename] [link_name]


To create a soft link

ln -s [filename] [link_name]


Special Permissions

There are three special permissions that can be set for files & directories -

Special userid (suid)    -> owner
Special groupid (sgid) -> group
Sticky bit                     -> others


Special userid

If set, the file will get executed based on the owner's permission and not based on the executor's permission.


To set special user id

Symbolic Method -> chmod u+s [filename]
Numeric Method  -> chmod 4755 [filename]

[! the first digit (4 for owner, 2 for group, 1 for others) denotes the special permission]


Special groupid

If set for a directory, all the future files/directories that gets created under that directory will have the group owner same as that of the parent directory.


To set special groupid

Symbolic Method -> chmod g+s [directory]
Numeric Method  -> chmod 2755 [directory]


Sticky bit

If set for a directory whose content have permission set as 777, other users can edit the contents of that directory but cannot remove or rename or move them.


To set sticky bit

Symbolic Method -> chmod o+t [directory]
Numeric Method  -> chmod 1777 [directory]


To flush the history of the current logged in user

history -c



-- End of Day 6 --

Monday, July 14, 2014

Road to RHCE - Day 5

Day 5

I/O redirection

To redirect  the output of a command to a file

hwclock > [filename]


To redirect the error from a command to a file

hwclok 2> [filename]


To redirect the standard input to a file

cat > [filename] << [eof_string]
blah blah
blah blah
[eof_string]


A sample shell script to create a text file with contents

#!/bin/bash
cat > test1 << END
This is the first line
This is the second line
END


Use of pipe ( | ) symbol

The pipe ( | ) symbol is used to redirect the output of first command as the input of the second.

date | cat > date.out

[! the above command will create the date.out file with the current date as it's content]


Text processing tools

There are many text processing tools in linux, like -

less
head
tail
more
cat
grep
sed
awk
cut
diff
tailf
wc
sort


To display top 'n' number of lines in a file

head -n [filename]


To display bottom 'n' number of lines in a file

tail -n [filename]


To search a string in a file

grep [string] [filename]


sed

The definition of sed is System Editor. It is used to find and replace a string in a file.


To search and replace only the first occurrence of the string of every line temporarily

sed 's/old_value/new_value' [filename]


To search and replace all occurrences of the string temporarily

sed 's/old_value/new_value/g' [filename]


To search and replace all occurrences of the string permanently

sed -i 's/old_value/new_value/g' [filename]


To delete a line (say, 3rd line) using sed

sed -i '3d' [filename]


To extract specific field from a text file

cut -d: -f6 [filename]

[! where : is the delimiter and 6 denotes sixth field to extract]



To find the difference between two files

diff [file1] [file2]


To get the statistics of a text file

wc [filename]

[! this will provide the number lines, characters, words that are present in that file]


To sort the contents of a file

sort [filename]


To find a file

find -name "*.txt"

find /home/ -user testuser

[! this command searches all files owned by testuser under /home]


Executing commands with 'find'

  • Commands must be preceded with either -exec or -ok (-ok prompts before acting on each file).
  • Command must end with ' \;' (a space, a backslash and a semicolon)
  • Can use {} as filename placeholder

find -size +100M -exec mv {} /tmp/ \;

[! the above command will search for any file that is >100MB in the current directory and move all those files to /tmp/]


To create a dummy file of size 1GB

dd if = /dev/null of = [target_filename] bs = 100M count = 10



-- End of Day 5 --

Friday, July 11, 2014

Road to RHCE - Day 4

Day 4


File Management

There are different ways to create a file -

vim [filename]
touch [filename]
cat > [filename]
[! when using 'cat' command, press Ctrl+D to save. '>>' to append to an existing file]


To create a directory

mkdir [directory_name]


To create multiple files using touch

touch filename{1..10}
[! this option will work with mkdir command as well]


To copy a file

cp [source_file] [target]


To copy a directory

cp -r [source_directory] [target]


To move/rename a file or directory

mv [source] [target]
mv [old_name] [new_name]


To delete a file

rm [filename]


To delete a directory

rmdir [directory_name]

 [! this works only on empty directory]

rm -rf [directory_name]

[! this works even on directory with contents]


--End of Day 4--