0% found this document useful (0 votes)
9 views56 pages

here i did masters in linux commands

This document provides a comprehensive overview of various Linux commands, including file and directory management, text editing, and user management. It covers commands for creating, deleting, and modifying files and directories, as well as commands for managing user accounts and permissions. Additionally, it includes examples of using commands like grep, sed, and zip for text processing and file compression.

Uploaded by

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

here i did masters in linux commands

This document provides a comprehensive overview of various Linux commands, including file and directory management, text editing, and user management. It covers commands for creating, deleting, and modifying files and directories, as well as commands for managing user accounts and permissions. Additionally, it includes examples of using commands like grep, sed, and zip for text processing and file compression.

Uploaded by

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

ADVANCE

LINUX
COMMANDS

Divya jayaraman
mkdir <directory name> - The mkdir command is
used in Unix-based operating systems to create a
new directory.

rmdir <directory name> - The rmdir command in


Linux is used to remove empty directories.

date - The date command in Linux is used to display


current date and time.
cal -The cal command in Linux is used to display a
calendar.

whoami - The whoami command in Linux is used to


display the username of the current user.

pwd - The pwd command in Linux stands for "print


current working directory.
ls commands:
ls - The ls command in Linux is used to list the
contents of a directory.

ls -l - This command lists files and directories in the


current directory in long format. It provides detailed
information about each file or directory, including
permissions, number of links, owner, group, file size,
timestamp, and name.
ls –lr - The command ls -lr in Linux is used to list files
and directories in a long format (-l) and sort them in
reverse order (-r).

ls –lt - To list files and directories arranged according


to their timestamp (modification time), you can use the
ls command with the -t option.

ls –ltr - The command ls -ltr in Linux is used to list


files and directories in long format (-l), sorted by
modification time (-t) in reverse order (-r).
ls –a - The command ls -a in Linux is used to list all
files and directories, including hidden ones.

Create File:

touch <filename> - The touch command in Linux is


used to create new empty files.

touch<file1><file2><file3>-The command touch is


used to create multiple files at the same time.
ddeelelteethte efilets he files
rm –r <filename> - The rm command with the -r
option is used to recursively remove directories and
their contents, not individual files .To remove a single
file, you do not need to use -r.

rm* - The command rm* is potentially dangerous


because it attempts to delete all files in the current
directory.
rm<filename>-The rm command in Linux is used to
remove files.

rm f*- The command rm f* in Linux is used to delete all


files in the current directory whose names start with the
letter f.

rm -rf <directory name>- The command rm -rf directory_name


is used to forcefully and recursively remove a directory and all
its contents, including subdirectories and files.
change directory
cd <directory name> - The cd command in Linux is
used to change the current working directory.

cd.. - This command moves the current working


directory up one level to its parent directory.

cd~- The command cd ~ is used to navigate to the


home directory of the current user
History commands:
history - The history command in Linux is used to
display a list of previously executed commands from the
current shell session.

history 10 - To display the last 10 commands from your


command history in Linux.
history c - The command history -c in Linux is used to
clear the current shell session's command history.

Write a command in linux file:


cat>filename - The cat command in Linux is used to
display the contents of a file.

cat>>filename - The cat >> filename command in


Linux is used to append text to file named filename.
cat <filename> - The cat filename command in Linux is
used to display the contents of a file n filename directly
in the terminal.

cat –n <filename> - The command cat -n filename in


Linux is used to display the contents of a file
(<filename>) with line numbers added to each line.

cat filename1 filename2 filename3 >> filename4 - The


command cat filename1 filename2 filename3 >>
filename4 in Linux is used to concatenate (combine)
the contents of filename1, filename2, and filename3
and append them to filename4.
cat<filename> | grep ls- The command cat filename |
grep ls displays lines from filename that contain the
string ls.

mv commands
mv<old directory name> <new directory name> - To
rename a directory in Linux using the mv command.

mv<old filename> <new filename> - To rename a files in


Linux using the mv command.
mv<file name> <destination directory path> - To move
a file to a specific destination directory in Linux using
the mv command.
.

mv<directory name> <destination directory path> - To


move a directory (folder) to a specific destination
directory.

mv<filename> <directory>- The command mv


