0% found this document useful (0 votes)
10 views

Lec 09 - Linux Basic Commands

Information Secuirty Notes

Uploaded by

vabepi7064
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Lec 09 - Linux Basic Commands

Information Secuirty Notes

Uploaded by

vabepi7064
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

LINUX BASED NETWORKS

Linux Based Networks

Punjab University Gujranwala Campus

Linux Basic Commands Class Meeting # Slide : 1

LINUX BASED NETWORKS

Today’s Agenda

Linux Basic Commands Class Meeting # Slide : 2

1
LINUX BASED NETWORKS

Logging In As Root
Regardless of whether you’ve chosen a graphical or console
login screen, you’ll have to supply a login account name and
the password associated with that account.
From a console screen, for example, you’ll see something
like:

Red Hat Linux release 8.0


Kernel 2. xx on an i686
localhost login:root
Password:
yourrootpassword
Linux Basic Commands Class Meeting # Slide : 5

LINUX BASED NETWORKS

Shell Prompt

Now that you have logged in, you will see a shell prompt.

[root@localhost /root]#

This is where you will spend most of your time as system


administrator.

Linux Basic Commands Class Meeting # Slide : 6

3
LINUX BASED NETWORKS

Logging Out of Root

Just type exit at the prompt, as in:

[root@localhost /root]# logout

or by using the key combination of

[Ctrl]-[D]
Or just type logout at the prompt:

[root@localhost /root]# exit

Linux Basic Commands Class Meeting # Slide : 7

LINUX BASED NETWORKS

System Shutdown
The Need To Shutdown

The Linux operating system keeps the more current versions


of the "table of contents", or inode table, in memory to
speed disk access. If the system is not shutdown properly
the inode table stored in memory is not written to the disk so
the table of contents will not be correct and files will be lost.

Never, under any circumstances, shutdown your


Linux system simply by pressing the power button

Linux Basic Commands Class Meeting # Slide : 8

4
LINUX BASED NETWORKS

The Three Finger Salute

Shutting down in this matter will forcibly log off any


other users who will lose whatever their working on

Linux Basic Commands Class Meeting # Slide : 9

LINUX BASED NETWORKS

The shutdown Command

#shutdown -h now

The shutdown command is the best option for shutting


down a system with users currently logged on.

Linux Basic Commands Class Meeting # Slide : 10

5
LINUX BASED NETWORKS

halt Command

#halt

Since they are based on the UNIX operating system, some


versions of Linux allow you to use the commands "fasthalt"
or "haltsys" to immediately bring the system down in a safe
and orderly fashion.

Linux Basic Commands Class Meeting # Slide : 11

LINUX BASED NETWORKS

Rebooting The System

The reboot Command

The "shutdown -r" Command for rebooting the system

Linux Basic Commands Class Meeting # Slide : 12

6
LINUX BASED NETWORKS

WARNING!

Make certain that you’ve saved your work before


halting or restarting your system from the shell
prompt. Running applications will be closed and you
won’t have the option of saving your work or your
session.

Linux Basic Commands Class Meeting # Slide : 13

LINUX BASED NETWORKS

Changing your Password

Exercise to change your password?


1. Type the command passwd.
2. You will then be asked for a new password.
3. And then asked to confirm that password.
4. Then you will arrive back in the shell.
5. The password you have chosen will take effect
immediately,
6. Replacing the previous password that you used to log in.

Linux Basic Commands Class Meeting # Slide : 14

7
LINUX BASED NETWORKS

Listing Files (ls)

¾ Type in the command.


[root@localhost /root]#ls
If there were files, you would see their names listed in
columns with no indication of what they are for.

¾ To see a hidden file you have to use the command

[root@localhost /root]#ls -a

¾ Another variant ls -l which lists the contents in long format.

[root@localhost /root]#ls -l
Linux Basic Commands Class Meeting # Slide : 15

LINUX BASED NETWORKS

Output of example [ls –l]


Information Type ls Output
File access permissions -rw-rw-rw-
Number of links 1
User(file owner) root
Group root
File Size (in bytes) 512
Last modification date Feb 6
Last modification time 21:11
Filename myfile

Linux Basic Commands Class Meeting # Slide : 16

8
LINUX BASED NETWORKS

ls (cont.)
They can be strung together in any way that is convenient for
example ls -a -l, ls -l -a or ls -al | either of these will list all files
in long format.

[root@localhost /root]#ls –a -l

[root@localhost /root]#ls –l -a

[root@localhost /root]#ls -al

