Linux Basics Commands
![](https://redientsecurity.in/wp-content/uploads/2022/07/linux-commands-1.png)
“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
Commands | Description |
---|---|
Ctrl + U | Cut the line from the terminal, If your are at end of the line |
Ctrl + K | Cut the line from the terminal , If you are beginning of the line |
Ctrl + Y | Paste the copied items |
Ctrl + W | Delete the word before the cursor and copy to clipboard |
Alt + T | change the position of the words before the cursor |
Alt + L | To make a single letter or whole word in Lowercase, at after the cursor |
Alt + U | To make a single letter or whole word in Uppercase, at after the cursor |
Alt + D | To Delete a single word after the cursor |
Alt + . | To Print the last words written in previous command |
Ctrl + L | To clear the terminal |
File Management Commands
Commands | Description |
---|---|
pwd | To check full path of the current working directory |
cd | To change the directory |
cd .. | To change current working directory to parent directory |
ls -l | To list the files and directories in current or present working directory |
ls -ld | To list directories |
ls -a | To list files including hidden files |
ls -lt | To list files sorted by last modified date and time |
ls -lh | To list file size in human readable format |
ls -lR | To Show all sub-directories recursively |
tree | To 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
![](https://redientsecurity.in/wp-content/uploads/2022/07/Screenshot-from-2022-07-11-15-04-38-1024x107.png)
To Rename a file
$ cp mv <file-name> <new-file-name>
In the below example i have renamed redient-security file to sredient
![](https://redientsecurity.in/wp-content/uploads/2022/07/Screenshot-from-2022-07-11-15-15-53-1024x72.png)
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
![](https://redientsecurity.in/wp-content/uploads/2022/07/Screenshot-from-2022-07-12-10-52-55-1024x83.png)
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:-
![](https://redientsecurity.in/wp-content/uploads/2022/07/Screenshot-from-2022-07-12-11-10-52-1024x80.png)
If you want to remove read and write permission from the user then run below command
$ sudo chmod u-rw <file-name>
Example:-
![](https://redientsecurity.in/wp-content/uploads/2022/07/Screenshot-from-2022-07-12-11-44-46-1024x70.png)
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
![](https://redientsecurity.in/wp-content/uploads/2022/07/Screenshot-from-2022-07-12-11-48-21-1024x109.png)
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
Codes | Description |
---|---|
0 | No permissions |
1 | Execute only permission |
2 | Write only permission |
3 | Execute and Write permission |
4 | Read only permission |
5 | Read and Execute permission |
6 | Read and Write permission |
7 | Read, Write and Execute permission |
Lets start assigning read only permission to user, group and others
$ sudo chmod 444 <filename>
Example:-
![](https://redientsecurity.in/wp-content/uploads/2022/07/Screenshot-from-2022-07-12-12-14-03-1024x72.png)
Give read, write and execution to User
$ sudo chmod 744 <filename>
![](https://redientsecurity.in/wp-content/uploads/2022/07/Screenshot-from-2022-07-12-12-24-07-1024x64.png)
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 :-
![](https://redientsecurity.in/wp-content/uploads/2022/07/Screenshot-from-2022-07-12-12-33-19-1024x64.png)
To remove read and write permission from group run the below command
$ sudo chmod g-rw <filename>
Example:-
![](https://redientsecurity.in/wp-content/uploads/2022/07/Screenshot-from-2022-07-12-12-35-50-1024x70.png)
Commands | Description |
---|---|
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
Commands | Description |
---|---|
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 |