<filename> <directory> moves the specified file to the
target directory
mv<multipledirectories> <directory>- The command
mv <multiple directories> <directory> moves multiple
directories into a single target directory.

Text Editor :

Window (notepad) – GUI text editor


Linux(vi, nano) – CLI text editor

nano <filename> - This command opens the nano text


editor with the file sample.txt.

Save - ctrl+o exit - ctrl+x


vi <filename> - This command opens the vi text editor
with the file (file1).

SED COMMANDS(stream editor):


sed ‘s/wrong word/correct word’ filename- to perform a
substitution of text in a file but that will not make change
in original file.
sed -i ‘s/wrong word/correct word/’ <filename> - It will
change the wrong word into correct word without
opening the text editor it will make changes in original
file.

sed –i ‘$d’ <filename> - The command sed -i '$d'


<filename> specifically removes the last line of the file.
sed –i ‘2d’ <filename> - The command sed -i '2d'
<filename> is used to delete the second line of a file in
place using the sed stream editor.

sed –i ‘2,$d’ <filename> - The command sed -i '2,$d'


<filename> is used to delete all lines from the second line
to the end of the file in place using the sed stream editor.
GREP COMMANDS (global regular expression print)
grep “ls” <filename> - This command for search for a
word or letter in the file.

grep –i “ls” <filename> - The command grep -i "ls"


<filename> is used to search for a specific pattern in a
file while ignoring case sensitivity.
grep –c “chanda” <filename> - The command grep -c
"chanda" <filename> is used to count the number of
lines in a file that contain a specific pattern .

grep –v “chanda” <filename> - The command grep -v


"chanda" <filename> is used to display all lines in a file
except that specific word “pattern”.
grep –n “chanda” <filename> - The command grep -i -n
"chanda" <filename> is used to search for a specific
pattern in a file and display the matching lines along
with their line numbers without any case sensitive.

grep -i –c “CHANDA” <filename> - The command grep


-i -c "CHANDA" <filename> is used to count the
number of lines in a file that contain a specific pattern
without any case sensitive..
grep -i -v “KIM TAEHYUNG” <filename> - The
command grep -i -v "KIM TAEHYUNG" <filename> is
used to display all lines in a file except that specific word
“pattern” without any case sensitive.
grep -i -n “chanda” <filename> - The command grep -i
-n "chanda" <filename> is used to search for a specific
pattern in a file and display the matching lines along
with their line numbers without any case sensitive.

cat <filename> | grep “specific word”- The command


cat file2 | grep chanda displays lines from file2 containing
the word "chanda".
cat <filename> | grep -c “specific word”- The command
cat file2 | grep -c "chanda" counts and displays the
number of lines in file2 that contain the word "chanda".

cat <filename> | grep -v “specific word”-The command


cat file3 | grep -v "chanda" displays all lines from file3
except those containing the word "chanda".
cat <filename> | grep -n “specific word”- The command
cat file3 | grep -n "chanda" displays lines from file3 that
contain the word "chanda" along with their line numbers.

copy the file and directory


cp <filename1> <filename2>- The command cp file1
file2 copies the content of file1 to a new file named file2.
If file2 already exists, it will be overwritten.
cp <filename> <directoryname>- The command cp file1
aws/ copies the file file1 into the aws/ directory.

cp -r <directory name> <directory name>- The


command cp -r aws/ aws1/ recursively copies the
directory “aws/” and all its contents into a new directory
named “aws1/”.

cp <filename> <new filename>- The command cp file1


docker.txt will copy the contents of file1 to a new file
named docker.txt, if it does not exist means it will
automatically create an new docker.txt file.
cp<filename> <directroyname>/<filename>- The
command “cp file1 aws/file1”copies the file “file1” into
the “aws/” directory, renaming it as file1 within that
directory.

cp * <directroyname>/ - The command cp * demo/


copies all files in the current directory into the directory
named demo/.
zip commands:
zip <directoryname>.zip *- The command zip devops.zip
* creates a compressed ZIP file named devops.zip
containing all the files in the current directory. It does
not include subdirectories unless explicitly specified.

zip -sf <zipfilename>- The command zip -sf devops.zip


lists the contents of the ZIP file without extracting them
zip <zipfile> <newfilename>- The command zip
devops.zip chan.txt adds the file chan.txt to the existing
ZIP archive devops.zip