Linux Basic Commands Class Meeting # Slide : 17

LINUX BASED NETWORKS

pico -- joe

Simple Text Editor

Linux Basic Commands Class Meeting # Slide : 18

9
LINUX BASED NETWORKS

joe Text Editor

The ^ represents the control Key

Use ^KH to get help then esc and , and . to


back and forward respectively.

Linux Basic Commands Class Meeting # Slide : 19

LINUX BASED NETWORKS

EXIT
^KX Save and Exit
^C Abort
^KZ Shell

FILE
^KE Edit
^KR Insert
^KD Save

Linux Basic Commands Class Meeting # Slide : 20

10
LINUX BASED NETWORKS

SEARCH

^KF find Text ^L Find Next

Linux Basic Commands Class Meeting # Slide : 21

LINUX BASED NETWORKS

GO TO

^U Prev. Screen
^V Next Screen
^A Beginning of line
^E End of Line
^KU Top of file
^KV End of File
^KL To Line Number

Linux Basic Commands Class Meeting # Slide : 22

11
LINUX BASED NETWORKS

BLOCK
^KB Begin
^KK End
^KM Move
^KC Copy
^KW File
^KY Delete
^K/ Filter

Linux Basic Commands Class Meeting # Slide : 23

LINUX BASED NETWORKS

SPELL

