Hello there ๐.I hope you are doing great . In this article I am going to share the basic commands that you must know to get started with Linux.
Note: This article does not covers every Linux command rather it focuses on the important and useful commands that you will need to use frequently
1.man command
This command acts as a manual. Whenever you don't know how to use a command just type
man <command>
to get the information related to the command.
$ man ls
LS(1) User Commands LS(1)
NAME
ls - list directory contents
SYNOPSIS
ls [OPTION]... [FILE]...
DESCRIPTION
List information about the FILEs (the current directory by default). Sort entries alphabetically
if none of -cftuvSUX nor --sort is specified.
Mandatory arguments to long options are mandatory for short options too.
-a, --all
do not ignore entries starting with .
-A, --almost-all
do not list implied . and ..
--author
with -l, print the author of each file
-b, --escape
print C-style escapes for nongraphic characters
--block-size=SIZE
- ls command
This command is use to list all the folders and files which are present inside a particular folder.
ls <folder name>
main_folder: ls
file.txt folder1 folder2
The above code shows the files and folder which are present inside the main_folder
3.mkdir command
This command is used to make a new directory/folder
mkdir <foldername>
main_folder: mkdir newfolder
The above command will create a new folder name newfolder inside the main_folder.
4.rmdir command
Just like mkdir creates a folder,rmdir is used to delete a folder
rmdir <foldername>
main_folder: rmdir newfolder
5.pwd command
whenever you feel lost or if you want to know in which directory you are just use pwd command.
main_folder: pwd
/mnt/c/Users/Rahul Kumar Yadav/main_folder
- touch command
This command is used to create empty file.
main_folder:touch cherry.txt
The above command creates cherry.txt file in the main_folder. If the file already exists this command will open the file in write mode.
- cp This command is used to copy the file.
main_folder:cp cherry.txt another_folder
The above command copies cherry.txt to folder named another_folder
Note:To copy folders you need to add -r tag.
Example:To move the folder named pen into another folder named class,you can do this.
cp -r <foldername> <destination folder>
8.mv command
This command is used to move a file from one folder to another folder.
Example:To move a file named cherry.txt to another folder named another_folder you will need to do this
main_folder:mv cherry.txt another_folder
Note : mv can also be used to rename a file,where the first argument is the current file name and the second argument is the new file name.
Example:To rename a file named cherry.txt to mango.txt you can do this
main_folder:mv cherry.txt mango.txt
9.echo command
This command is used to print the string on the terminal
main_folder:echo hello
hello
10.history command
This command is used to see the history of all the commands we have used till now.
main_folder:history
11.chmod
The files present in the Linux/macOs have 3 permissions :Read,Write,execute.
To see the permissions of a file just use the command ls -al <filename>
example
main_folder:ls -al mango.txt
-rwxrwxrwx 1 itzrahulyadav itzrahulyadav 0 Oct 5 22:56 mango.txt
The weird letter combinations that you see above are rwx where r means read,w means write and x means execute.
chmod 777 mango.txt
The above command gives the read ,write and execute permissions to the owner of the file,for the members of the group owning the file and for the other users.
Here's a quick overview:
0 = no permission
1 = execute
2 = write
4 = read
In short if you want to provide only read permissions - use 4.
If you want to provide read and write operations use 6 which is equal to 4(read) + 2(write) .
If you want to provide read,write and execute commands use 7 which is equal to 4(read) + 2(write) + 1(execute)