0% found this document useful (0 votes)
132 views

LINUX Commands

The document provides a list of common Linux commands and their uses. Some key commands include: - who am i - to check the user ID - hostname - to view the host name - uname - to check the operating system name and version - date - to view the system date and time - ls - to list files in a directory - cd - to change directories - mkdir - to create new directories - rm - to delete files - cat - to view the contents of a file - grep - to search for text within files It also includes commands for package management, networking, editing files, and using Git.

Uploaded by

yaswanth Reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
132 views

LINUX Commands

The document provides a list of common Linux commands and their uses. Some key commands include: - who am i - to check the user ID - hostname - to view the host name - uname - to check the operating system name and version - date - to view the system date and time - ls - to list files in a directory - cd - to change directories - mkdir - to create new directories - rm - to delete files - cat - to view the contents of a file - grep - to search for text within files It also includes commands for package management, networking, editing files, and using Git.

Uploaded by

yaswanth Reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 9

linux commands:

---------------
who am i ----> to know the user id.

who ----> to know how many users connected.

hostname ----> to know the host in server.

hostnamectl set-hostname web1 / sudo hostnamectl set-hostname web1 ----> to change


the host name ( sudo --> admin previlieges).

exec bash ----> to refresh the terminal.

uname ----> to know which `os` using.

uname -a ---> to know the details of os (kernel version, built config, os


name ....etc).

cat -----> to open the content in the file.

cat /etc/redhat-release ----> to know the distribution of os. (cat


/etc/ec2_version ---> for ubuntu)

date -------> to check the date & time of server (UTC).

------ sudo datectl ----> to change the time to regional zone.

echo "hello" ------> to print the text.

clear -----> to clear the screen.

uptime -----> to find the details of load, starting time of server,


connection ..etc ( load avg parameters ---> before 1min, 5min, 15min).

history -----> to check the history.

history -c -----> to clear the history.

free -h, -k, -m -----> to check the ram size of server (h > human readable, k >
kilobyte, m > megabyte).

df -h, -k, -m ------> to find the mounts(drivers) of storage.

cat /proc/cpuinfo ------> to find the cpu information of server / to find the
file content in mount i.e, /proc.

pwd -----> to check the current/present working directory (folder).

mkdir directoryname ------> to create a new directory

cd directoryname -------> to enter into directory (or) change directory

cd .. -------> to exit from the directory.

rm -rf -------> to delete the directory /file (it delete's the directory /file
empty or full).

rmdir directoryname -------> to delete the directory ( it delete's the directory


only if it is empty).
mkdir dir1 dir2 . . . .dir^n --------> to create multiple directories at a time.

mkdir -p dir1 dir2 . . . dir^n -------> to create multy-level directories at a


time.

touch filename -------> to create new empty file.

cat >>filename -------> to create new empty (or) content file. {note: press
ctl+d after writing content in the file).

mkdir /tmp filename --------> to create a file in specific location.

rm filename -------> to delete/remove the file.

rm * ------> to delete all files at a time.

ls ------> to check list the files. (In metadata identifiers are : - file, d
directory, l links).

ls -l --------> to list the files according to alphbetical order


in metadata.

ls -lr --------> to list the files according to reverse alphbetical


order in metadata.

ls -ls --------> to list the files according to size order in


metadata.

ls -lsr --------> to list the files according to reverse size


order in metadata.

ls -lt --------> to list the files according to time order in


metadata.

ls -ltr --------> to list the files according to reverse time


order in metadata.

ls -l ,ls -la, ls -lr, ls -ls, ls -lsr, ls -lt, ls -ltr /tmp ---------> to open
list of files in specific location.

touch .filename -----> to create hidden file.

mkdir .directoryname ------> to create hidden directory.

ls -la -------> to check the all list of files/directories of hidden.

cat filename -------> to see the content in the file.

head filename -------> to see the content in the file at top side of file ( it
defaultly shows 10 lines of content).

head -number filename ------> to see the content in the file at top side of file
( it shows the no.of lines of content we given).

tail filename --------> to see the content in the file at bottom side of file ( it
defaultly shows 10 lines of content).

tail -number filename --------> to see the content in the file at bottom side of
file ( it shows no.of lines of content we given).

cp existingfilename newfilename --------> to copy the file into another file /


backup.

cp existingfilename /tmp ---------> to copy the file into tmp location.

mv existingfilename newfilename ---------> to move the file /renaming the


file.

mv existingfilename /tmp/newfilename --------> to move the file to tmp location


(with same name or different name).