^[N Word
^[L File

Linux Basic Commands Class Meeting # Slide : 24

12
LINUX BASED NETWORKS

System manual pages


You should now use the man command to look up the manual
pages for all the commands that you will learn. Type
# man cp

# man mv

# man rm

# man mkdir

# man rmdir

# man passwd

# man man
Linux Basic Commands Class Meeting # Slide : 25

LINUX BASED NETWORKS

System info pages

You can also type info <command> for help on many basic
commands.
Some packages will however not have info pages.

Linux Basic Commands Class Meeting # Slide : 26

13
LINUX BASED NETWORKS

Manipulating directories

cd — change directories
The cd command is used to take you to different directories.

#cd directory1/directory2

And similarly you can get back to where you were with

#cd ..

By simply typing cd you get back to your home directory no


matter where ever you are
#cd
Linux Basic Commands Class Meeting # Slide : 27

LINUX BASED NETWORKS

The "more" Command

# ls | more

Linux Basic Commands Class Meeting # Slide : 28

14
LINUX BASED NETWORKS

The "less" Command

#ls | less

Linux Basic Commands Class Meeting # Slide : 29

LINUX BASED NETWORKS

Make directories [mkdir]

#mkdir java

#mkdir –p java/javaservers/apachi

Linux Basic Commands Class Meeting # Slide : 30

15
LINUX BASED NETWORKS

Directories [pwd]

The command pwd stands for present working directory


(also called the current directory) and is used to tell you
what directory you are currently in.

#pwd

Linux Basic Commands Class Meeting # Slide : 31

LINUX BASED NETWORKS

Directories [rmdir]
rmdir—Remove empty directories

#rmdir –p dir1/dir2/dir3

Linux Basic Commands Class Meeting # Slide : 32

16
LINUX BASED NETWORKS

Directories [rm]
rm—Remove files

#rm –rf filename

#rm –rf directoryname

Both commands are dangerous to use as a root user

Linux Basic Commands Class Meeting # Slide : 33

LINUX BASED NETWORKS

Relative vs. absolute pathnames


A command that requires a file name can be given the file in
two ways.
If you are in the same directory as the file

# cp myfile newfile

Otherwise, you can enter the full path name, like

# cp /home/jack/myfile /home/jack/newfile

Linux Basic Commands Class Meeting # Slide : 34

17
LINUX BASED NETWORKS

Relative and Absolute paths


For example I as root user want to copy a file from /etc
directory to our home directory

#cp /etc/passwd ./profile (Absolute path)

#cp ../etc/passwd . (Relative path)

Linux Basic Commands Class Meeting # Slide : 35

LINUX BASED NETWORKS

Directories [cp]
SYNOPSIS
cp [options] source dest

OPTIONS
–P, —parents the command cp —parents a/b/c existing_dir
copies the file a/b/c to existing_dir/a/b/c,
creating any missing intermediate directories.

–p, —preserve Preserve the original files’ owner, group,


permissions, and timestamps.

-r Copy directories recursively, copying all non


directories as if they were regular files.
Linux Basic Commands Class Meeting # Slide : 36

18
LINUX BASED NETWORKS

Basics of Wildcards
Wildcards Meaning
* Match any sequence of one or more characters.
? Match any single character.
[] Match one of the enclosed characters or range.

Example Meaning
Jo* Files that begin with Jo
Jo*y Files that begin Jo and end in y
UL*l*s.c Files that begin with UL, contain an l and end in
s.c
?.h All files that begin with a single character
followed by .h

Linux Basic Commands Class Meeting # Slide : 37

LINUX BASED NETWORKS

Basics of Wildcards (cont…)


Example Meaning

Doc[0-9].txt Files with the names Doc0.txt,Doc1.txt…..,


Doc9.txt.
Doc0[A-Z].txt Files with the names Doc0A.txt,Doc0B.txt,
Doc0Z.txt.

ls [A-M]* list the files that begin with A through M


[a-dJW-Y]* matches all files beginning with a, b, c, d, J, W,
X or Y.
*[a-d]id matches all files ending with aid, bid, cid or did.

Linux Basic Commands Class Meeting # Slide : 38

19
LINUX BASED NETWORKS

Some useful commands [clear]

The clear command clears your terminal and returns the


command line prompt to the top of the screen.

[root@localhost /root]# clear

Linux Basic Commands Class Meeting # Slide : 39

LINUX BASED NETWORKS

bc
A calculator program that handles arbitrary precision (very
large) numbers. It is useful for doing any kind of calculation
on the command line. It use is left as an exercise.

[root@localhost /root]# bc

Linux Basic Commands Class Meeting # Slide : 40

20
LINUX BASED NETWORKS

cal [[0-12] 1--9999]

Prints out a nicely formatted calendar of the current month, or


a specified month, or a specified whole year.

[root@localhost /root]# cal 1947

Linux Basic Commands Class Meeting # Slide : 41

LINUX BASED NETWORKS

whoami
Prints out your login name.

[root@localhost /root]#whoami

Linux Basic Commands Class Meeting # Slide : 42

21
LINUX BASED NETWORKS

date
Prints out the current date and time.

[root@localhost /root]#date

Linux Basic Commands Class Meeting # Slide : 43

LINUX BASED NETWORKS

df Stands for disk free


This tells you how much free space is left on your system.

[root@localhost /root]# df -h

Linux Basic Commands Class Meeting # Slide : 44

22
LINUX BASED NETWORKS

free Prints out available free memory.


You will notice two listings: swap space and physical
memory.

[root@localhost /root]# free

Linux Basic Commands Class Meeting # Slide : 45

LINUX BASED NETWORKS

uname
Prints out the name of the Unix operating system you
are currently using.

[root@localhost /root]# uname -a

Linux Basic Commands Class Meeting # Slide : 46

23
LINUX BASED NETWORKS

wc
wc [-c] [-w] [-l] <filename>

Counts the number characters/bytes (with -c), words


(with -w) or lines (with-l) in a file.

[root@localhost /root]# wc –c /etc/passwd

Linux Basic Commands Class Meeting # Slide : 47

LINUX BASED NETWORKS

Using cat command to create files


Start cat to see what this means. At the shell prompt, type:
[newuser@localhost /newuser]# cat
The cursor moves to a blank line. Now, in that blank
line, let’s type:

stop by sneaker store


and press the [Enter] key. Your screen will look like:

[newuser@localhost /newuser]# cat


stop by sneaker store
stop by sneaker store

To quit cat now, press the [Ctrl] and [D] keys at the
same time.
Linux Basic Commands Class Meeting # Slide : 48

24
LINUX BASED NETWORKS

Cat
Standard Input & Standard Output

But cat has just demonstrated the definition of standard input


and standard output.
Your input was read from the keyboard (standard input), and
that input was then directed to your terminal (standard
output).

Linux Basic Commands Class Meeting # Slide : 49

LINUX BASED NETWORKS

Using Redirection

Redirection means causing the shell to change what it


considers standard input or where the standard output is
going.
To redirect standard output, we’ll use the > symbol. Placing
> after the cat command

Linux Basic Commands Class Meeting # Slide : 50

25
LINUX BASED NETWORKS

Let’s try Redirection.


[newuser@localhost /newuser]# cat >sneakers.txt
buy some sneakers
then go to the coffee shop
Then buy some coffee

Now press [Enter] to go to an empty line, and use the


[Ctrl]-[D] keys to quit cat.

You can even use cat to read the file, by typing at the prompt.

[newuser@localhost /newuser]#cat sneakers.txt

Linux Basic Commands Class Meeting # Slide : 51

LINUX BASED NETWORKS

Caution

You can easily overwrite an existing file! Make sure the name
of the file you’re creating doesn’t match the name of a pre-
existing file, unless you want to replace it.

Linux Basic Commands Class Meeting # Slide : 52

26
LINUX BASED NETWORKS

Exercise
Create another file named home.txt having the following
contents
bring the coffee home
take off shoes
put on sneakers
make some coffee
relax!
Check the file using cat command ?

Linux Basic Commands Class Meeting # Slide : 53

LINUX BASED NETWORKS

Joining Files and Redirecting Output

[user@localhost /user]# cat sneakers.txt home.txt > myfile

Now it’s time to check our handiwork. Type:

[newuser@localhost /newuser]# cat myfile

Linux Basic Commands Class Meeting # Slide : 54

27
LINUX BASED NETWORKS

Appending Standard Output

when you use >>, you’re adding information, rather than


replacing it.

Type

#cat home.txt >> sneakers.txt

Now let’s check the file by typing:

#cat sneakers.txt

Linux Basic Commands Class Meeting # Slide : 55

LINUX BASED NETWORKS

Redirecting Standard Input


Just type:

#cat < sneakers.txt

Linux Basic Commands Class Meeting # Slide : 56

28
LINUX BASED NETWORKS

Using Output Redirection with Other commands

Type

$ date > date.dat


$ cat date.dat
$ ls > list.dat
$ cat list.dat

Now combine these two files in file name


combo
Linux Basic Commands Class Meeting # Slide : 57

LINUX BASED NETWORKS

The tee Utility


You can use the tee utility in a pipe to send the output of a
command to a file while also sending the output to standard
output.
The utility takes a single input and sends the output in two
directions.

$ ls-l | tee who.out

Linux Basic Commands Class Meeting # Slide : 58

29
LINUX BASED NETWORKS

touch command
This command updates the timestamp of a file or directory. If
the named file does not exists, it will be created empty.

# touch file or directory

Linux Basic Commands Class Meeting # Slide : 59

LINUX BASED NETWORKS

Determining file type

file <filename>
This command prints out the type of data contained in a file.

# file portrate.jpg

will tell you that portrate.jpg is a JPEG image data,

Linux Basic Commands Class Meeting # Slide : 60

30
LINUX BASED NETWORKS

Access statistics of a file or directory


You can use the stat program to get statistics on a file or
directory. For example:

#stat /tmp

Linux Basic Commands Class Meeting # Slide : 61

LINUX BASED NETWORKS

which command

To locate the exact path of a program, you can use the which
command
Type

#which httpd

Linux Basic Commands Class Meeting # Slide : 62

31
LINUX BASED NETWORKS

cmp
Syntax:

cmp [-Is] file1 file2

This command will compare the contents of two files. If there


are no differences within the two files, cmp by default will be
silent.

Linux Basic Commands Class Meeting # Slide : 63

LINUX BASED NETWORKS

cmp
To demonstrate, filel.txt contains:
this is file 1
the quick brown fox jumps over the lazy dog.

and file2.txt contains:


this is file 2
the quick brown fox jumps over the lazy dog.

Linux Basic Commands Class Meeting # Slide : 64

32
LINUX BASED NETWORKS

Demonstration of cmp

[root@localhost /root]# cmp file1.txt file2.txt


file1.txt file2.txt differ: char 14, line 1

The results of cmp correctly identify character 14, line 1 as the


unequal character between the two files.

Linux Basic Commands Class Meeting # Slide : 65

LINUX BASED NETWORKS

head
Syntax:
head [-count | -n number] filename

This command will display the first few lines of a file. By


default, the first 10 lines of a file are displayed.
However, you could use the preceding options to specify a
different number of lines.

[root@localhost /root]# head -2 doc.txt


# Outline of future projects
ff Last modified: 02/02/99

Linux Basic Commands Class Meeting # Slide : 66

33
LINUX BASED NETWORKS

tail

[root@localhost /root]# tail -50 doc.txt

[root@localhost /root]# tail -r doc.txt

Linux Basic Commands Class Meeting # Slide : 67

LINUX BASED NETWORKS

locate

An alternative command is locate <filename>. This searches through


a previously created database of all the files on the system, and hence
finds files instantaneously.
Its counterpart updatedb is used to update the database of files used
by locate. On some systems updatedb runs automatically every day at
04h00.

Linux Basic Commands Class Meeting # Slide : 68

34

You might also like