Anda di halaman 1dari 7

Linux

Linux is a family of open-source operating systems (OS) that are based on the Linux kernel.
There a large community of active developers that create their own distributions of Linux,
known as distros for short. The website ​DistroWatch​ is one of the popular databases that
allow you to search and acquire new distros. In total DistroWatch returns around 800 results,
which really proves how active and involved the Linux community is.

The most common distros are a particular flavour of Linux, known as GNU/Linux. This is a
combination of software available from the GNU project combined with the Linux kernel. The
GNU project was created by Richard Stallman who wrote the first General Public License
(GPL).

Open Source:
Open source software is software that’s source code is publicly available for anyone to use
modify and package/compile themselves, all for free without having to purchase any form of
license.

Taken from the OSI official website, here is the current definition of Open Source:
Generally, open source software is software that can be freely accessed, used, changed,
and shared (in modified or unmodified form) by anyone. Open source software is made by
many people and distributed under licenses that comply with The Open Source Definition.

Linux isn’t licensed under OSI however, it is licensed under the GPL v2 license written by the
Free Software Foundation (FSF). Which is another organisation founded by Richard
Stallman.

Using Linux:
Many people praise Linux for its many capabilities over out of the box software such as
Windows or macOS. It has the ability to be extremely lightweight, with some distributions of
Linux (such as ​Damn Small Linux, referred to as DSL)​ only taking up around 50mb of disk
space.

Some Linux distros don’t contain a GUI (graphical user interface) instead opting for a
completely CLI (command line interface) approach to user interaction. This means that the
user will interact with the OS completely through commands and scripts that they write.
These distros of Linux most commonly used for interacting with servers. Although even in
GUI-based distributions many users still opt to use the CLI for most operations. A terminal
emulator exists in every GUI-based distro for this very reason.

Useful Commands
There are many hundreds of different commands available in Linux and there is plenty of
documentation online. Below I will run through the main commands that I use regularly as an
ATD.
cd:
This will change the directory that you are currently in, known as the Current Working
Directory (CWD), to the path given as arguments. To return to your home directory in most
cases you can just enter ​cd​ on its own but you can also enter ​cd ~/​ . The ~ symbol refers to
your home directory. You can also enter ​cd ..​ with the .. referring to the parent directory.

ls:
List files in the current working directory or in a given path. Contains many useful flags to
display more information.8

● -a displays hidden files


● -l displays in a list format
● -h displays file sizes in a human-readable format
● -d only shows directories
● -R recursively displays files in subdirectories
● -s sorts files by filesize

$​ ls
file_0.txt file_2.txt file_4.txt file_6.txt file_8.txt
file_1.txt file_3.txt file_5.txt file_7.txt file_9.txt

$​ ls -a
. file_0.txt file_2.txt file_4.txt file_6.txt file_8.txt
.. file_1.txt file_3.txt file_5.txt file_7.txt file_9.txt

$​ ls -l
total 0
-rw-rw-r-- 1 sysadmin sysadmin 0 Mar 16 13:28 file_0.txt
-rw-rw-r-- 1 sysadmin sysadmin 0 Mar 16 13:28 file_1.txt
-rw-rw-r-- 1 sysadmin sysadmin 0 Mar 16 13:28 file_2.txt
-rw-rw-r-- 1 sysadmin sysadmin 0 Mar 16 13:28 file_3.txt
-rw-rw-r-- 1 sysadmin sysadmin 0 Mar 16 13:28 file_4.txt
-rw-rw-r-- 1 sysadmin sysadmin 0 Mar 16 13:28 file_5.txt
-rw-rw-r-- 1 sysadmin sysadmin 0 Mar 16 13:28 file_6.txt
-rw-rw-r-- 1 sysadmin sysadmin 0 Mar 16 13:28 file_7.txt
-rw-rw-r-- 1 sysadmin sysadmin 0 Mar 16 13:28 file_8.txt
-rw-rw-r-- 1 sysadmin sysadmin 0 Mar 16 13:28 file_9.txt
tree:
Recursively looks through a folder and displays the contents. Also takes the -L flag where
you determine how many levels to display. For example tree -L 3

$​ tree
.
|-- file_0.txt
|-- file_1.txt
|-- file_2.txt
|-- file_3.txt
|-- file_4.txt
|-- file_5.txt
|-- file_6.txt
|-- file_7.txt
|-- file_8.txt
|-- file_9.txt
|-- myDir1
| |-- file_0.txt
| |-- file_1.txt
| |-- file_2.txt
| `-- file_3.txt
|-- myDir2
| |-- file_0.txt
| |-- file_1.txt
| |-- file_2.txt
| `-- file_3.txt
`-- myDir3
|-- file_0.txt
|-- file_1.txt
|-- file_2.txt
`-- file_3.txt

3 directories, 22 files

touch:
Creates a new file in the current directory or at a given path with a given name and
extension. Also updates the timestamp on existing files.
$​ touch file_0.txt

mkdir:
Creates a directory with the given name and/or path
$​ mkdir myDir4

rm:
Removes (deletes) a file or files. The -r flag can be used to remove directories.
$​ rm file_0.txt
$​ rm -r myDir3/
cp:
Copies a given file to a given destination. If you’re copying a directory the -r flag must be
used to recursively copy the contents/subdirectories.
$​ cp file_1.txt myDir4/
$​ cp -r myDir3/ myDir2/

mv:
Works very much like cp but deletes the original file. Can also be used to rename files.
$​ mv file_2.txt myDir2/

ln:
Used to created links between files similar to shortcuts in Windows. There are two link
options, hard which points to the same file on disk and soft links which create a new file that
is a pointer to the original.
$​ ln file_0.txt ./Documents -s
$​ ls -l /Documents
-rw-rw-r-- 2 sysadmin sysadmin 0 Mar 6 20:50 file_0.txt ->
file_0.txt

