You are on page 1of 26

uname -a --linux system infor

uname -r --kernel rel info

uname -a
uname -r
uptime

hostname

hostname -i ipadd of host

hostname -i ip add of host


hostname
hostname -i ip add of host

last reboot sytem reboot history


last reboot
last reboot
hostname -i
uname -r
date
cal
cal
whoami who you are logged in as
whoami who you are logged in as
whoami
dmesg detected hardware and boot message
dmesg detected hardware and boot message
dmesg detected

___________________________________________________________________________________
_________

rht -vmctl start server


rht -vmctl start server
rht -vmclt start server
rht -vmctl start server
rht -vmctl start server
rht -vmctl view server
rht -vmctl view server
rht -vmctl view server
rht -vmctl reset server
rht -vmctl reset server
rht -vmctl reset server
rht -vmctl reset server

gnome-control-center region
gnome-control-center region
gnome-control-center region
LANG=fr_FR.utf8 date
LANG=fr_FR.utf8 date
LANG=fr_FR.utf8 date
LANG=fr_FR.utf8 date

CLI is command line interface--It is a text based interface which is used to enter
commands and to give instructions to computer
Linux command line is prvided by a program called as shell
Default shell in linux is bash GNU bourne-again shell bash

GNU bourne-again shell--bash improved version of bourne shell--sh


shell prompt $
# privilge mode when shell is running in root

usermod -L morgan

ctrl+d to end session

GNOME shell

Parts of Gnome shell

TOP bar--applications and places , vol ,net

menu for the user's name--

Message tray open--Super+M

date +%R
date +%R
date +%X
date +%X

passwd
passwd
passwd
file /etc/passwd

file /etc/passwd
file /home
file /etc/bin

head /etc/passwd

10 lines tail /etc/passwd

tail -n 3 /etc/passwd

wc /etc/passwd count lines

wc -l /etc/passwd count line only

wc -w /etc/passwd count word only

wc -c /etc/passwd count character only

history

ls listing of files/ directory


ls -al formatted listing with hidden files
cd home--change directory to home
mkdir home make directory home

ls --al
ls --al
ls --al formatted listing with hidden files

rm -r rajan removes directory rajan


rm -f rajan forcefully removs rajan file

rm -r rajan
rm -f rajan
rm -rf rajan forcefully removes directory rajan

rm -rf rajan

cp -r dir1 dir2 copy dir 1 to dir 2 and if dir 2 is not existing then will create
it.

cp -r dir1 dir2
mv rajan1 rajan2

ln -s file link

ln -s file link

ln -s file link

A symlink (symbolic) is a type of file that points to other files or directories


(folders) in Linux.
You can create a symlink (symbolic) by using the ln command in the command line.
Symbolic links are useful because they act as shortcuts to a file or directory

cat > rajan std input into file rajan


cat > rajan
tail -f rajan output last 10 lines as it grows

cal shw calender


cal

who is online w

whoami
whoami
whoami
finger user --display info abt user

finger user finger user

uname -a show kernel information


uname -a show kernel information
uname -a
uname -a

cat /proc/cpuinfo
cat /proc/meminfo
cat /proc/cpuinfo
cat /proc/meminfo
man
man
df show disk usage
df show disk usage
du show directory usage
du
du
df
free show memory and swap usage
free show mem and swap usage

whereis app shows possible loc of app


whereis app
whereis app
which app
which app
which app

ps display urs currently active process


top
top top display all running process
ps
ps
top

kill pid

kill pid kill process id pid

kill pid

killall proc kill all processes named proc


killall
killall
touch rajan
cat rajan
mkdir rajan
more rajan
bg lists background jobs
bg
bg resume a stopped job in background

fg bring the most recent job to foreground


fg bring the most recet job to foreground

fg n brings the job n to foreground

fg n

tar cf rajan.tar files


tar cf rajan.tar files

tar cf rajan.tar files create a tar names rajan.tar conatining files

tar xf rajan.tar
tar xf rajan.tar
tar xf rajan.tar extract the file from rajan.tar

tar xf rajan.tar

tar czf rajan.tar.gz files

tar czf rajan.tar.gz files create a tar with Gzip compression


tar czf rajan.tar.gz files

tar czf rajan.tar.gz files

tar xzf rajan.tar.gz extract a tar using Gzip


tar xzf rajan.tar.gz

tar xzf rajan.tar.gz

tar cjf rajan.tar.bz2 create a tar using Bzip2 compression


tar cjf rajan.tar.bz2
tar cjf rajan.tar.bz2

tar xjf rajan.tar.bz2 extract a tar using bzip2


