Linux

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 5

Linux Commands:

1. ls Command:

->ls: it shows the files.


->ls -l: it shows the fils in a long list format, it also shows the file sizes.
->ls -r: it shows files in reverse alphabetical order.
->ls -lr: it shows files in long list wit reverse. aplhabetical order combination
of both l and r in ls command.
->ls -lh: it shows the files in long list with human readable format.
->date: it shows date and time.
->cal month year: it shows the calender of the particular month and no of days in
it of the particular year and in which day we are in now and highlights it.
->history: it shows all the history of commands we used in shell.
-> !number: in history command it has number for the we used previously if we enter
!number it will display the output of the dcommand we used earlier.

(or)

->history number: shows only the last three commands we entered.


->!-n: it shows the third command we used form the bottom of the history list.
-> !!: to execute the most recent command.
->! recent command name: it executes the command which was recently used in a
iteration.
->variable="value": it is used to initialize variables and it is local variable
declaration.
->echo $variable name: it is used to print the content of the variable stored
locally.

->Environment variables:
it is used to declare variables gloabally using the command echo $varaiable name
Ex: ->echo $var1
here globally var1 is created.
->var1=48
var1 is initialized to a value
->echo $var1
output: 648
->env | grep variable name: it will create the variable locally but we need to
convert to to global variable
so we use the export command to convert the local varoiable in to global variable.
Ex: env | grep var1
->var1=1000
the value is initialized.
-> export variable name:
Ex: export var1
-> to see the gloabal variable we need to call the command
env | grep var1
output: var1=1000
-> we can directly craete a environmenrt variable using the export command-> makes
a variable gloabal
Ex: export var1="yaso"
and for seeing the gloabal variable we need to enter the command env | grep var1

->unset: it is used to clear the exported values in the variable which was globally
declared.

-> echo $PATH: it displays the path of the current shell.

->type command name:it tells about the command details


Ex: type echo
output: echo is a shell built in.

->which command: The which command searches for the location of a command by
searching the PATH variable.
Ex: which ls
output: /bin/ls

->type -a command name: it shows the details of the command withh the path of the
command in it.

->alias variablename="command" : it defines a alias name for the command for faster
use with a single word in linux.

->Functions:
To create a function
Ex: function name () {
>commandsd
>values
}

To calla a function:
Ex: function name
output:
list of details in the function.

->for echo singl quotes and double qoutes are works in different ways.
Ex:
->echo 'hi the path is $PATH'

output:
hi the path is $PATH

->echo "hi the path is $PATH"

output: hi the ppath is


/home/sysadmin/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr
/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

->Back Quote: (``)


it displays the command value if we want to use in a echo command if not it
displays the date insyead of the date output by the command.
Ex:
->echo today is `date`

output: today is Tue Jan 30 04:24:27 UTC 2024

->Semicolon command:
it is use to work on multiple commands at a time.
Ex: cal 1 2024; cal 2 2024; cal 3 2024
output:
January 2024
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
February 2024
Su Mo Tu We Th Fr Sa
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24

March 2024
Su Mo Tu We Th Fr Sa
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31

->Ampersand:
it is used to display a command within a single line
Ex: ls /etc/ppp && echo hi

output:
ip-down.d ip-up.d
hi

->Double pipe:

Sytax: command1 || command2

Ex:
ls /etc/ppp || echo hi

output:
ip-down.d ip-up.d it is executed because if there is working command with the
output the other command cant be executed.
If the command has error the other command works well.
Ex: ls /etc/junk || echo failed

output:
ls: cannot access '/etc/junk': No such file or directory
failed

->pwd: print working directory.


->whoami: systemadmin
->unmae: linux (operating sytem name)
->uname-n or name --nodename: it displays the username of the linux.
->echo Today is $(date): it also displays the data with command executed.
->man command name: it displays the command details in a document format.

->cat file name: it displays thre content of the file we stored in it.

->echo "text" > filename: to store in file and the previous data will be deleted.
->echo "text" >> filename: to edit the file without deleting previous data and adds
new content in to it.

->read NAME: it reads strring

->Host A host is a computer. Many people automatically think of a desktop


computer or laptop when they hear the term computer. In reality, many other
devices, such as cell phones, digital music players and many modern televisions,
are also computers. In networking terms, a host is any device that communicates via
a network with another device.

->Network A network is a collection of two or more hosts (computers) that are


able to communicate with each other. This communication can be via a wired
connection or wireless.

->Internet The Internet is an example of a network. It consists of a publicly


accessible network that connects millions of hosts throughout the world. Many
people use the Internet to surf web pages and exchange emails, but the Internet has
many additional capabilities besides these activities.

->Wi-Fi The term Wi-Fi refers to wireless networks.

->Server A host that provides a service to another host or client is called a


server. For example, a web server stores, processes and delivers web pages. An
email server receives incoming mail and delivers outgoing mail.

->Service A feature provided by a host is a service. An example of a service


would be when a host provides web pages to another host.

->Client A client is a host that is accessing a server. When you are working on
a computer surfing the Internet, you are considered to be on a client host.

->Router Also called a gateway, a router is a machine that connects hosts from
one network to another network. For example, if you work in an office environment,
the computers within the company can all communicate via the local network created
by the administrators. To access the Internet, the computers would have to
communicate with a router that would be used to forward network communications to
the Internet. Typically when you communicate on a large network (like the
Internet), several routers are used before your communication reaches its final
destination.

->ifconfig: it shows the details of the ip address and it can also be used to
change the ip configurations.

->Groups:

->groupadd filename: it creates a group for the user created one.


->groupadd -g groupid number filename: it creates a group with specific group id
defined by user.
->groupadd -r filename:it will assign a group id with the lowest of the initial
group id we created.
->grep filename /etc/group: it will show the group details with the group id it was
assigned.
->getent filenmae/groupname: it will get the details of the group with its group
id.
->Group name rules:

1. start with underscore or a-z alphabets.


2. 32 characters are allowed for naming a group.
3. some distributions may not allow more than 16 letters for nmaing a group.
4. after the first characyter the remaining lettrs can be underscore(_).
5. the last letter cant be placed with a hyphen.

->groupmod -n newfilename oldfilename: it will modify the group name with the new
one and with the same group id it was assigned.
->groupdel groupname: it will delete a group we created.
Users and Ownerships:

->touch /directory/filenmae: it creates a file in the directory of owners group


and it its owner will be the admin of the group.
->id: it checks who is the user.
->chgrp group_name file -> it changes a group name of using this command.
->

You might also like