zip -d <zipfile> <delete filename>- The command zip -d


devops.zip hell.txt deletes the file hell.txt from the ZIP
archive named devops.zip.
zip -e <zipfilename> *- The command zip -e devops.zip *
creates a password-protected ZIP file named devops.zip
containing all files in the current directory. You will be
prompted to enter and confirm a password.

unzip <zipfile>- The command unzip devops.zip extracts


the contents of the ZIP archive named devops.zip into
the current directory.
word count commands:
wc -l <filename>- The command wc -l file1 counts the
number of lines in the file named file1 and displays the
count.

wc -w <filename>- The command wc -w file2 counts the


number of words in the file named file2 and displays the
count.
wc -c <filename>- The command wc -c file1 counts the
total number of bytes (characters) in the file named file1
and displays the count.

wc <filename>- The command wc file1 displays the line


count, word count, and byte (character) count of the file
file1.
head and tail commands:
head <filename>- The command head file1 displays the
first 10 lines of the file named file1 by default

head -n <no> <filename>- The command head -n 5 file1


displays the first 5 lines of the file named file1

tail <filename>- The command tail file1 displays the last


10 lines of the file named file1 by default.
tail -n <no> <filename>- The command tail -n 3 file1
displays the last 3 lines of the file named file1.

find commands:
find -name <filename>- The command find -name file1
searches for a file named file1 in the current directory
and its subdirectories.

find -name <filename>- The command find -name


ansible.txt searches for a file named ansible.txt in the
current directory and display the path of the file .
softlink and hardlink commands:
ln -s <filename> <filename link>- The command ln -s
<filename> <filename_link> creates a soft link
(symbolic link) to the specified file.

ln <filename> <filename_link>- The command ln


<filename> <filename_link> creates a hard link
(symbolic link) to the specified file
root user commands:
sudo su - The command sudo su allows a user to switch
to the root user (superuser) with administrative
privileges.

useradd <username> - The command useradd dev is


used to create a new user account named “dev” in a
Linux system.

cat /etc/passwd- The command cat /etc/passwd displays


a list of all users on the Linux system, with detailed
information about each user account.
passwd <username> - The command passwd chanda is
used to change the password for the user account named
“chanda” on a Linux system

su <username> - The command su prem is used to


switch to the user account named “prem” on a Linux
system.
cat /etc/group - The command cat /etc/group displays
the contents of the /etc/group file, which contains
information about all the groups on the Linux system.

remove user commands:

userdel <username> - The command userdel prem is


used to delete the user account named prem from the
Linux system but home directory will not be deleted.
userdel <username> --remove - The command userdel
dev --remove (or equivalently userdel dev -r) is used to
delete the dev user account and remove the associated
home directory and files.

rename useraccount commands:


usermod -l <new name> <existing name> - The
command usermod -l harinimala harini is used to rename
a user account in Linux but this new name is not
changed in homedirectory.
mv <existing name> <new name> - The command mv
harini harinimala is used to rename a file or directory in
Linux. In this case, it is renaming the file or directory
named harini to harinimala.

id <particular username> - The command id harinimala


is used to display information about the user named
harinimala on a Linux system.

groupmod -n <newname> <exiting name> - The


command groupmod -n harinimala harini is used to
rename a group in Linux. Specifically, this command
renames the group harini to harinimala.
add user in group command:
groupadd <groupname> - The command groupadd
devopsTraining is used to create a new group named
devopsTraining in a Linux system

sudo gpasswd -a <addusername> <groupname> - The


command “sudo gpasswd -a ravi ec2-user” is used to
add the user ravi to the group ec2-user on a Linux
system.
sudo gpasswd -d <username> <groupname> - The
command “sudo gpasswd -d ravi ec2-user” is used to
remove the user ravi from the group ec2-user on a Linux
system.

sudo lid -g <groupname> - this command used to list all


user in group

sudo usermod -aG <groupname><username> - The


command sudo usermod -aG ec2-user ravi is used to add
the user ravi to the group ec2-user in Linux.
file permission commands:

sudo chmod u+x <filename>- The command “sudo


chmod u+x demo.txt” adds execute permission for the
file owner (user) on demo.txt.