tar xjf rajan.tar.bz2
tar xjf rajan.tar.bz2

gzip rajan
gzip rajan
gzip rajan compresses file and rename to rajan.gz

gzip -d rajan.gz
gzip -d rajan.gz
gzip -d rajan.gz decompresses rajan.gz back to rajan
gzip -d rajan.gz

ping host

whois domain
whois domain get whois info for domain
whois domain
dig domain
dig domain
dig domain get DNS info for domain
dig domain

dig -x host
dig -x host reverse lookup host
dig -x host

___________________________________________________________________________________
__________________________________

ssh admin@192.187.1.2
ssh admin@192.187.1.2

ssh -p 65022 admin@192.187.1.2 ssh with port no.


ssh -p 65022 admin@192.187.1.2 ssh with port no.

ssh admin@192.187.1.2:65022
ssh -p 65022 admin@192.187.1.2 ssh with port no.

exit

ctrl +d exit

date +%r --display current time in 12 hr clock time

date +%r

date +%r

date +%r --display current time in 12 hr clock time

ctrl + A --jump to the begining oc cmd line

ctrl+ A --jump to the begining of cmd line

ctrl + A --jump to the begining of cmd line

ctrl + E --jump to the end of cmd line

ctrl + E --jump tot the end of cmd line

ctrl + E --jump to the end of cmd line

ctrl + U---clear from the cursor to the begining of cmd line

ctrl + U--clear from the cursor to the begining of cmd line

ctrl + U --clear from the cursor to the begining of cmd line

ctrl + k--clear from the cursor to the end of cmd line

ctrl + K --clear from the cursor to the end of cmd line

ctrl + leftarrow--jump to the begining of previuos word on cmd line


ctrl+ leftarrow---jump to the begining of previous word on cmd line

ctrl+ right arrow--jump to the end of next word on the cmd line

ctrl+ right arrow--jump to the end of next word on cmd line

ctrl + R --search for the history list of cmds for a pattern

ctrl + R--search for the history list of cmd for a pattern

/usr--installed software , shared lib , include file and read only program data

/usr--installed software ,,shard lib , inlcude file and read only program data

/usr--installed software,,shared lib, include file and read only program data
sub direc of /usr-- /usr/bin--user cmds

/usr/sbin--system administrator cmds

/usr/local--locally customized software


/usr/local--locally cutomized software

/etc--configuration files specific to this system


/etc--.conf file ,,conf files specific to this system

/var--variable data spcific to this system that should persist b/w boots
/var varaible data specific to this system that should persist b/w boots

//var--variable data specific to this system that should persist b/w boots

/run---run time data for processes started since the last boot

/run --run time data for the processes started since the last boot

/run--run time data for the processes started since the last boot
/home---home directories
/home--home dierctories

/root--home directory for the administrative superuser, root

/root--home directory for the adminsistrative superuser , root

/root--home directory for the administrative superuser, root

/tmp----A world-writable space for temporary files

/tmp---writabel space for temporaray files for all

/tmp--writable space for temporaray files for all

/boot --files needed to start the boot process

/boot--files needed to start the boot process

/boot--files needed to start the boot process

/dev--contains special device files that are used by the system to access hardware

/dev--contains special device files that are used by the system to access hardware

/dev--contains special device files that are used by the system to access hardware

ls -ltr : To sort the file names in the last modification time in reverse order

ls -ltr : to sort the file names in the last modification time in reverse order..

ls -ltr : to sort the file names in the last modification time in reverse order

ls -al --to display all info abt files and directory.

rm -r rajan(dir)-- to remove directory recursively


rm -f rajan --to remove rajan file forcd fully

rm -f rajan-- to remove rajan file force fully.

cp file1 file 2--copy file 1 to file 2

cp -r rajan1 rajan 2--copy directory 1 to directory 2

mkdir -p ---cerate multiple parent directories with subdirectories

mkdir -p --create multiple parent directory with sub directories

touch --create a 0kb file or update a file

nano---create a 0k kb file or update a file

nano---create a 0 kb file or update a file

cat > file1 ---places input into file1

cat > file1---places inptu into file1

tac reverse of cat

cd --change directory

cd change directory

cd .. --chnage to parent directory

cd ..--change to parent directory

ln file1----to create hard link

ln file1--to create hard link

ln file1---to create hard link

ln file1---to create hard link

ln -s file1
ln -s file1
ln -s file1

| A pipe line is a sequence of one or cmds separated by the pipe character (|).

A pipe connects the std output of the first cmd to the std input of the next cmd.

A pipeline is a sequence of one or more cmds separated by the pipe character.

