Linux Main
Linux Main
#Basic_Linux_commands:
Listing commands
ls option flag arguments --> list the sub directories and files available in the present directory
hashtag#Examples:
ls -l--> list the files and directories in long list format with extra information.
ls -a --> list all including hidden files and directory.
ls *.sh --> list all the files having .sh extension.
ls -i --> list the files and directories with index numbers inodes.
ls -d */ --> list only directories. (we can also specify a pattern).
hashtag#Directory_commands
pwd --> print work directory. Gives the present working directory.
cd path_to_directory --> change directory to the provided path
cd ~ or just cd --> change directory to the home directory
cd - --> Go to the last working directory.
cd .. --> change directory to one step back.
cd ../.. --> Change directory to 2 levels back.
mkdir directoryName --> to make a directory in a specific location.
Examples:
1. mkdir newFolder # make a new folder 'newFolder'
ls -l--> list the files and directories in long list format with extra information.
ls -a --> list all including hidden files and directory.
ls *.sh --> list all the files having .sh extension.
ls -i --> list the files and directories with index numbers inodes.
ls -d */ --> list only directories. (we can also specify a pattern).
Directory commands
pwd --> print work directory. Gives the present working directory.
cd path_to_directory --> change directory to the provided path
cd ~ or just cd --> change directory to the home directory
cd - --> Go to the last working directory.
cd .. --> change directory to one step back.
cd ../.. --> Change directory to 2 levels back.
mkdir directoryName --> to make a directory in a specific location.
Examples:
Pwd: This command will print your directory location, where you currently working.
Cat: This is used to concatenate and display files on the terminal. It can also be used
to modify existing ones.
Vim: This is a text editor used in Linux. It stands for “Vi Improved”.
Mostly used modes in VIM:
Normal mode: This is the default mode in which vim starts. In normal mode, you can
use various commands to navigate and edit the text.
Insert mode: In insert mode, you can type text into the file. To enter insert mode,
press the "i" key. To exit insert mode and return to normal mode, press the "Esc" key.
Command mode: In command mode, you can enter commands to perform various
actions, such as saving the file or quitting vim. To enter command mode, press the ":"
key.
Grep: This command searches for a particular string/ word in a text file. This is similar to
“Ctrl+F” but executed via a CLI.
Sort: This command is used to sort the results of search either alphabetically or numerically.
It also sorts files and directories.
sort -r: the flag returns the results in reverse order.
sort -f: the flag does case-insensitive sorting.
sort -n: the flag returns the results as per numerical order.
Tail: This command prints the last N number of data of the given input. By default, it prints
10 lines.
We can specify the number of lines, that we want to display.
Chmod: This command is used to change the access permissions of files and directories.
For example: Following “chmod” command will give the user permission to read, write and
execute a file.
Chown: This command is used to change the file Owner or group.
ID: This is used to find out user and group names and numeric ID’s (UID or group ID)
of the current user or any other user in the server.
Find: This is used to find files and directories and perform subsequent operations on
them.
In the below command, It will search in the present working directory and its
subdirectories, and print the name of the file that have “.txt” file extension.
File Permissions in Linux
Q1. How to create file permissions?
Q2. How to Check the Permission of Files in Linux
Q3. What are the three permission groups in Linux?
Q4. What are the three kinds of file permissions in Linux?
Q5. Reading the Security Permissions in Linux
Q6. How to Change Permissions in Linux
Let’s dive deeper one by one,
Q1. How to create file permissions?
It will set the boundaries for User, Group, Other User by setting up the only required
permission to them so that the any file or any directories will not be affected.
Letter Definition
r “read” the file’s contents.
Below is a simple script named backup.sh that can be used to backup your files. It will create
a timestamped directory and copy all files in the current directory to that backup directory.
#!/bin/bash
src_dir="/c/Users/csuryawa/chandu"
trg_dir="/c/Users/csuryawa/Backupfile"
backup_filename="backup_$(date +"%Y-%m-%d_%H-%M-%S").tar.gz"
Now, you can run this script whenever you want to back up your work.