sudo chmod u-w <filename> - The command “sudo


chmod u-w demo.txt” removes the write permission for
the file owner (user) on demo.txt.
sudo chmod u-rwx <filename> - The command sudo
chmod u-rwx demo.txt removes read (r), write (w), and
execute (x) permissions for the file owner (user) on
demo.txt.

sudo chmod g+w <filename> -The command sudo


“chmod g+w demo.txt” adds write permission for the
group (g) on the file demo.txt.

sudo chmod o+w <filename> - The command


sudo chmod o+w demo.txt adds write permission
for others (o) on the file demo.txt.
numeric permissions commands:

sudo chmod 000 <filename> -The command “sudo


chmod 000 demo.txt” removes all permissions (read,
write, and execute) for user, group, and others on the
file demo.txt.

sudo chmod 111 <filename> -The command “sudo


chmod 111 demo.txt” sets execute-only permissions for
the user, group, and others on the file demo.txt.
sudo chmod 110 <filename> -The command “chmod
110 demo.txt” sets execute-only permissions for the
user and group, and no permissions for others on the
file demo.txt.

sudo chmod 222 <filename> The command “sudo


chmod 222 demo.txt” sets write-only permissions for
the user, group, and others on the file demo.txt.

sudo chmod 102 <filename> - The command “chmod


102 demo.txt” sets execute-only permissions for the user,
no permissions for the group, and write-only permissions
for others on the file demo.txt.
sudo chmod 444 <filename> -The command “sudo
chmod 444 demo.txt” sets read-only permissions for
the user, group, and others on the file demo.txt.

sudo chmod 421 <filename>- The command “chmod


421 demo.txt” sets the following permissions: read for
the user, write for the group, and execute for others on
the file demo.txt.
add the premission:
sudo chmod 630 <filename>- The command “sudo
chmod 630 demo.txt” sets read and write permissions
for the user, write and execute permissions for the
group, and no permissions for others on the file
demo.txt.

sudo chmod 777 <filename> -The command “sudo


chmod 777 demo.txt” sets full permissions (read,
write, and execute) for the user (owner), group, and
others on the file demo.txt.
ownership commands:
sudo chown <new username> <filename> - The
command “sudo chown prem docker.txt” changes
the ownership of the file docker.txt to the user prem.

sudo chown :<groupname> <filename> - The command


“sudo chown :devops docker.txt” changes the group
ownership of the file docker.txt to the group devops
sudo chmod <username>:<groupname> <filename> -
The command “sudo chown ec2-user:ec2-user
docker.txt” changes both the user ownership and the
group ownership of the file docker.txt to ec2-user.

package install commands:

sudo yum install <software> - The command sudo yum


install git is used to install the Git version control system
on a Linux system that uses YUM (Yellowdog Updater,
Modified) as its package manager, such as CentOS,
RHEL, or Fedora.
top -top command is used to display a real-time,
dynamic view of system processes and resource usage
in Linux.

kill- The kill command in Linux is used to terminate


processes by sending them specific signals.
lastlog - The lastlog command in Linux is used to
display the most recent login information for all
system users.

last -3 - The last -3 command displays the last 3 login


sessions from the system login history.
uname -a - The uname -a command in Linux displays
detailed information about the system and kernel.

ifconfig - The ifconfig command is used to view and


manage network interfaces in Linux systems.
sudoers file commands:
ec2-user have root permission because of that ec2-user can
add raja as root user but raja doest not have root permission so
he cant create ot add another root user (to add raja as root
user we need to add raja name in sudoers file crt this sentence

when ec2-user trying to create an rootuser(raja)

when raja trying to create an another rootuser


sudo lid -g wheel <groupname> - The sudo lid -g wheel
command is used to list all the members of the wheel
group on a Linux system.

sudo lid -g wheel - The sudo lid -g wheel command is


used to list all the members of the wheel group on a
Linux system.
sudo cat /etc/passwd - The command sudocat/etc/passwd
displays the contents of the /etc/passwd file, which
contains user account information on a Linux system.

sudo visudo - The sudo visudo command is used to safely


edit the /etc/sudoers file in Linux. This file defines which
users or groups can execute commands as the superuser
(root) or other users using sudo.

You might also like