A pipe connects the std output of the firt cmd to the std input of next cmd.

:wq write the file and quits vim editor


:wq write the file and quits vim editor

sudo su-
sudo su-
sudo su-
chmod chnages the file permission

chown cmd chnages the file ownership

___________________________________________________________________________________
_____________________________

rht-vmctl start server


rht-vmctl stop server
rht-vmctl view server

rht-vmctl reset server

LANG=fr_FR.utf8 date to set french lang and date

LANG=fr_FR.utf8 date

LANG=en_US.utf8 date

LANG=en_US.utf8 date

localectl set-locale LANG=fr_FR.utf8


localectl set-loacle LANG=en_US.utf8

A command line is a text-based interface which can be used to input instructions to


a computer
system. The Linux command line is provided by a program called the shell.

The default shell for users in Red Hat


Enterprise Linux is the GNU Bourne-Again Shell (bash).

Bash is an improved version of one of


the most successful shells used on UNIX-like systems, the Bourne Shell (sh).

When a shell is used interactively, it displays a string when it is waiting for a


command from the
user. This is called the shell prompt. When a regular user starts a shell, the
default prompt ends
with a $ character.
rl [student@desktopX -]$

The $ is replaced by a # if the shell is running as the superuser, root. This makes
it more obvious
that it is a superuser shell, which helps to avoid accidents and mistakes in the
privileged accou nt.
[root@desktopX -]#

With a graphical environment


running, access a text login prompt on a virtual console by holding Ct rl +Alt and
pressing a
function key (F2 through F6).
Press Ctrl +Alt+Fl to return to the first virtual console and the
graphical desktop.
Commands entered at the shell prompt have three basic pa rts:
• Command to run
• Options to adjust the behavior of the command
• Arguments, which a re typica lly targets of the command

The interpreter that executes commands typed - as strings.-- Shell

- The visual cue that indicates an interactive shell is wating for the user to type
a command.--- Prompt

-
The name of a p rog ram to run. --Command
-
The part of the command line that adjusts the - behavior of a command.------Option

- The pa rt of the command line that specifies the ta rget that the command should
operate on.---- Argument

-
The hardware display and keyboard used to - interact with a system.---Physica l
conso le

·- One of multiple logical consoles that can each support an independent login
session.---- Virtual con so le

-
An interface that provides a display for output and a keyboard for input to a
shell session. ---Terminal -

The default des ktop environment in Red Hat Enterprise Linux 7 is provided by GNOME
3

Starting a terminal-- Select Appl icat ions > Ut ilities > Terminal

On an empty des ktop, rig ht-c l ick, or press the Menu key, and select Open in
Terminal from the
context menu that appears.

To lock the screen, select (User)> Lock or type Ct rl+Alt+L. The screen will lock
if the graphical
sess ion is idle for a few min utes.

To shut down the system, select (User)> Power Off from the top bar or type Ct rl+Al
t+Del

[student@desktopX -]$ date


Sat Apr 5 08 : 13:50 PDT 2014

[student@desktopX -]$ date +%R


08 : 13

[student@desktopX -]$ date +%x


04/05/2014
[student@desktopX -]$ passwd
Changing password for user student .
Changing password for student .
(current ) UNIX password : old_password
New password: new_password
Retype new password : new_password
passwd : all authentication tokens updated successfully.

The file command scans the beginning of a file's contents and displays what type it
is.
The files to be classified are passed
as arguments to the command.

[student@desktopX -]$ file /etc/passwd


RH124-RHEL 7-en-1-20140606 15
/etc/passwd : ASCII text
[student@desktopX -]$ file /bin/passwd
/bin/passwd : setuid ELF 64-bit LSB shared object, x86-64, version 1
(SYSV) , dynamically linked (uses shared libs), for GNU/Linux 2.6.32,
BuildID[sha1]=0x91a7160a019b7f5f754264d920e257522c5bce67, stripped
[student@desktopX -]$ file /home
/home : directory

[student@desktopX -]$ head /etc/passwd


root:x:0:0: root : /root : /bin/bash
bin:x:l:l:bin : /bin : /sbin/nologin
daemon :x:2:2: daemon : /sbin : /sbin/nologin
adm:x:3:4:adm: /var/adm: /sbin/nologin
lp :x:4:7:lp : /var/spool/lpd : /sbin/nologin
sync:x:5:0: sync :/sbin : /bin/sync
shutdown:x:6:0: shutdown : /sbin : /sbin/shutdown
halt:x:7:0: halt :/sbin : /sbin/halt
mail:x:8:12:mail: /var/spool/mail: /sbin/nologin
operator :x:11:0:operator : /root : /sbin/nologin
[student@desktopX -]$ tail -n 3 /etc/passwd
gdm:x:42:42: : /var/lib/gdm: /sbin/nologin
gnome-initial-setup :x:993: 991: : /run/gnome-initial-setup/: /sbin/nologin �--
tcpdump :x:72:72 : : / :/sbin/nologin

