Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
11 views

Fundamentals of Computer Science

Linux is an open-source operating system created by Linus Torvalds as an alternative to Unix. It evolved from the Linux kernel and includes tools and libraries from the GNU project. Linux distributions come in many varieties tailored for different uses like servers, desktops, embedded devices, and more. The command line interface and shell are fundamental to interacting with Linux using commands to navigate directories, view and edit files, install and manage software, and more.

Uploaded by

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

Fundamentals of Computer Science

Linux is an open-source operating system created by Linus Torvalds as an alternative to Unix. It evolved from the Linux kernel and includes tools and libraries from the GNU project. Linux distributions come in many varieties tailored for different uses like servers, desktops, embedded devices, and more. The command line interface and shell are fundamental to interacting with Linux using commands to navigate directories, view and edit files, install and manage software, and more.

Uploaded by

Talema Ayalew
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 43

Fundamentals of

Computer Science
Introduction to Linux Basic Commands &
Environment
What is Linux
Linux is an operating system that evolved from a kernel
created by Linus Torvalds

by Linus Torvalds as a free and open-source


Origins alternative to Unix.
Unix was developed in the 1970s at Bell Labs

is open-source software and can be used Unix is a proprietary operating system,


Licensing freely without any licensing fees. meaning that it requires a license to use.

both have a similar design but are less both have a similar design but larger and
Kernels complex. more complex than the Linux kernel.

On the other hand, Linux is widely used on Unix is typically found on enterprise-level
Availability both enterprise and personal computers. servers and workstations and is less
commonly used on personal computers.
What is Linux
Linux is an operating system that evolved from a kernel
created by Linus Torvalds

bug fixing recognition and solution is very fast require longer up time, to get the best
time possible bug-fixing,and a patch.

Source Code The source is accessible to the general public. The source is not accessible to the general
Availability public.

It has about 85-120 viruses listed to date


Virus Threats It has about 60-100 viruses listed to date. (rough estimate).
Where is Linux used?
Linux distributions are tailored to different
requirements such as

1 Server
2 Desktop
3 Workstation
4 Routers
5 Embedded devices
6 Mobile devices (Android is a Linux-based
OS)
Many software vendors release their own packaged
Linux OS (kernel, applications) known as distribution

Linux distribution = Linux kernel + GNU system


utilities and libraries + Installation scripts +
Management utilities etc.

1. Debian, Ubuntu, Mint


2. Red Hat, Fedora, CentOS
3. Slackware, openSUSE, SLES, SLED
4. Gentoo
command line interface is the primary interface to
Linux/Unix operating systems.

Shells are how command-line interfaces are


implemented in Linux/Unix.

Types of Shell
sh
csh
ksh
bash
Tcsh Reading assignment
Directory Structure
All files are arranged in a hierarchical structure, like

an inverted tree. The top of the hierarchy is traditionally

called root (written as a slash / )

It is maintained by the Linux Foundation

all files and directories appear under the root

directory /
Navigation of the Command Line
Root Directory – the top-most directory in a file system structure
 Home Directory – the file system directory for a given user on
an operating system
Current working directory – the directory in which the user is
currently in
Absolute path – the path of a file from the root directory
Relative path – the path of a file from the current working
directory
File system structure – the organization of the files and
directories of a compute
Using the Terminal
Open terminal
System Info
date Show the current date and time
cal Show this month's calender eg cal -3/cal -j
uptime Show current uptime
uname –a Show kernel information
man command Show the manual for command
df Show the disk usage
du Show directory space usage
free Show memory and swap usage
whereis app Show possible locations of app

which app Show which applications will be run by default

W Display who is on line(user name, terminal where the

corresponding user is working, time of login)

Hostname Print the name of the local host

whoami Who you are logged in as(show current user)

Getent passwd show list of user


id username Print user id (uid), group (gid), supgroups.
History Show last (1000 or so) commands executed from
the command line on the current account
Police
Ethiopia
Condom
+
ፈረስ ቤት

+
+
User
Create new user
User add username----useradd aau
Change password
Sudo password username-----sudo password aau----
Delete user
Userdel username ----------userdel aau

Reading add group and associate user to group


Basic comand
man [command ] shows the manual for a command or
program eg. man who

info [command] similar to man, with a more robust


structure for linking pages together. eg: info man

echo is used to print information to screen


eg: echo well come to basic commands
pwd Show current working directory
cd [directory] Changes into the given directory, or into
the home directory when no parameter is provided
eg. cd desktop– move from current directory to Desktop
Viewing Directory Contents
ls <option> path lists the contents of a directory.

Common options to the ls command