sudo adduser username/userid -----------> to create/add user

sudo passwd username/userid -----------> to generate password to the user


(after using this command type password two times)

cat /etc/passwd ------------> to check the updated/to check the users list.

sudo usermod userid -G ---------> to add users to the group

sudo groupadd groupname ---------> to create a new group

sudo getent group ---------> to check the groups list

sudo gpasswd -d username gropname ----------> to remove user from


group

sudo groupdel groupname -------> to delete the group

sudo userdel username -------> to delete the users

sudo chown newowner filename ---------> to change the ownership of a file

sudo chmod 111 filename -------> to change the permissions of file (permissions:
r-->read, w-->write, x-->execute)
values: 0 = no permissions
1 = execute only
2 = write only
4 = read only
3 = write & execute
5 = read & execute
6 = read & write
7 = all permissions
8 = no & invalid

sudo su ---------> to switch the user from another user ( it defaultly switch
to root user)

sudo su username/userid ------> to switch the user to another user.

ps -ef --------> to find the list of process id's

ps -ef | grep ssh -------> to search the file in process of ssh.

kill -9 processid -------> to kill/end the process

top --------> to check the health/load/cpu utilization/ process & memory


utilization

grep word filename --------> to search the content in the file.

grep -i word filename -------> to search the content in the file with
excluding case-sensitive

grep -ic word filename -------> to search the content in the file with
how many occurencies are there.

find filename -------> to find the file

find . filename -------> to find the file in current location (. is pwd


here)

find . -emty ---------> to find empty file in current location

find . -size+1g --------> to find the files based on the size

find . -time7 -------> to find the files based on the time

networking command: to work all these networking


command first install {net-tools, bind-utils, telnet}
--------------------
ping domain or ipaddress --------> to check the health/connection
details of a particular server

ifconfig or ip addr ---------> to check the ip address


of same server.

nslookup hostname ----------> to check the ip address of a


mapped hostname (hostname of other servers)

sudo telnet ipaddress ---------> to check the port numbers in


a server

netstat -ntlp ---------> to give the access permission


to a particular tool/server.

package managements:
----------------------
sudo yum update -------> to check/update the packages in linux

sudo yum install toolname ------> to install the


tool/softwares in linux

sudo yum install -- wget url -------> to install the


tool/softwares from url in linux

sudo yum remove toolname ------> to uninstall the


tool/softwares in linux

sudo service nginx start ---------> to start the


nginx service in linux (restart, status, stop )

tar -cf newfilename.tar filename ---------> to zip the files/directories.

tar -xf filename.tar ---------> to extract the files/directories.


ln -s pathname linkname ----------> to create a link from one mount to other
mount

unlink linkname --------> to remove the link

nano filename --------> to edit the file in nano editor ( after editing
press ctl+x to save file)

vi filename --------> to edit the file in vi editor ( press i to enter into


insert mode & after editing press esc & :wq to save file)

GIT COMMANDS:
---------------
git init -------> to intialize the git in working area

git config --global init.defaultbranch <name> ------------->


to add the branchname as default in working area

git branch -m <name> --------> to rename the branchname

git status -------> to check the files status in working area

git add <filename> ---------> to add the file from working area
to staging area (after this command git tracks the file).

git add -A ---------> to add the all files from working area to
staging area

git rm --cached <filename> ---------> to remove/unstage/undo


the file from staging area to working area.

git commit -m "message" ----------> to commit the file from


working area to local repo/staging area (after this file added to local repo)

git config --global user.name <username> --------> to set


the username for commits as default.

git config --global user.mail <usermail> --------> to


set the usermail for commits as default.

git log <filename> ---------> to check the details of


commits to a particular file

git log ---------> to check the details of commits in


localrepo

git remote add <projectname> <url of remoterepo> ---------> to


add the remote repository to local repository

git remote ---------> to check the projects of remoterepo

git remote delete projectname --------> to delete the


remoterepo from the localrepo

git push projectname branchname ----------> to push the code


from localrepo to remoterepo
git pull <url> -----------> to pull the updted files from
remote repo to working area & localrepo (it is combination of git fetch + git
merge)

git clone <url> --------> to pull the updted files from


remote repo to working area

git fetch <url> -------> to pull the updated


files from remoterepo to staging area

git branch <branchname> --------> to create new branches under


master branch

git checkout -b <branchname> -----> to create and enter into


branch at a time

git branch -----> to list the branches

git checkout <branchname> -------> to switch the branches

git clone -b <branchname> <url> -------> to clone the branches