alias:
Assigns an alias to a command, script or string of commands.
$​ alias md mkdir
$​ md aNewFolder
$​ ls
Desktop Downloads aNewFolder

grep:
Displays data from a given input based on a pattern provides. This is usually used in
conjunction with other commands such as ls or cat. It searches the input from those
commands for files or lines that match the pattern.
$​ ls -l | grep file_02.txt
file_02.txt
find:
Searches recursively to find files that match a given query. If the files are executable then
the ​-exec​ flag can execute them. You find files based on a name using the -name flag but
also by owner, date, size, etc.
$​ find . -name "file*"
./file_0.txt
./file_1.txt
./file_2.txt
./file_3.txt
./file_4.txt

cat:
Short for “concatenate”, displays the contents of a given file.
$​ cat myDir1/file_01.txt
Hello There!

Compressing/Archiving Files:
As explained in Unit 2, old, unused/inactive data builds up on disk

Compression on Linux:
The main way to compress a file in Linux is by using the gzip command, which has lossless
file compression and decompression capabilities. The term lossless refers to the fact that the
file can be decompressed and reproduced without any data loss. The opposite of this would
be Lossy compression, which reduces the file size at the cost of losing data from the file in
the process. Files compressed with gzip are appended with a .gzip file extension.

Here’s an example of compressing a file using gzip:

Should we need to access the contents of the file again we can use the gunzip command:

Linux also features another compression tool called bzip2. It’s usage is the same as gzip but
its compression process contains more complex algorithms that take longer to
compress/decompress data. The longer wait times are a trade-off as bzip2 can compress
files to smaller sizes than what is possible with gzip. The method of uncompressing bzip2
files is identical to gzip, bunzip2 works with the same way as gunzip and decompresses
bzip2 files with the extensions .bzip2, .bz and .bz2.

Archival:
The process of combine multiple files into a single file ready for storage is known as
Archival. This is useful if you multiple files that are related to each other in some way and
you want them to be archived together. This can be many times more time efficient than
processing each file individually. The standard UNIX tool used for this is tar (an abbreviation
of tape-archive). There is a GNU version of tar that replaces it on Linux, which is also called
tar.

The tar command is used to create, extract and browse tar file (sometimes referred to as
tarballs). If you wish to create a tar file you must include teh -c flag to enable the create
mode. If also want the resulting tar file to have a custom new filename then you can include
the -f flag followed by the new name you wish to use.

You will notice in the example that the result tar file is around the same size as the sum of
the files that it has archived. This is because tar files are, by default, not compressed when
they’re created. To compress them on creation you can include the -z flag when you run the
tar command. This will automatically compress the file using gzip. You could also just run
gzip on the file after it’s been created. When compressing archive files the convention is to
append the .gz/.bz file extensions onto the end of the archive file. It would look something
like this:

This has created a compressed archive file that is considerably smaller than the original.
However, in order to view the contents, you must first uncompress the file (gunzip or
bunzip2), then you can read them with the tar command with the -t flag to enable the browse
mode and the -z to uncompress the data (using gunzip).

Security:
Linux uses the same “Everything is a file” concept that UNIX features. This means that you
are able to access the data from devices and peripherals (printers, keyboards, disk drives,
etc) all from the file system. This is achieved by using mounted virtual file systems that are
visible as one file hierarchy.

Users/Groups:
To control which users can access certain files in Linux User and Group permissions are
applied to them.

To create a new user in the system, the useradd and passwd commands are used. To se
the user’s home directory you must use the -d flag followed by the path to the directory. Here
is an example of creating a new user:

To create a new group we can use the groupadd command and then the usermod command
to add a user to that group. We can also use the id command to see which commands a
user has been added to.

In every system, the default user ​root​ has access to all files on the system without any
regard for permissions.

File Permissions:
All files in Linux have their own set of properties. One of these properties is the permission
levels of the file. Permission levels are used to restrict access to certain file and directories.
There are three types of access for a file: Read, Write and Execute. You can see these
properties of a file by using the ls -l command.

When we run this command we can see different sections each describing attributes of the
flie. In order they stand for:

- Filetype & Permission level


- Amount of hard links point to the file
- File owner
- File’s group
- File size
- Last edit - date and time

Many of these attribute sections are relatively straightforward to understand, however, the
file type and permissions section might not be immediately clear to some. The very first
character of the line indicates the file type, a ​-​ symbol indicates regular files, ​d​ for directories
and ​l​ for links. The rest of the section is made up of nine characters that indicate which
permissions the file has.

There are two main methods of expressing the permissions of a file in Linux. The first
method uses ​r,​ ​w​ and ​x​ (read, write and execute respectively) to indicate permissions that
are enabled and a ​-​ in place of those that aren’t enabled. So for a file to have read, write and
execute for just the owner and everyone else can only read it, the permissions would look
like this: ​rwxr--r--​. The nine characters that represent the permissions on file can be split
into the 3 sections. The first three are permissions for the ​user,​ the second is ​group
permissions and the final section is for ​other u ​ sers.

To add or edit permissions on a file the ​chmod​ command must be used. To give a file full
read, write, execute permissions to all users the command you would need to run looks like
this: ​chmod 777 my_script.py​. The three numbers that are passed into the command (777
in this case) represent the levels of permissions. Each number represents a set of 3 bits
(​rwx​), 111 in binary is equal to 7 in denary so the digits 0-7 are used to define any kind of
rwx combinations. For example, 766 will give a result of ​rwxrw-rw-​.

Anda mungkin juga menyukai