-l: show long listing format
-a: show hidden files
-r: reverse order while sorting
-t: show modification times
-h: use file sizes in (bytes, kilobytes, megabytes etc ) default
is bytes
mkdir create a directory

eg: mkdir example

mkdir a b c dir1 group1----create 4 directory

Copy directory

Cp -r b group1 --- this code copy directory b to group1 folder

cp -r dir1 dir2 Copy dir1 to dir2;create dir2 if not present


Rename directory
MV---- change the name of a director
Mv a NCSC---- this code rename folder a as NCSC

Delete directory
rmdir - Remove an existing directory
rmdir c---- this code remove a directory called c
rm -r Removes directories and files within the directories
recursively.
Creating file
touch  Create empty file
eg touch file 3
touch file1 file 4

cat>  used to places and input data into the file


eg. Cat>file2.txt after this you have write your file

Cat  cat file2.txt ---- used to open file2.txt on terminal

cat> file1 ---- used to override on file2

Cat>>  Append on a text Cat>>file2.txt then type append file

open  command lets open a file, directory


eg. open file2.txt or open aau
Merge file merge more than one file at same time
cat file1 file2.txt

Rename file
MV---- change the name of a file

Mv <Old file Name> <new fileName>


eg. Mv file4 movedFile

Mv movedfile renametxt.txt----- this code rename movedfile to renametxt


Copy File
Cp

Cp text2.txt AAU this code copy file text2.txt to directory AAU folder

Cp text2.txt text11.txt If text11.txt is text file the statement replace and

copy on it

Mv file11.txt aau---- this code cut file11.txt to aau directory

Delete File

rm - Remove an existing file

rm file4--- this code remove a text having name File4


ways to compare files on Unix
diff show you the differences between two text files
Diff text2.txt text11.txt
Diff –y text2.txt text11.txt Compare files side by side

Diff –c file1.txt file2.txt Compare Top to bottom

cmp Tells you if two files are different and where the first difference appears
wc  word counts newlines, words and bytes of a file
eg. wc text2.txt

 To count only word on afile


wc -w text2.txt

 To count only lines of file has


eg. wc -l text2.txt

 To count only characters in a file


eg. wc -m text2.txt
less  writes contents of file onto the screen a page at a time.
eg. less text2.txt

head  writes the first ten lines of a file to the screen


eg. head text2.txt
eg2. head -4 text2.txt this code print the first 4 line from file1.txt

tail  writes the last ten lines of a file to the screen.


eg. Tail text2.txt
eg2. tail-4 text2.txt this code print the last 4 line from file1.txt
Searching the contents of a file
less  search though a text file for a keyword (pattern).
eg. less text2.txt

grep  searches files for specified words or patterns.


eg. grep first text2.txt

To ignore upper/lower case distinctions, use the -i option, i.e.


eg. grep -i first file2.txt

Some of the other options of grep are:


-v display those lines that do NOT match
-n precede each matching line with the line number
-c print only the total count of matched lines
link to another file
LN

used to create links.

What is a link?

 It's like a pointer to another file. A file that points to another

file. You might be familiar with Windows shortcuts. They're

similar.

 We have 2 types of links: hard links and soft links.


Hard links Hard links
are rarely used. They have a few limitations: you can't link to directories,
and you can't link to external filesystems (disks). A hard link is created
using ln
Eg. ln file1.txt newfile.txt

 Now any time you edit any of those files, the content will be updated for both.

 If you delete the original file, the link will still contain the original file

content, as that's not removed until there is one hard link pointing to it.
Soft links Soft links
They are more powerful as you can link to other filesystems and to
directories, but when the original is removed, the link will be
broken.
You create soft links using the -s option of ln :
Eg. Ln –s file1.txt newfile.txt

In this case you can see there's a special l flag when you list the file using ls
-al , and the file name has a @ at the end, and it's colored differently if you
have colors enabled:
remove duplicate lines
Cat> fruit
Apple
Orange
Create a file with name Fruit 
Banana
Apple
Grasp

Deplication removed using Sort fruit


Uniq and sort key words
Uniq fruit
gzip
compress a file using the gzip compression protocol named
LZ77 using the gzip command.

Syntax Gzip filename


gunzip
command is basically equivalent to the gzip command, except the -d option is

always enabled by default.


tar
The tar command is used to create an archive, grouping multiple files in a single

file. Its name comes from the past and means tape archive. Back when archives

were stored on tapes. This command creates an archive named archive.tar with

the content of file1 and file2 : tar -cf archive.tar file1 file2
More on Linux command read from the link

Linux Directories - javatpoint

https://www.javatpoint.com/linux-directories

You might also like