Lec 09 - Linux Basic Commands
Lec 09 - Linux Basic Commands
Today’s Agenda
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:
Shell Prompt
Now that you have logged in, you will see a shell prompt.
[root@localhost /root]#
3
LINUX BASED NETWORKS
[Ctrl]-[D]
Or just type logout at the prompt:
System Shutdown
The Need To Shutdown
4
LINUX BASED NETWORKS
#shutdown -h now
5
LINUX BASED NETWORKS
halt Command
#halt
6
LINUX BASED NETWORKS
WARNING!
7
LINUX BASED NETWORKS
[root@localhost /root]#ls -a
[root@localhost /root]#ls -l
Linux Basic Commands Class Meeting # Slide : 15
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
pico -- joe
9
LINUX BASED NETWORKS
EXIT
^KX Save and Exit
^C Abort
^KZ Shell
FILE
^KE Edit
^KR Insert
^KD Save
10
LINUX BASED NETWORKS
SEARCH
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
11
LINUX BASED NETWORKS
BLOCK
^KB Begin
^KK End
^KM Move
^KC Copy
^KW File
^KY Delete
^K/ Filter
SPELL
^[N Word
^[L File
12
LINUX BASED NETWORKS
# man mv
# man rm
# man mkdir
# man rmdir
# man passwd
# man man
Linux Basic Commands Class Meeting # Slide : 25
You can also type info <command> for help on many basic
commands.
Some packages will however not have info pages.
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 ..
# ls | more
14
LINUX BASED NETWORKS
#ls | less
#mkdir java
#mkdir –p java/javaservers/apachi
15
LINUX BASED NETWORKS
Directories [pwd]
#pwd
Directories [rmdir]
rmdir—Remove empty directories
#rmdir –p dir1/dir2/dir3
16
LINUX BASED NETWORKS
Directories [rm]
rm—Remove files
# cp myfile newfile
# cp /home/jack/myfile /home/jack/newfile
17
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.
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
19
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
20
LINUX BASED NETWORKS
whoami
Prints out your login name.
[root@localhost /root]#whoami
21
LINUX BASED NETWORKS
date
Prints out the current date and time.
[root@localhost /root]#date
[root@localhost /root]# df -h
22
LINUX BASED NETWORKS
uname
Prints out the name of the Unix operating system you
are currently using.
23
LINUX BASED NETWORKS
wc
wc [-c] [-w] [-l] <filename>
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
Using Redirection
25
LINUX BASED NETWORKS
You can even use cat to read the file, by typing at the prompt.
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.
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 ?
27
LINUX BASED NETWORKS
Type
#cat sneakers.txt
28
LINUX BASED NETWORKS
Type
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.
file <filename>
This command prints out the type of data contained in a file.
# file portrate.jpg
30
LINUX BASED NETWORKS
#stat /tmp
which command
To locate the exact path of a program, you can use the which
command
Type
#which httpd
31
LINUX BASED NETWORKS
cmp
Syntax:
cmp
To demonstrate, filel.txt contains:
this is file 1
the quick brown fox jumps over the lazy dog.
32
LINUX BASED NETWORKS
Demonstration of cmp
head
Syntax:
head [-count | -n number] filename
33
LINUX BASED NETWORKS
tail
locate
34