Linux Basics

Linux Basics Commands

“Shortcuts increase your working productivity and save your time”.

To Open Terminal, press

Ctrl + Alt + T

To Close Terminal. press

Ctrl + Shift + Q

Close Single Terminal Tab, press

Ctrl +Shift + W

To Move Cursor

Open your terminal and type something

To move cursor to beginning of the line, press

Ctrl + A

To move cursor to end of the line, press

Ctrl + E

To move cursor Forward, press

Ctrl + F

To move cursor Backward, press

Ctrl + B

To locks the screen

Ctrl + L

Search previously used commands

Ctrl + R

Show last executed command

Ctrl + P

Text manipulation Shortcuts

CommandsDescription
Ctrl + UCut the line from the terminal, If your are at end of the line
Ctrl + KCut the line from the terminal , If you are beginning of the line
Ctrl + YPaste the copied items
Ctrl + WDelete the word before the cursor and copy to clipboard
Alt + Tchange the position of the words before the cursor
Alt + LTo make a single letter or whole word in Lowercase, at after the cursor
Alt + UTo make a single letter or whole word in Uppercase, at after the cursor
Alt + DTo Delete a single word after the cursor
Alt + .To Print the last words written in previous command
Ctrl + LTo clear the terminal

File Management Commands

CommandsDescription
pwdTo check full path of the current working directory
cdTo change the directory
cd ..To change current working directory to parent directory
ls -lTo list the files and directories in current or present working directory
ls -ldTo list directories
ls -aTo list files including hidden files
ls -ltTo list files sorted by last modified date and time
ls -lhTo list file size in human readable format
ls -lRTo Show all sub-directories recursively
treeTo see the representation of the file system starting from the current directory

File and Directory related commands

To Create file, i am using nano editor to create a file

$ sudo nano <file-name>

To Copy a file

$ cp -p <source-path> <destination-path>

In below example, i have copied redient-security file to Desktop

To Rename a file

$ cp mv <file-name> <new-file-name>

In the below example i have renamed redient-security file to sredient

To Remove or delete file

$ sudo rm <file-name>

To Create Directory

$ sudo mkdir <directory-name>

To Copy Directory

$ cp -R <source-path> <destination-path>

To Remove or delete Directory

$ sudo rm -R <dirctory-name>

To Remove loaded directory with files

$ sudo rm -rf <directory-name>

File & Directory permissions

Now, here we will create one file and change their permissions.

$ sudo nano redient-security

Type some line and save it by pressing Ctrl + x and Y

Now check the file permissions

$ ls -l redient-security

File and directory contains three types permission,
User, Group and Others

Here, -rw is permission for user
-r– is for group
-r– is for others
r = read, w = write, x = execute

Assign and Remove permission on File and Directory

Method is same to change permissions of file and directory

Let’s change the permissions of User

To give read, write and execute permission to user run the below command

$ sudo chmod u=rwx <file-name>

Example:-

If you want to remove read and write permission from the user then run below command

$ sudo chmod u-rw <file-name>

Example:-

If you want to give read only access to user then run the below command

$ sudo chmod u+r <file-name>

In below example, i have removed all permissions from user and assign read only permission

here, ” + ” sign is used for assign permissions and ” – “sign is used for remove permissions
In same way you can assign read, write and execution permissions to user and remove permissions from user.

Assign and Remove permissions from User, Group and Others using Numeric Codes

CodesDescription
0No permissions
1Execute only permission
2Write only permission
3Execute and Write permission
4Read only permission
5Read and Execute permission
6Read and Write permission
7Read, Write and Execute permission

Lets start assigning read only permission to user, group and others

$ sudo chmod 444 <filename>

Example:-

Give read, write and execution to User

$ sudo chmod 744 <filename>

In Same way you can assign permission to User, Group and Others

Let’s change the permissions of Group and Others

To give read and write permission to group run the below command

$ sudo chmod g+rw <filename>

Example :-

To remove read and write permission from group run the below command

$ sudo chmod g-rw <filename>

Example:-

CommandsDescription
chmod g=rwx <filename>assign read, write and execute permission to group
chmod g+rwx <filename>assign read, write and execute permission to group
chmod g-rwx <filename>remove read, write and execute permission from group
chmod g+r <filename>assign read only permission to group
chmod g+w <filename>assign write only permission to group
chmod g+x <filename>assign execute only permission to group
chmod g-r <filename>remove read permission from group
chmod g-w <filename>remove write permission from group
chmod g-x <filename>remove execution permission from group

Assign and Remove permissions from Others

CommandsDescription
chmod o=rwx <filename>assign read, write and execute permission to others
chmod o+rwx <filename>assign read, write and execute permission to others
chmod o-rwx <filename>remove read, write and execute permission from others
chmod o+r <filename>assign read only permission to others
chmod o+w <filename>assign write only permission to others
chmod o+x <filename>assign execute only permission to others
chmod o-r <filename>remove read permission from others
chmod o-w <filename>remove write permission from others
chmod o-x <filename>remove execution permission from others

Leave a Comment

Your email address will not be published. Required fields are marked *

wpChatIcon
    wpChatIcon