Linux Learning
Linux Learning
Linux Learning
com/linux/linux-administration-series
Linux is the name we give to operating systems that are built around the
Linux kernel. There's no single Linux operating system, and operating
systems that are based on the Linux kernel are referred to as Linux
distributions.
Linux is based on the idea of free and open source software, software
whose source code we can view, edit, and change to suit our needs. The
Linux world is enormous, and Linux can be used for everything from
running huge global networks to controlling electronic projects like a
Raspberry Pi. Linux can be your everyday desktop environment at home or
at school, your software development platform at work, and it even runs
some of the world's largest and most powerful supercomputers. All of
these applications share the same basic components, a kernel, a user
space, files and resources, and so on. If that sounds complicated, don't
worry. We'll take a look at each of these ideas and components in more
detail later on, and I'll recommend courses for you to explore in order
to dive even deeper, if you're interested to do so. Linux runs in a wide
array of places, and that means that there are many different kinds of
people who have many different jobs or roles where they use Linux. For
example, I'm primarily a system administrator. My skillset in Linux
revolves around setting up, configuring, and maintaining Linux systems
that are intended to be used for specific purposes. Many people work with
the source code of the kernel directly as software developers or as
hardware developers, to enable the kernel to work with new hardware and
new technologies. Another large group of people who use Linux are
developers who work outside the kernel, to create software for
productivity, like office suites, image editors, chat apps, and more.
Many software developers use Linux for their coding and programming work.
And an enormous amount of the services we use on the web are hosted on
Linux servers. And many people use Linux to get other creative and
productive work done. These are writers, video editors, artists,
musicians, scientists, analysts, and all kinds of professionals,
hobbyists, and explorers, who may not care about the technical details of
the kernel or of software development, but who want to use free and open
source software and operating systems. Linux is for all of these people
because Linux is for everybody. Chances are you're here because you're
interested to learn about using Linux for one reason or another. You may
be an aspiring kernel developer, a system administrator coming to Linux
from another operating system, a software developer who needs to become
familiar with working in the Linux environment, or someone who wants to
build robots or home automation or self-driving cars. Or you may be
someone who wants to focus on using software tools on the desktop and not
worry about anything under the hood. In any case, the goal this course is
to give you an introduction to what Linux is and to provide you some
recommendations for extending your learning. There aren't many
prerequisites for this course, aside from having a general high-level
understanding of how to use a computer. If you have experience using
Windows or macOS, those skills can transfer over to a Linux environment
pretty easily. We won't be installing Linux in this course, so you don't
need to prepare your computer or set anything up. I'll be using an
installation of Linux to show you a few things, and I'll point out
resources along the way that will get you started installing and using
Linux when you've decided which path to take and where your first steps
will go.
Hardware running only a Linux kernel, isn't very useful to most people,
so we'll need to use software that lets us use the computer for doing
whatever we need to do. Linux distributions come with a set of tools that
let users and software interact with the system. And these tools often
include a software package called the GNU coreutils, short for core
utilities. Many of these coreutils are commands that we'll commonly use
when working in a shell. Including commands to copy and move files, to
change permissions and security contexts, to view some status information
and so on. Humans use these, the command line, and scripts and other
programs can use them as well, to perform basic tasks. We can add other
software later, but out of the box so to speak, a basic Linux
installation will have these standard tools available. Which give us a
minimal operating set of utilities, and which are needed in order to
customize the system, use it to get work done, and even to install and
manage other software. This slide shows the coreutils that are part of
the Ubuntu desktop installation. You don't need to write them down or
anything like that, I just wanted to give you a look at how many there
are. I've highlighted some commonly used commands, like cat, which we use
to display file contents, cp, which is for copying files, df and du,
which show information about how much space is used up on the file
system, and more. My course, Learning Linux Command Line, covers some of
these common commands, the ones that are useful every day and which a
command line user should work to memorize. The coreutils also include
commands that many people will use less frequently, if ever. Some of them
are legacy commands that are expected to be available for historical
reasons. And some are for very specific tasks that most Linux users, and
certainly most Linux learners, won't need to use. I've been using Linux
for almost 20 years, and I've never used some of these. Generally
speaking, if you have a Linux distribution installed, you don't need to
worry about installing these tools yourself. They're just there in the
box alongside the kernel and other supporting software, that distribution
maintainers built in for us. And if you're going to be using desktop
environment, and not a shell in a terminal or console, you don't need to
worry about these at all. Well, most distros use the GNU coreutils, some
use a different set of tools called BusyBox. It's an alternative to GNU
coreutils and it's often found in small, or embedded systems. What makes
BusyBox interesting is that it's a single program, which offers many of
the functions of common coreutils tools. It also offers a wide array of
other tools as well. This shows the commands that BusyBox offers, and
again, I don't intend for you to write them down, or even remember them.
The point is to show how much supporting software we get from this one
package. Here, I've highlighted the BusyBox commands, which overlap with
the coreutils. The others are implementations of other common tools or
are features offered by shells and things like that. The point here is
that while the Linux kernel itself can interact with a huge amount of
hardware, and provides an enormous amount of functions that software can
hook into, much of what makes Linux a flexible, consistent and widespread
operating system, is the tools that accompany the kernel in a
distribution. Whether you're using a system with GNU coreutils, or
BusyBox, you can rely on having common, basic, familiar command line
tools at your disposal. When you reach for the command to copy a file
from one place to another for example, it's the same on all Linux
systems. It works pretty much the same, and it has the same name. This
common foundation of software makes it easier to switch between distros.
Because these commands are available nearly everywhere within the Linux
world.
Shell - simply put the shell is a program that takes command from the
keyboard and gives them to the operating system to perform. It's good to
be familiar with the shell, regardless of what you plan to use a Linux
system for.
Terminal - It is a tool which you can use to pass your shell commands.
This is a program that opens a window and lets you interact with the
shell .
drwxr - directory, read, write, execute, read -> these are the rights
ls >out.txt - save the results of the ls into some file named out.txt, if
it is not there, it will be created. The ">" arrow indicates the flow of
the stream, that the results will be input to the given file
q - quit terminal
cd command
cd command is used to Change the shell working directory. Navigating from
one directory to another is done with the command cd taken over the
directory name. Change the current directory. With no arguments âcdâ
changes to the users home directory. How to use the cd command, by The
Linux . cd command in Linux/Unix | change directory. Linux and UNIX cd
command help and examples. cp command in linux. mkdir command in linux.
cat command in linux. rmdir command in linux. pwd command in linux. grep
command in linux. clear command in linux. cd options linux
cd [dir] -
cd ~ means go to home directory
Suppose you have a folder named "My Books", notice that there is a space
between MY and BOOKS, so if you give cd My Books command, then it will
not locate it, because cd always looks for the first word after it.
There are three ways of locating such a folder which has a space in its
name.
************************
cat
cat command is used to show the content of a files and also to combine
several files together in one file. The cat command does not accept
directories as input. cat (Unix) . The cat Command. How To: Use cat
Command In Linux / UNIX. Linux and UNIX cat command help and examples.
cat - Unix, Linux Command . Searches related to cat command. cat command
windows. cat command examples. cp command, ls command. cat command in
Linux with examples. cat command terminal. cat command in UNIX. bash cat
command.
cat -s list1.txt - display the contents of the file by squeezing all the
line breaks into one line break. It does not ffect the other contents of
the file.
cat > test.txt - whatever you type after this, will be saved into a file
named test.txt
press ctrl + D - to indicate the end of the file
*************************
*************************
Input/Output Redirection
capturing output from a file/command/program and sending it to another
file/command/program.
************************
pipe command
lets say you want to send the output of a command to another command
you can use pipe command, to chain together multiple commands, sending
the output of each one to another.
wc << EOF lets you directly send data to wc command, and then when you
are done typing, you can type EOF, and it will give you the required
output.
"EOF" here is a text marker, you can use anything, but make sure to
choose something that would not normally occur in your text.
ls docs
*displays a std error output saying that docs does not exist*
*************************
echo
echo "some text"- displays that text on the console window by default
apropos "What you want to search for" - used in case when you want to
find a command but you don't know the name of it.
to create one folder that has space in its name - mkdir "my folder" or
mkdir my\ folder
**************************
to copy a file to a folder
cp file_name1(source) file_name2(destination)
**************************
**************************
(mv command is used to move files/folders from one folder to another)
mv myfile Documents
**************************
to remove a file
**************************
to remove a folder
rmdir folder_name (spearated by spaces)
**************************
**************************
wildcard pattern matching - works with any command that uses files or
directories. For example: ls or rm
example: ls a* - will give you all file names that start with a
example: la a*a - will give you all file names that start and end with a
example: ls ??? - gives all file names that are three character long
example: ls ?a? - gives all files that are three character long with an a
in the middle
**************************
**************************
file links
There are two kinds of links, called hard links and soft links (or
symbolic links).
To understand the difference, first we need to understand a little bit
about how file information is stored and referenced. When I have a file,
say users.txt, the actual data in the file is stored on the disc in a
series of data blocks. And the locations of those are stored in a
structure called an inode. And then the file system associates the name
of the file in its index of files with the data in that inode.
When we create a link, we tell the file system to associate the file with
a name we provide. A hard link associates that name with the inode of an
existing file, and a soft link associates the name we provide with a file
name of an existing file.
So if we make a hard link to users.txt and then rename users.txt, our
link will still point to the same information. But if we make a soft link
to users.txt and then rename users.txt, our soft, or symbolic, link will
break.
Because of how they work, a symbolic link, or sym link shows up to the
system as a short cut, or a reference to the referenced file. And a hard
link shows up as a regular file. In fact, all the files you see in your
file system, unless they are a soft link, are actually hard links
themselves.
**************************
**************************
finding files
if you create file with touch, then they take up no space by default.
if you want to create files and allocate space to them simultaneously, we
can use:
truncate -s 1MB file_name
lets say you have a file named "lemon" and a folder named "lemon".
if you do:
find . -name "lemon"
it will fetch both the file and the folder
if you do:
find . -name "lemon" -type d [it will fetch only the folder/directory]
if you do:
find . -name "lemon" -type f [it will fetch only the file]
Using "Diff"
It tells you the difference between two files.
**************************
Comparing non text files
**************************
Archives and Compression
(combine files into one large file) (reduce the size of the
file)
(not necessarily compressed)
tar -cf archive_name.tar * (-c for create and f to store the result into
a file) (you have to specify what set of files you want to archive, in
this case you want to archive all the files, so you cna say *)
tar -czf files.tgz file* text* (all the files and all the files that
start with the word text)
**************************
**************************
Regular Expressions
you can use: cat users.txt | grep -E ".*" (last thing means all
characters)
**************************
Changing Files Programmatically
Using sed
substitution:
cat users.txt | sed 's/e/d/' - s for substitute, letter "e", we want to
replace with letter "d".
But this replaces only the first instance of "e" with "d" in each line.
If you want all instances to be replaced, then you can give greedy (g).
If you want to remove all the characters after a space, you can basically
do, match characters after the space using regex and then replace them
with nothing
Using AWK
awk is basically used to modify the files
example:
list all the first names or the first items in each line
cat users.txt | awk '{print $1}'
**************************
File Permissions
Read(r) 4 4 4
Write(w) 2 2
Execute(x) 1
7 6 4
Symbolic Notation:
set permission (=)
add permission (+)
remove permission (-)
"stat mytext" lets you see the file permissions along with time stamps.
************************
Root User
there's a user called root that acts as the super user. That is, a user
who's not constrained by any limitation. Everything is visible to root.
And, unless the file's encrypted, no file is out of root's reach.
************************
Installing Software
keeps track of software available from the Ubuntu repository, and lets us
install it, remove it, or otherwise manage it on our system
************************
Remote Access