The wc command
----�------------------------------'
counts l i nes, words, and characters in a file. It can take a -l, - w, or -c
option
to display only the lines, words, or characters, respectively.

�- �student@desk:�pX -]$ wc /etc/passwd


39 70 2005 /etc/passwd
[student@desktopX -]$ wc -1 /etc/pas swd
39 /etc/passwd
[student@desktopX -]$ wc -c /etc/group /etc/hosts
843 /etc/group
227 /etc/hosts
1070 tota
wc -l /etc/file1
wc -l /etc/file1
wc -c

[student@desktopX -]$ history


... Output omitted ...
23 clear
24 who
25 pwd
26 ls /etc
27 uptime
28 ls -1
29 date
30 history

The exclamation point character, ! , is a metacharacter that is used to expand


previous
commands without having to retype them. ! number expands to the command matching
the
number specified. ! string expands to the most recent command that beg ins with the
string
specified.

[student@desktopX -]$ !ls


ls -1
total e
drwxr-xr-x. 2 student student 6 Mar 29 21: 16 Desktop
... Output omitted ...
[student@desktopX -]$ !26
ls /etc
ab rt
adj time
aliases
... Output omitted ...
hosts
hosts . allow
hosts . deny
pulse
purple
qemu-ga

What kind of file is /usr/bin/clean - binary - files? Is it readable by humans?

Use the file command to determine its file type.


I
. [student@desktopX -]$ file /usr/bin/clean - binary - files
/usr/bin/clean-binary-files : POSIX shell script, ASCII text executable

