IT403 Chp1 Shell
IT403 Chp1 Shell
1
2
What is ‘Shell’ {
3
4 [ The Linux command line
5
6
interpreter]
7 < The most basic way to interact with the
8 system. >
9
10 < It’s a program that takes commands from the
11 keyboard and gives them to the operating system
12 to perform. >
13
14 }
Introduction to Linux
IT 403 - Global University Spring 2023
1 What is ‘Shell’ {
2
3
4 <In the old days, it was the only user
5 interface available on a Unix-like system such
6 as Linux. >
7
8
9 <Nowadays, we have graphical user interfaces (GUIs)
10 in addition to command line interfaces (CLIs) such
11 as the shell. >
12
13
14
}
Introduction to Linux
IT 403 - Global University Spring 2023
1 What is ‘Shell’ {
2
<Even though the shell is a command line interface,
3
4
the mouse is still handy. Besides using the mouse
5
to scroll the contents of the terminal window, we
6 can can use it to copy text. >
7
8
9 The first ever computer
10 mouse was made in 1964,
11 but wasn't opened to
12 the public until 1968.
13
https://www.sutori.com/en/story/history-of-the-
14
} computer-mouse--2KWUavjKLozs9P8VsV8znyoQ
Introduction to Linux
IT 403 - Global University Spring 2023
1
2
What is ‘Shell’;
Functionality:
3 ∗ Execute other programs.
4 ∗ Manage files.
∗ Manage processes.
5
Every Linux system has at least one shell program.
6
7 Well-known shells:
8 ○ V6 / Thomson Shell (1971) - Unix - No scripting
9 ○ V7 / sh (Stephen Bourne 1977) -Introduced Scripting - Still Used
○ Tcsh and Csh
10 ○ Ksh (Korn shell)
11 ○ Zsh Shell
○ Bash (Bourne Again Shell)
12
13
The command ‘echo $0’ displays the name of the shell you are working with.
14
Introduction to Linux
IT 403 - Global University Spring 2023
1
2
History of ‘Shell’;
3
4
5
6
7
8
9
10
11
12
13
14
https://developer.ibm.com/tutorials/l-linux-shells/
Introduction to Linux
IT 403 - Global University Spring 2023
1
2
Power of Shells; {
3
4 ‘The shell is also a programming language of its
own with complete programming language constructs
5 such as conditional execution, loops, variables,
6 functions and many more.’
7
8 <p That is why the Unix/GNU Linux shell is
9 more powerful compared to the Windows shell. >
10
11 </p>
12
13
14 }
Introduction to Linux
IT 403 - Global University Spring 2023
1
2
Power of Shells; {
3
4
5
6
7
8
9
10
11
12
13
14 }
Introduction to Linux
IT 403 - Global University Spring 2023
1
2
Power of Shells; {
3
4
5 // Makes 10 files : files_1.txt -> files_10.txt
6 touch file_{1..10}.txt
7
8
9
10 You can make scripts and have the header as :
11 #!/bin/bash
12
And then you can run them ./script_name
13
14 }
Introduction to Linux
IT 403 - Global University Spring 2023
1
2
Power of Shells; {
3
4
5
6
7
8
Guess the number !
9
10 // file available in Google Classroom
11
12
13
14 }
Introduction to Linux
IT 403 - Global University Spring 2023
1
2 Starting a Shell {
3
4
< Three methods are commonly used for starting a shell: >
5 Terminal
6 < In a GUI window >
7
8
9
Text-Mode Console
< Linux supports virtual terminals >
10
11
12
Remotely
13 < ssh on linux or Putty/PowerShell on Windows >
14
}
Introduction to Linux
IT 403 - Global University Spring 2023
1 Launching A ‘TERMINAL’
2
3
{
4 < The details of how to launch a
terminal program differ from one
5
desktop environment to another. >
6
7 < The ‘$’ character preceding the
cursor is called the shell prompt.
8
It tells you that the system is
9 ready and waiting for input >
10
11 < On some systems, the default shell
12 prompt also includes the name of the
current directory. >
13
14 }
Introduction to Linux
IT 403 - Global University Spring 2023
1
2
Logging In Remotely; {
3
4
SSH
< Remote logins should be enabled by running
5 a server program such as the Secure Shell
6 (SSH) >
7 Program
8
< You can use a client program, such as ssh
9 on linux or putty on Windows >
10
11 Other
12 < Other text-mode remote-login programs, such
as telnet and rlogin, exists (Older Protocols
13
/ Minimal Security >
14 }
Introduction to Linux
Some ‘COMMAND LINE’
{
# TIPS
}
IT 403 - Global University Spring 2023
1
2
Tips < /1 > {
3 < Command completion: Press TAB on the input line and the
shell will complete the word. Completion works on program,
4 file, or folder names. Displays possible completions if
5 multiple options.>
6
7
}
8
9 Tips < /2 > {
10
11 < Repeating the last command : Type the UP arrow to put
the last command you typed back on the input line.>
12
13
14 }
Introduction to Linux
IT 403 - Global University Spring 2023
1
2
Tips < /3 > {
3
< Reverse-incremental search: Ctrl-r, to search, in
4 reverse, through your command history.>
5
6
7
}
8
9 Tips < /4 > {
10
< Running a list of commands: Type each command in the
11 order you want them to run, separating each command
12 from the next with a semicolon (‘;’) >
13
14 }
Introduction to Linux
IT 403 - Global University Spring 2023
1
2
Tips < /5 > {
3
4 < !! : Re-Run the last command>
5
6
7
}
8
9 Tips < /6 > {
10
< Use wildcard characters : Wildcard characters such as *
11
and ? can be used to match multiple files or characters in
12 a pattern. For example, the command ls *.txt will list all
13 files with the .txt extension in a directory.>
14 }
Introduction to Linux
IT 403 - Global University Spring 2023
1
2
Tips < /7 > {
3 < History : The command line keeps a history of all the
4 commands you have typed. (!n to run a specific one /
5 HISTSIZE)>
6
7
}
8
9 Tips < /8 > {
10
11 < Use aliases: Aliases allow you to make custom shortcuts
12 for frequently used commands. For example, you can make
an alias for the ls command that includes the -l option ,
13
like this: alias ls='ls -l'.>
14 }
Introduction to Linux
IT 403 - Global University Spring 2023
1
2
3
Shell Commands {
4
5 [A command can be:]
6
7
< a built-in shell command; >
8
9 < an executable shell file known as a shell script; >
10
11 < or a source compiled, object code file. >
12
13
< Shell commands are CASE SENSITIVE >
14 }
Introduction to Linux
IT 403 - Global University Spring 2023
1
2
Commands have ‘3 Parts’ {
3
4 01 command
5
< cal >
6
7
8 02 options
9 < cal -j >
10
11
12
03 parameters
13 < cal -j 3 2023 >
14 }
Introduction to Linux
IT 403 - Global University Spring 2023
1
2
Let’s RUN some ‘Commands’ {
3
4 01 pwd
5
< Print working directory >
6
7
8 02 cd
9 < Change directory > (./ , ~ , ../ )
10
11
12
03 ls
13 < List files and directories >
14 }
Introduction to Linux
IT 403 - Global University Spring 2023
1
2
Basic Shell ‘ls’;
The Linux ls command is one of the basic commands and it is used to
3 list information about files and sub-directories of the working
directory (by default).Files with * mean that they are executable.
4
5 ∗ ls -l ->> long listing format
6 ∗ ls -r ->> reverse alphabet order
∗ ls -p ->> file type -> directories -> /
7 ∗ ls -s ->> by file size
8 ∗ ls -lh ->> human readable format -> instead of bytes
∗ ls -t ->> by time /date -> the last one ls -t | head -1
9
∗ ls -ltr ->> long listing by time / reversed
10 ∗ ls -m ->> list separated by comma
11 ∗ ls -a ->> display hidden files
∗ ls -1 ->> display 1 file / line
12 ∗ ls -R ->> recursive , repeat the command for all subfolders
13 ∗ ls path will work also -> ls ~ home
14 ∗ ls ->> l alone will work also
Introduction to Linux
IT 403 - Global University Spring 2023
1
2
Basic Shell ‘Commands’ {
3 cat / tac mkdir
4 reads data from file and
5 gives their content as Make a new directory
6 output. (tac -> reverse)
7 more less
8 Show file(s) contents and
View file(s) content
switch between files (useful
9 one screen at a time
for large files) :n/:p
10
11 Head (-n x) tail
12 Used to print the first N Used to print the last N-1
13 lines of a file (default 10) lines of a file
14 }
Introduction to Linux
IT 403 - Global University Spring 2023
1
2
Basic Shell ‘more/less’ {
3 The less command is a Linux terminal that shows a file's
4 contents one screen at a time. It is useful when dealing
5 with a large text file because it doesn't load the entire
6 file but accesses it page by page, resulting in fast
7 loading speeds.
8
9 :n ->> next file && :p <<- previous file
10
11
more and less have the option to view multiple files at
12
once. more allows us to view them as a single file
13
separated by lines, and less allows us to switch between
14
them. Also there is a difference between content display
}
Introduction to Linux
IT 403 - Global University Spring 2023
1
2
Basic Shell ‘cat/tac’ {
3
4 cat command : Concatenate, or cat, is one of the most
5 frequently used Linux commands. It lists, combines, and
6 writes file content.
7
8 ● cat filename ->> displays content of filename
9 ● tac filename ->> displays content in reverse order.
10
11 Combining Files:
12
13 ● cat file1 file2 > file3 ->> merges file1/file2 into file3
14
}
Introduction to Linux
IT 403 - Global University Spring 2023
1
2
Basic Shell ‘mkdir’ {
3 mkdir command accepts many options, such as:
4
5 ➔ mkdir -p IT403/2023/hw will make the new “IT403”
6
directory with the subfolders/2023/hw
7
8 ➔ mkdir -pvm777 xxx/yyy/zzz (-m sets the file
9 permissions) to make a directory with full read, write,
10
and execute permissions.
11
12 ➔ -v prints a message for each new directory.
13
14
}
Introduction to Linux
IT 403 - Global University Spring 2023
1
2
Basic Shell ‘head/tail’ {
3
head command is used to read the file from the beginning and the
tail command is used to read the file from the ending
4
(by default it’s 10 lines and it accepts multiple files)
5
6 ➔ -n x : prints the first x lines
7
8 ➔ -n -x : head : omits x last lines; tail : no changes when using the -
9 ➔ -c x : prints the first x characters
10
➔ -q : prints the content without mentioning filename
11
12 ➔ -v : prints the filename at the top before the content
13 ➔ tail -f : used to monitor the log entries written by running programs
14
Introduction to Linux
IT 403 - Global University Spring 2023
1
2
Basic Shell ‘Commands’ 3 {
3
4 clear df
5
6 <Clear the CLI > < available disk space >
7
8
9
10 tar locate
11
< locate a file in
12 < file compression #>
Linux System >
13
14 }
Introduction to Linux
IT 403 - Global University Spring 2023
1
2
Basic Shell ‘locate’ {
3 Find files by name. It reads one or more databases made by
4 updatedb and writes file names matching at least one of the
5 PATTERNs to the screen
6
7 ➔ Usage : locate filename
8 ➔ -c : write the number of matching entries only
9
10 ➔ -i : ignore case matching
11 ➔ -lx : limit the results to x
12
➔ -b file : searches for files and directories whose names match the
13
14 search pattern only at the base of their file path
}
Introduction to Linux
IT 403 - Global University Spring 2023
1
2
Basic Shell ‘tar’ {
3 The tar command on Linux is often used to make archive files.
4 The tar command can extract the resulting archives, too.
5
6 ➔ Usage : tar -czvf name-of-archive.tar.gz
7
/path/to/directory-or-file
8
9 ➔ -c: make an archive.
10 ➔ -z: Compress the archive with gzip.
11
➔ -v: Display progress in the terminal also known as
12
13 “verbose” mode. The v is optional but it’s helpful.
14 ➔ -f: Allows you to specify the filename of the archive.
}
Introduction to Linux
IT 403 - Global University Spring 2023
1
2
Basic Shell ‘tar’ {
3
4 The tar command accepts multiple files / directories
5
6 ➔ tar -czvf archive.tar.gz file1 folder1/ file2 …
7
8 Exclude Directories and Files
9
10
11 ➔ --exclude=/folder ; --exclude=file
12 ➔ tar -czvf archive.tar.gz /home/ubuntu --exclude=*.mp4
13
14
}
Introduction to Linux
IT 403 - Global University Spring 2023
1
2
Basic Shell ‘bzip2 compression’ {
3
4 gzip compression is most frequently used to make .tar.gz ,
5 tar also supports bzip2 compression. This allows you to make
6 bzip2-compressed files, often named .tar.bz2 files.
7
8 To do so, just replace the -z for gzip in the commands here
9 with a -j for bzip2
10
➔ tar -cjvf archive.tar.bz2 files
11
12 Gzip is faster, but it generally compresses a bit less, so
13 you get a somewhat larger file. Bzip2 is slower, but it
14 compresses more.
}
Introduction to Linux
IT 403 - Global University Spring 2023
1
2
Basic Shell ‘extracting a tar’ {
3
Extract an archive
4
➔ tar -xzvf archive.tar.gz
5
6
7 Extract to a specific directory
8
9 ➔ tar -xzvf archive.tar.gz -C /tmp
10
11
12
Show contents of an archive
13
14 ➔ tar -tvf archive.tar.gz
}
Introduction to Linux
IT 403 - Global University Spring 2023
1
2
3
112 {
4
5
[OBTAINING HELP]
6 <The Linux man (manual) command is used to obtain
7 help with Linux commands.>
8 <Use man <command> to display help for that command.>
9
<Use man -k <keyword> to find all commands with that
10
keyword.>
11
12 <Another tool you can use in a textual environment is
the --help option.>
}
13
14
Introduction to Linux