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

Basic of Linux

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

Basic of Linux

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

Basic of Linux

1. Linux made by the Linus Torvald in 1991.


2. Linux is a Kernel. {OS = Kernel + Software}.
3. Linux is not a Unix derivative. It was written from scratch.
4. A Linux distribution = is the Linux kernel and a collection of software, that together
create OS.
5. Linux OS = Linux kernel + GNU.
6. Linux is the combination of GNU software and Linux kernel.
7. Linux is based on CLI (command line interface) while windows is based on GUI (Graphical
user interface). Linux too has GUI but the CLI is very popular for Linux.

Linux features (Advantages):

1. Open source
2. Secure
3. Simplified updates for all installed software
4. Light weight
5. Multiuser – Multitask
6. Multiple distribution – Red Hat, Debian, Fedora, Ubuntu, KALI Linux.

File system hierarchy:

1. / = Forward slash – Top level root directory.


2. /home = It is the home directory for root user.
3. /root = It is home directory for root user.
4. /boot = It contains bootable files for Linux.
5. /etc = It contains all configuration files.
6. /usr = By default software are installed in this directory.
7. /bin = It contains commands used by all user. Root user can too use these commands.
8. /sbin = It contains commands used by only root user.
9. /opt = Optional application software packages.
10. /dev = Essential device files, this includes terminal devices, USB or any device attached to the
system.

Linux Commands and it’s use cases:

1. How to create a file.


1. cat
2. touch
3. vi/vim
4. nano

1. cat =
1. Create file: To create a single file.
2. Concatenate file: To add more than one file into a single file.
3. Copy files: To copy the content of file x into file y.
4. To exit: Use ctrl+d.
5. If you want to add something in your existing file, you can add with the help of this
command. But you cannot edit anything in that file, you can only add.
6. tac: To see the content, from bottom to top.

2. Touch=
1. Create an empty file.
2. Create multiple empty files.
3. Change all timestamp of a file.
4. You can update access time or modify time individually too, of the file.
5. touch -a & touch -m (commands for above line).

Time stamp: (cmd: stat ‘filename’)


1. Access time: Last time when a file was accessed.
2. Modify time: Last time when a file was modified.
3. Change time: Last time when file metadata was changed.

3. vi/vim (editor):

1. A programmer text editor.

2. It can be used to edit all kinds of plain text, it is especially useful for editing programs, mainly used
for Unix programs.

Commands –

:w – to save

:wq or :x – To save & quit.

:q – Quit only (it will not save your current work).

:q! – Force quit (No save).

i = Press i to insert (to edit or add something in the file).

Esc = Press esc to come back from the editing or adding zone.

4. Nano:
To create a file, and edit a file too.
Use ctrl+x = to exit, and Y = to save and press enter.

Some more basic commands:

sudo su = super user do switch user


ls = To see the list of directory and files.

ls -l or ll = To see the list of directory and files, with details (ll includes hidden files).

ls -a = To see the list of all directories and files (included hidden one).

history = to see the history of the commands, which you have already run.

Ctrl+l or clear = To clear the page.

mkdir = To create a directory. Use -p to create a directory inside a directory.

cd = To change the directory.

cd .. = To come out from the directory (backspace).

cd ../../.. = 3 time back, in a single command.

pwd = Print working directory.

.filename/.directoryname = If you want to create a hidden file or hidden directory, just use . (dot)
before the file name.

cp = To copy a file data into another file. But the data of another file will be removed, once used this
command.

Example – cp file1 file2

cp -r = To copy a directory and its contents.

mv = To cut and paste. And to rename a file or directory.

Example – mv file1 dir1 or mv dir1 dir2 or mv file1 myfile

rm = To remove (delete) a file.

rm -r = To remove directory.

rm -rf = To remove non empty files and directory. (forcefully).

which = To check the location of installed Package (software) or whether it is installed in your system
or not.

tree = To check the details of the directory and files in one page. (apt-get install tree).