The ls command has multiple options for displaying attributes on fil es. The most
common and
usefu l are -1 (long l isting format), - a (a ll files, includes hidden fil es),
and -R (recursive, to include
the contents of all subdirectories

The command cd ~ changes directory to the directory where the user was previous to
the
current directory. Watch as this user ta kes adva ntage of this behavior to
alternate between two
directories, useful when process ing a series of similar tasks.

List the current user's home d irectory (long format) in simp l est syntax, when it
is not the c u rrent location. ---ls -l ~

file starting with . is a hidden file ls -R shows all subdirectories

The cd .. command uses the .. hidden directory to move up one leve l to the parent
d irectory,
without needing to know the exact parent name. The other hidden directory (.)
specifies the
current directory on commands in which the cu rrent location is either the source
or desti nation
arg ument. avoiding the need to type out the directory's absol ute path name.

[student@desktopX Videos]$ pwd


/home/student/Videos
[student@desktopX Videos]$ cd .
[student@desktopX Videos]$ pwd
/home/student/Videos
[student@desktopX Videos]$ cd
[student@desktopX -]$ pwd
/home/student
[student@desktopX -]$ cd ..
[student@desktopX home]$ pwd
/home
[student@desktopX home]$ cd
[student@desktopX /]$ pwd
I
[student@desktopX /]$ cd
[student@desktopX -]$ pwd
/home/student
[student@desktopX -]$

List the c u rrent user's home directory (long fo rmat) in


- simplest synta x, when it is n ot the current l ocation. ---ls -l ~

Return to the most p revious working d irectory. cd ~

cd ~--return to previuos working direc

M ove up two leve ls from the c u rrent l ocation cd ../..

cd ../..

rm file1

cp file1 file2

mv file1 file2---The result is a rena me


mkdir dir1

cp -r dir1 dir2p--The " recursive" option is required to p rocess a source


directory.

cp -r dir1 dir2---- Copying non-empty


directories, with contents, requires the - r recursive option.

mv dir1 dir2--- lf dir2 exists, the result is a move. If dir2 doesn't exist, the
result is a
rename

mv dir1 dir2

rm -r dir1

cp file1 file2 file3 dir1

cp file1 file2 file3 dir1

mv file1 file2 file3 dir1--The last argument must be a directo ry.

mv file1 file2 file dir1

mv dile1 file2 file3 dir1

rm -f file1 file2 file3----use caution with "force" option; you will not be
prompted to confirm
yo ur action.

rm -f file1 file2 file3

mkdir -p par1/par2/dir-----use caution with "create parent" option; typing errors


are not caught.

mkdir -p par1/par2/dir

cp -r dir1 dir2 dir3 dir4

mv dir1 dir2 dir3 dir4

rm -rf dir1 dir2 dir3 dir4

rm -rf dir1 dir2 dir3 dir4

The mkdir command creates one or more directories or subdirectories, generating


errors if
the file name already exists or when attempting to create a directory in a parent
directory
that doesn't exist. The -p parent option c reates missing pa rent directories for
the requested
destin ation. Be cautious when using mkdir - p, since accidental spel ling m
istakes create
unintended directories without generating error messages.

cd ../documents
cd ../dir1

ls -lR

ls -lR

rm -ri Thesis

rm -ri Thesis -ri will recursively remove directory thesis and all its content.
but due to i it will interactively prompt for each file or subdirectory deletion
from thesis directory

The rmdir command deletes directories only if empty. Removed directories ca n not
be
undeleted.

rmdir dir1

if not empty then rmdir -r dir1

cd ../friends

/friends$cp ~/music/music1 ~/music/music2 ~/pic/pic1 ~/pic/pic2 ~/file/file1

* Any string of 0 or more characters.

* any string of 0 or more characters

* any string of 0 or more characters

? any single character

? Any single character.


~ --The cu rrent user's home directory.

~ ~ ~
~+ --current working directory.

~+ -- ~+ ~+

~username ---User username's home directory.

~username ~username ~username


~+ The cu rrent worki ng directory.

~- ==The previous working d irectory.


~- ~- ~-

[abc ... ] Any one character in the e nclosed c lass.


[abc] [anc]

[!abc ... ]Any one character not in the enclosed c l ass.


[!abc] [!abc] [!abc]
[[:alpha:]] Any alphabetic character. [[:alpha:]]
[[:alpha:]]

[[:lower:]] Any l ower-case character. [[:lower:]]


[[:lower:]]
[[:lower:]] [[:lower:]]
[[:upper:]] [[:upper:]]
[[:upper:]] Any upper-case character.

[[:alnum:]] Any alp habetic character or dig it.

[[:alnum:]] [[:alnum:]] [[:alnum:]] [[:alnum:]]

[[:punct:]] Any printable character not a space or alphanumeric.°

[[:digit:]] Any digit, 0-9. [[:digit:]] [[:digit:]]

mkdir dir1 ; cd dir1

mkdir dir1 ; cd dir1

touch raja bravo extra dun kill cahe --will cerate all empty files with current
date and time

ls [ac]*

will list all files having char as a and c in their name

ls *a
ls a*

ls *a*

ls ????

list files with 4 char name

ls ????? list file with 5 char name

The tilde character (~), when followed by a slash delimiter, matches the cu rrent
user's home
directory. When fo llowed by a stri ng of characters up to a slash, it will be
interpreted as a
username, if one matches. If no username matches, then an actual tilde followed by
the string of
characters will be returned.

Command su bstitution a l lows the output of a command to rep l ace the command
itse lf. Command
su bstitution occurs when a command is enc losed with a beginning dollar sign and
parenthesis,
$ ( command), or with backticks, · command'.
echo Today is 'date +%A'

echo Today is 'date +%A'

echo today is 'date +%A'


today is Wednesday.

echo The time is $(date +%M) minutes past $(date +%1%p)

echo The time is $(date +%M) minutes past $(date +%1%p)

echo The time is $(date +%M) minutes past $(date +%1%p)

The time is 26 minutes past 11AM.

[student@desktopX glob]$ host=$(hostname); echo $host

desktopX

host=$(hostname) ; echo $host

[[:space: ]] Any one whitespace character; may incl ude tabs, newline, or carriage
returns, and form feeds as we ll as space.

[student@desktopX glob]$ echo "Will variable $host evaluate to S ( hostname }?"


Will variable desktopX evaluate to desktopX?
[student@desktopX glob]$ echo ' Will variable Shost evaluate to S ( hostname}? '
Will variable $host evaluate to $(hostname)?
[student@desktopX glob]$

---Besides suppressing globbing and shell expa nsion, q uotations direct the shell
to additionally suppress
command and va ria ble su bstitution. The q uestion mark is a meta-character that
also needed
protection from expansion.

[student@desktopX glob]$ host=$(hostname); echo $host


desktopX

[student@desktopX glob]$ echo "***** hostname is ${host}******"

***** hostname is desktopX *****

Red Hat Package Manager (RPM) package

Man command handling-----

Spacebar Scroll forwa rd (down) one screen


Page Down Scroll forwa rd (down) one screen
Page Up Scroll backwa rd (u p) one screen
DownAr row Scroll forwa rd (down) one line
UpArrow Scroll back (u p) one line

n
N
g
G
q
n---Repeat previous search forwa rd (down) in the man page
N---Repeat previous search bac kwa rd (up) in the man page
g---Go to start of the man page.
G----Go to end of the man page.
q---Exit man and return to the command shel l prompt

A keyword search of man pages is performed using man - k keyword, which displays a
l i st of
keyword-matching man page topics with section numbers.

[student@desktopX -]$ man -k passwd

checkPasswdAccess (3) query the SELinux policy database in the kernel.


chpasswd (8) update passwords in batch mode
ckpasswd (8) nnrpd password authenticator
fgetpwent_r (3) get passwd file entry reentrantly
getpwent_r (3) get passwd file entry reentrantly
passwd (1) - update user 's authentication tokens
sslpasswd (1ssl) compute password hashes
passwd (5) password file

passwd . nntp (5) - Passwords for connecting to remote NNTP servers


passwd2des (3) - RFS password encryption

man 1 gedit

man 1 gedit

gedit file1

gedit file1

passwd -l rajan

passwd -l rajan

passwd -u rajan

passwd -u rajan
man 1 passwd
man 1 passwd
man -f passwd

man -f passwd
man -f passwd
man -k zip
man -k zip
man -k zip
man -k boot
man -k boot
man -k boot
man -k ext4
man -k ext4
man -k ext4
man tar
pinfo tar
pinfo tar
pinfo tar

The less command is a Linux terminal pager that shows a file's contents one screen
at a time.
It is useful when dealing with a large text file because it doesn't load the entire
file but
accesses it page by page, resulting in fast loading speeds.

yum list *_doc*

yum list *_doc*


yum list *_doc*
yum list *_doc*
redhat-support-tool
redhat-support-tool
redhat-support-tool

tar -xvJf sosreport.tar.xz

tar -xvJf sosreport.tar.xz

tar -xvJf sosreport.tar.xz


tar -xvJf sosreport.tar.xz
cd /var/tmp
cd /var/tmp
rm -rf sosreport

man -t passwd > passwd.ps


man -t passwd > passwd.ps

man -t passwd > passwd.ps

man -t passwd > passwd.ps

[student@serverx - ]$ man - k postscript viewer

Using m u ltiple words with the - k option finds man pages matching either word; t
hose with
" postscript" or "viewer" in their descriptions.

man -k postscript viewwr

firefox /usr/share/doc

Using firefox, open the system's package documentation directory and b rowse into
the
man - db package subdirectory. View the provided manual(s).
firefox /usr/share/doc

Processes are created with default connections for channels 0, 1, and 2, known as
standard input, standard
output, and standard error. Processes use channels 3 and above to connect to other
files.

Redirecting s tdout suppresses process output from a ppea ring on the terminal. As
seen
in the fol lowing table, redirecting only stdout does not suppress stderr e rror
messages
from displaying on the terminal. The special file /dev/null q u ietly di scards
channel output
redirected to it.

> file redirect stdout to a file.

> file1 redirect stdout to a file


> file1 redirect stdout to a file

» file

redirect
stdout to a file, a ppend � •
to c u rrent file
content

> file1
>> file1 >> file1

>> file1

2>file1 redirect stderr to file1


2>file1 redirect stderr to file1
2>file1 redirect stderr to file1

2>/dev/null --discard stderr error msg by redirecting to /dev/null

2>/dev/null --discard stderr error msg by redirecting to /dev/null


2>/dev/null 2>/dev/null 2>/dev/null 2>/dev/null 2>/dev/null

&>file &>file1 &>file1 &>file1 &>file1 combine stdout and stderr to one file
combine stdout and stderr to one file combine stdout and stderr to one file

&>file1 &>file1

>>file2>&1
>>file2>&1
>>file2>&1 >>file2>&1 >>file2>&1
>>file2>&1 combine stdout and stderr append to current file content

»file2>&1
>>file2>&1

date > /tmp/file1.txt


date > /tmp//file.txt
date > /tmp/file.txt

tail -n 100 /var/log > /tmp/file


tail -n 100 /var/log > /tmp/file
tail -n 100 /var/log > /tmp/file
tail -n 100 / var/log > /tmp/file

cat file file2 file3 file4 > /tmp/allfiles


cat file1 file2 file3 file4 > /tmp/allfiles

cat file1 file2 file3 file4 > /tmp/allfiles


cat file1 file2 file3 file4 > /tmp/allfiles

ls -a /tmp/file1
ls -a /tmp/file1
ls -a /tmp/file1
echo "new line of information" >> /tmp/file1
echo "new line of information" >> /tmp/file1

2>/dev/null 2>/dev/null
&> file1
&> file1
&> file1
&> file1
>>file 2>&1
>>file 2>&1
>>file 2>&1 >>file 2>&1 >>file 2>&1
>>file 2>&1

find /etc -name passwd 2> /tmp/errors


find /etc -name passwd 2> /tmp/errors
find /etc -name passwd 2> /tmp/errors
find /etc -name passwd 2> /tmp/errors
find /etc -name passwd > /tmp/process 2> /tmp/errors
find /etc -name passwd > /tmp/process 2> /tmp/errors

find /etc -name passwd > /tmp/process 2> /dev/null

find /etc -name passwd > /tmp/process 2> /dev/null

find /etc -name passwd &> /tmp/together


find /etc -name passwd &> /tmp/together
find /etc -name passwd &> /tmp/together

find /etc -name passwd >> /tmp/togther 2>&1


find /etc -name passwd >> /tmp/togther 2>&1
find /etc -name passwd >> /tmp/together 2>&1

ls -l /usr/bin | less
ls -l /usr/bin | less
ls -l /usr/bin | less

ls | wc -l > /tmp/file1
ls | wc -l > /tmp/file1

ls -t | head -n 10 > /tmp/file1

The tee command displays or redirects the intermediate result normally suppressed
due to
piping. In the first exa mple, the ls listing is viewed on a terminal while
simultaneously being
stored in a fi le.

>>file1 2>&1
>>file1 2>&1
>>file1 2>&1

&>/dev/null
&>/dev/null

In the shell command window, display today's date with day of the week, month,
date, and year.

[student@se rverx -]$ date +%A", "%B" "%d", "%Y


F riday, February 21, 2014

date +%A", "%B","%d", "%Y


date +%A", "%B", "%d", "%Y

date +%A", "%B", "%d", "%Y


date +%A", "%B", "%d", "%Y

echo "$user file is located at " $(hostname)


echo "$USER file is located at" $(hostname)
echo "$user file is located at " $(hostname)

ls -al > file1.txt


vim file1.txt

V--Enter line-based
visual mode with upper case v.

Enter linebased visual mode with V. Move down using the down arrow key twice to
select the first
three rows. Delete the rows with x.

In this step, enter


visual mode with lower case v, which allows selecting characters on a single line
only.
r. Enter visual mode w ith v.
Use the arrow keys to pos ition the cursor at the l ast cha racter, as shown in the
screens hot.
Delete the selection with x.

enter visual mode with the control sequence Ctrl - v, which a l lows
selecting a block of characters on m u ltiple l i nes.

Use the arrow keys to position the cursor at the first character of the g roup
owner column.
E nter visual mode with Ctrl-v. Use the arrow keys to position the cursor at the
last
character and row of the group owner column, as shown in the screenshot. Delete the
selection with x.

Use the arrow keys to pos ition the cursor at a ny character on the Desktop row. E
nter visual
mode with u pper case v. The fu ll line is sel ected, as shown in the screenshot.
Delete the
selection with x.

cp file1.txt file1$(date +%s).txt

cp file.txt file1$(dte +%s).txt

cat file.txt | mail -s "file1" student

cat file.txt | mail -s "file1" student


cat file.txt | mail -s "file1" student
cat file1.txt | mail -s "file1" student

ps -f | tee -a file.txt

ps -f | tee -a file.txt
ps -f | tee -a file.txt

Every process (running prog ram) on the system runs as a particu lar user. Every fi
le is owned by
a particular user. Access to files and directories a re restricted by user. The
user associated with a
running p rocess determines the files and directories accessible to t hat p rocess.

id--to show info abt the current logged in user.


id --to show info abt the current logged in user.

ps a--show all process


ps au---show all process and their user
ps au

The format of /etc/passwd follows (seven colon-separated


fie lds):

username : password : UID: GID: GECOS: :home/dir : shell

username is a mapping of a UID to a name for the benefit of human users.

0 password is where, historica lly, passwords were kept in an encrypted format.


Today, they a re
stored in a sepa rate file ca l led /etc/shadow.
UID is a user ID, a number that identifies the user at the most fundamental level
GID is the user's primary group ID number. Groups will be discussed in a moment.
GECOS field is arbitrary text, which usually incl udes the user's rea l name
/home/dir is the location of the user's personal data and configuration files.
shell is a prog ram that runs as the user logs in. For a regular user, this is
norma lly the
prog ram that provides the user's command line prompt.

Norma lly, the primary g roup of a newly created user is a newly created g roup
with the same
name as the user. The user is the only member of this User Private Group (U PG).

Most operating systems have some sort of superuser, a user that has all power over
the system.
This user in Red Hat Enterprise Linux is the root user. This user has the power to
override
normal privileges on the file system, and is used to manage and administer the
system.

The main d istinction is su - sets up the shell environment as if this were a


clean login as that user, while su just sta rts a shell as that user with the cu
rrent environment
setti ngs.
In most cases, admin istrators wa nt to run su - to get the user's normal settings.

The common solution previously


d iscussed is to allow sta ndard users to temporarily "become root" using the su
command. The
d isadvantage is that while acting as root, all the privileges (a nd responsibil
ities) of root a re
g ranted. Not only ca n the user restart the web server, but they can a l so remove
the entire /etc
d irectory. Additional ly, all users req uiring superuser privilege in this manner
must know the root
password.

The sudo command allows a user to be permitted to run a command as root, or as


another user,
based on settings in the /etc/sudoers file. Unl ike ot her too ls such as su, sudo
requires users
to enter their own password for authentication, not the password of the account
they a retrying
to access.
echo $home

echo $path
echo $home
echo $path

tail -5 /var/log/messages
tail -5 /var/log/messages
sudo tail -5 /var/log/messages
cp /etc/motd /etc/motld
cp /etc/motd /etc/motld

echo "welcom" >> /etc/mota1


userdel username removes user from /etc/passwd but at user's home directory no
intact

userdel username

userdel -r username removes user and it's home directory

userdel -r username userdel -r username

useradd prince
useradd prince

ls -l /home

find / -nouser -o -nogroup 2> /dev/null


find / -nouser -o -nogroup 2> /dev/null

passwd student
UID 0 is always assigned to the superuser accou nt, root.
UID 1 -200 is a ra nge of "system users" assigned statica l ly to system processes
by Red Hat.

UID 201 -999 is a ra nge of "system users" used by system processes that do not own
files on
the file system. They a re typica lly assigned dynamically from the available pool
when the
softwa re that needs them is insta l led.

UID 1000+ is the ra nge available for assignment to regular users

sudo groupadd -g 5000 raja


sudo groupadd -g 5000 rajan

The -r option wi ll create a system g roup using a GID from the ra nge of va lid
system GID
numbe rs l isted in the /etc/login.defs file.

sudo groupadd -r appusers

sudo groupadd -r appusers

The groupmod command is used to cha nge a group name to a GID mapping. The -n
option is
used to specify a new name.
sudo groupmod -n javapp appusers
sudo groupadd -n javaapp appusers

The -g option is used to specify a new GID

sudo groupmod -g 6000 ateam


sudo groupmod -g 6000 ateam

sudo groupdel javapp


sudo groupdel javaapp

The membership of a group is controlled with user management. Change a user's


primary
group with usermod -g groupname.

sudo usermod -g javapp student


sudo usermod -g javaapp student

Add a user to a supplementa ry g roup with use rmod - aG groupname username.

Add the juliet user to the shakespeare group as a supplementary g roup.

sudo usermod -G shakespeare juliet


sudo usermod -G shakespeare juliet
There a re three pieces of i nformation stored in a modern password hash:

$1$gCjLa2/Z$6Pu0EK0AzfCjxjv2hoLOB/

1. 1: The hashing algorithm. The number 1 indicates an MD5 hash. The number 6
appears when
a SHA-512 hash is used.
2. gCjLa2/Z: The salt used to encrypt the hash. This is originally chosen at ra
ndom. The
salt and the unencrypted password a re combined and encrypted to c reate the
encrypted
password hash. The use of a salt prevents two users with the same password from
having
identica l entries in the /etc/shadow file.
3. 6Pu0EK0AzfCj xj v2hoLOB/: The encrypted hash.
When a user tries to log in, the system looks up the entry for the user in
/etc/shadow,
combines the salt for the user with the unencrypted password that was typed in, and
encrypts
them using the hashing algorithm specified. If the res u lt matches the encrypted
hash, the user
typed in the right password. If the res u lt doesn't match the encrypted hash, the
user typed in the
wrong password and the login attempt fa i l s. This method a l lows the system to
determine if the
user typed in the correct password without storing that password in a form usable
for logging in.

chage -d 0 username will force a password u pdate on next login.


chage -l username will l i st a username's cu rrent settings.
chage -E YYYY- MM-DD wi ll expire an account on a specific day.

chage -d 0
chage -d 0
chage -d 0
chage -l username
chage -l username
chage -E 2022-07-24
chage -E 2022-07-24

The date command can be used to ca lculate a date in the future.

date -d "+45 days"


date -d "+45 days"
date -d "+45 days"

sudo usermod -L rajan


sudo usermod -L rajan

sudo usermod -L -e 1 rajan

You might also like