Linux Notes 1
LINUX BASIC COMMANDS
COMMANDS:
1. Command used to print a line of text:
echo
Ex: echo “hello world”
2. Command which is used to create a directory:
mkdir
Ex: mkdir online [folder name]
3. To create multiple directories:
mkdir dirname dirname dirname…dirname
4. To create sub directories:
cd dirname ; mkdir dirname
5. To create multiple sub-directories inside a sub-directories:
mkdir -p dir1/sd1/ssd1
6. To list all the files/folders which you have created:
ls
7. To enter into particular
directory: cd (change
directory) Ex: cd
directory_name6 9.Present
working directory:
pwd
8. To clear the terminal:
clear
9. To come out of a particular directory
cd ..
Linux Notes 2
10. To remove a only empty directory
rmdir directory_name
11. To remove a directory which contains files/subdirectories
rm – r directory_name
FILES
1.To create a file:
touch file_name
2.To create multiple files
touch file1 file2 file3 file4
3.To add content in the files = Editors(1. Vi and 2. Nano)
a. vi : This command is used to add content in a particular
file syntax: vi file_name press—>i
<add content> and press—>esc:wq
b. nano : this command is used to add content in a particular
file syntax: nano file_name To save the content ctrl+s
To exit from editor ctrl+x
Linux Notes 3
4. To see/display the content
present in a particular file cat
file_name
5. To remove a particular file
rm file_name
6. To remove multiple files
rm file1 file2 file3 7. To display
calendar cal (for current
month)
8. To display calendar for particular month cal
month year
9. To display all month in a year cal year
10. To display/print the date and time
date
11. To know the information of a particular command
man command
ABSOLUTE PATH AND RELATIVE PATH
1.To change the directory.
2.To move the files/directories from one location to another location.
3.To copy the files/directories from one location to another location.
4.To rename the files/directories
Relative path: Implementing any operation just by denoting directory name
is called relative path.
Linux Notes 4
Example: cd world--->cd india--->cd karnataka
Absolute path: Implementing any operation by denoting the whole
path of a particular directory.
Example: cd/home/ec2/world/india
To move a file from home to a directory:
Syntax: mv file_name directory_name/absolute path of directory
source destination
Three ways of moving home file
1.Using only relative path---mv Hitman dir2
2.Using only absolute path---mv/home/ec2-user/Hitman/home/ec2user/dir2/
3.Using both relative and absolute---mv Hitman/home/ec2-
user/dir2/
To copy a file/directory from one place to the other
Syntax: cp filename Directoryname/absolute path of directory
To copy the main directory which includes sub-directories to a another
directory.
Syntax: cp -r main_directory name directory_name
To rename a file/directory:
Syntax: mv oldfilename new_filename ls -a---> To see the hidden
files/directories ls -lt--->To list the files/directories in order and with
timings they are created.