less = To see the content of first entire page. To exit press q.

head = To see the content of 10 starting lines.

tail = To see the content of 10 last lines.

more = To see the entire content, page by page.

sudo apt install “package name” = To install a package (software) in our system.

Hostname = To see the private IP address for your machine.

Cat /etc/os-release = To see the basic details of your machine.

Ifconfig = To see the IP addresses and ethernet port of your machine.


Apt install nginx = To install nginx in your machine. (apt – advanced package tool).

Apt remove nginx = To remove nginx from your machine.

Apt update nginx = To update, installed nginx in your machine.

Service (systemctl) nginx start = To start the nginx (if it is showing inactive).

Service nginx status = To check the status of your nginx. It is active (running) or not.

Cd /var/www/html = It is the location, where we can see and make index.html file.

Whoami = To see who you are.

Echo = If your machine has been using by others users too, then this command will help you to pass
the message to them. (To highlight the message).

We can create the file too by using the echo command.

Eg – echo “welcome” >filename.

Echo “namaste” >>filename

Echo >filename

Grep = If you want to see the specific content in your file (like – name, contact no or whatever). It
works same like, ctrl+f works in windows.

Sort = To change the data alphabetically into the file. (A-B-C).

useradd = To create the user. Like in windows we create user by the control panel, so that the user
cannot have the admin rights. Eg- useradd ajay

Cat /etc/passwd – it is the location where we can see the users.

Note – when we create a user, then the group will automatically be created by the same name.

groupadd = to create the group.

Eg- cat /etc/group – location to see the existing groups. We can also see the users which is already
added in that group.

Note – But when we create the group, the user will not be created by the same name.

gpasswd -a = to add the user into group. & use -M to add multiple users into the group. Use (,) to
separate the users.

Eg- gpasswd -a username groupname

cat /etc/group – to check, if the user has been added in the group or not.

Note – if you want to add any user in the group, then you must create the user first.

ln = To create a hard link (backup) of your file. And the hard link automatically syncs with your
original file. Even if you delete your original file, the data will not be affected here. As it works like a
backup file. Weather you update your original file or backed up (hard link) file. The data will be
updated in both files at the same time.
ln -s = To create a soft link of your file. It is also sync with your original file, but when you delete your
original file then you will not see the content of your file here, as it works like a shortcut.

Tar = To group/pack multiple files into one file. Tar is an achiever.

Eg – tar -cvf filename.tar filename. tar -xvf filename.tar – to extract the tar file.

gzip = To compress the file or directory.

Eg – gzip filename

gunzip = To upzip the zip file/directory.

Access modes/Permissions

The three basic permission modes are:

Read (r) (4) = Allows users to view (display) the content of a file or list the contents of a directory.

Write (w) (2) = Allows users to modify the content of a file or create/delete files within a directory.

Execute (x) (1) = Allows users to execute a file (if it's a script or executable) or enter into a directory.

These permissions are assigned to three categories of users:

Owner/user = The user who owns the file or directory.

Group = A group of users who share certain permissions.

Others = Any user who is not the owner and not part of the group.

Method 1:

= Each permission is assigned a numeric value: read (4), write (2), and execute (1).

These values can be added to represent the permission modes.

For example, "rwx" becomes 7 (4 + 2 + 1), "rw-" becomes 6 (4 + 2), and "r--" becomes 4 (4).

(r = 4, w=2, x=1)

Commands:

chmod = To change the access mode of a file.

chown = To change the owner of a file or directory.

chgrp = To change the group of a file or directory.

- rw- r-- r-- 1 root root 18 Aug 15 13:45 filename


file
Represent: file or owner/root other symbolic who is group size
directory or link user group users link owner name (bytes) date time filename
Aug-
-/ d / l rwx rwx rwx 1 root root 18 13:45 filename
15

Method: 2 = (=, +, –)

U = user/owner

G = Group

O = Others

u=rwx, g=rw-, o=r—

You might also like