Abhishek S. Sharma
Posted on August 22, 2020
Forget your bird, Love Linux
Click on playground and roll on your sleeves :c) -
There are four types of the shell, we have in Linux-
- Broune Shell -Sh shell
- C Shell - csh or tcsh
- Z shell -zsh
My Favorite - Bourne again shell -bash
-
To check shell type-
echo #SHELL
-
To print on the terminal
echo Hi from terminal !!
-
To view the current directory, display absolute path, means path from the root
pwd
-
To view all the files in a directory, -a will display hidden files as well
ls
ls -a -
To change directory, it is case-sensitive, and you have to type in the name of the folder exactly as it is.
cd .. - To go back from a folder to the folder before that
cd my_directory - to goto my_directory folder -
When folder name has space e.g. my bird
cd my\ bird
-
Create a new directory
mkdir abhishek
-
When folder name has a space e.g. abhishek sharma
mkdir abhishek\ sharma
-
make directory hierarchy from one command
mkdir -p /dir_1/dir_2/dir_3/dir_4
-
Run multiple commands in a single line
cd abhishek\ sharma; mkdir devops_tools; ls
-
Create a file
touch file_1.txt
-
Write content in the file
cat > file_1.txt
write anything, write- "this is my first file in Linux" and type Ctrl+d to save
-
another way to do it
echo "this is my first file in linux" > file_1.txt
-
View content
cat file_1.txt
-
Remove directory and file commands
mkdir removable_dir
rmdir removable_dir
mkdir removable_dir
cd removable_dir; touch removable_file.txt
rmdir removable_dir
---it gives you an error -
Notes: only blank directories can be deleted with rmdir; to delete a directory, which has content in it, we will use rm -r
rm -r removable_dir
-
To delete a file
rm file_1.txt
Copy commands-
-
Copy a file to another file
cp {options} source_file target_file
cp new_file.txt copy_file.txt -
Copy File(s) to another directory or folder
cp {options} source_file target_directory
touch /dir_1/dir_2/file_4.txt
cp -v /dir_1/dir_2/file_4.txt /dir_1/dir_2/dir_3/dir_4 -
Copy directory to directory
cp {options} source_directory target_directory
-
To copy a directory from one place to another use -r or -R option in cp command
cp -r /dir_1/dir_2/dir_3/dir_4 /dir_1/dir_2/
-
If the destination directory already has the same file, still you want to copy that file, to overwrite it use *-i*
cat > dir_1/dir_2/file_4.txt - this is me. press ctrl+d
cp -i /dir_1/dir_2/file_4.txt /dir_1/dir_2/dir_3/dir_4 -
Move command- mv command to move the files one place to another
touch dir_1/dir_2/file_3.txt
mv -v dir_1/dir_2/file_3.txt dir_1/dir_2/dir_3 -
Rename filename
touch latest.txt
-
want to change this file name latest to new
mv latest.txt new.txt
rm latest.txt -
Search something
locate new.txt
-
if you want to ignore the case
locate -i New.txt
-
if you want a file that has the word "this"
locate -i this
-
If you want the file(s) that has words "this" and "me"
locate -i *this*me
To view available disk space
df
above command will show disk space in KB, to view in MB use the following command
df -m
-
To view disk usage by files
du
-
to view disk space used by a directory
du dir_1
-
To view Linux distro
uname
uname -a -
Package manager apt-get
sudo apt-get update
sudo apt-get install nginx -y -
To view your IP and name in host or network
hostname
hostname -I -
To know your user account
whoami
-
To view user id, group id, group etc.
id
-
Download a file from a link
curl www.randomlink.com/downloadable-file.txt -O
OR
wget www.randomlink.com/downloadable-file.txt -O downloadable-file -
Service start/stop/enable/disable/restart/status
systemctl status nginx
systemctl restart nginx
systemctl stop nginx
systemctl status nginx
systemctl start nginx
systemctl disable nginx
systemctl enable nginx -
To check connection to server
ping {ip address}
ping www.google.com
Bonus to read
- Write clear to clean the terminal.
- to autofill use TAB. Suppose you have a folder- my_folder and want to go to that folder, You just need to type cd my and then TAB and the terminal fills the rest up and makes it cd my_folder.
- To stop a command write Ctrl+C
- to force stop a command write Ctrl+Z
- Write exit to exit from terminal
Posted on August 22, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.