git branch -r -------> to view the list of branches in


remoterepo

git branch -d <branchname> ------> to delete the branches


in localrepo

git push remote origin --delete <branchname> -------> to


delete the branches in remoterepo

git push <projectname> <branchname> --------> to push the branch


from localrepo to remoterepo

git merge <branchname> --------> to merge the files from other


branches to master branch (first switch to master)

maven commands:
---------------
mvn clean install -------> to clean the old build files and build
new artifact

ansible commands:
-----------------
syntax to ad-hoc commands:
---------------------------
ansible <clients> <module> <module arguments>

ex: ansible web01 -m yum -a "name=nginx


state=installed" --become (--become=run as root)

ansible web01 -m yum -a "name=java-1.8.0-


openjdk -y state=installed" --become

ansible all -m get_url -a "url=<tomcat url>


dest=/root"
ansible all -m unarchive -a "src=<tomact
path> dest=/root remote_src=true"

ansible all -m shell -a "<any linux commands>

syntax to playbook:
-------------------
ansible-paybook <playbook name>

syntax to roles:
----------------
ansible-galaxy init <role name>

ansible-playbook <playbook name> (call the role in playbook)

docker commands:
----------------

docker image commands:


----------------------
docker images -----> to search images in docker

docker pull <image name> ----> to pull the images from docker-
hub

docker inspect <image name> ----> to display the complete


details of images

docker rmi <image name> ----> to delete the images from docker

docker info -----> gives entire info about docker

docker history <image name> ----> to check the history of


image

docker image prune ----> to delete the unused images from


docker

docker container commands:


--------------------------
docker create <image name> ----> to create container using
local images

docker ps -a -----> to display all containers

docker ps -----> to display running containers

docker create --name <specified name> <image name> ----> to


create container with our specified name

docker rename <container id> <new name> -----> to rename the


container

docker run <image name> ----> to run the container (it


performs pull image, create container, run container)

docker run -d -p 80:80 nginx ----> to run container on detach mode


and particular port number (-d=detach mode, -p=port number)

docker exec -it <container name> /bin/bash ----> to enter into


the container

docker start <container id> -----> to start container

docker stop <container id> -----> to stop container

docker stats <container id> -----> to check the stats of


container

docker rm <container id> -----> to delete container

docker data management:


-----------------------
docker run -d --mount type=bind,src=<path we want>,target=/var -p
80:80 nginx ------> to save the data of a container in our own location

docker volume create <name of volume> -----> to create a


volume in docker home

docker run -d --mount src=<volume name>,target=/var -p 80:80 nginx


------> to save the data of a container in docker home location

docker run -d --mount type=tmpfs,target=/var -p 80:80 nginx


------> to save the data of a container in temparory location

docker networking commands:


---------------------------
docker run -d --network=bridge -p 80:80 nginx -----> to run the
container in bridge network (bridge network= both host&container ipaddress mapped
internally, we can access either of any ip)

docker run -d --network=none -p 80:80 nginx -----> to run


the container in none network (none network= no interaction b/w host&container
ipaddress, only used for back purpose,data updation)

docker run -d --network=host -p 80:80 nginx -----> to run


the container in host network (host network= only accessed by host ip i.e; ec2
public ip)

kuberntes commands:
-------------------

syntax for commands :


---------------------

kubectl <operation-name> <object-type> <objectname>

ex: kubectl create deploy mynginx --


image=nginx:1.14.2 --replicas=2 -n flip-dev
kubectl rollout undo deployment/nginx:1.14.2

objects in kubernets:
---------------------
namespace(ns), deployment(deploy), services(svc),
daemonset(ds), job, cronjob, statefullset, configmap, secrets, replication
controller, volume, user, role, rolebinding

operations in kubernetes:
-------------------------
create ----> create a resource from a file or from stdin

expose ----> Take a replication controller, service,


deployment or pod and expose it as a new kubernets service

run ----> run a particular image on the cluster

set ----> set specific features on objects (updating)

explain ----> documentation of resources

get ----> display one or many resources

edit ----> edit a resorce on the server

delete ----> delete resources by filename, stdin,


resources and names, or by resources and lable selector

scale ----> set a new size for a deployment, replicaset or


replication controller

rollout ----> manage the rollout of a resorce (degrading)

cluster-info ---> display cluster info

top ----> display resorce(CPU/memory) usage

describe ---> show details of a specific resorce or group


of resorce

logs ----> print the logs of a container in a pod

exec ----> execute a command in a container

You might also like