Mastering Linux CLI Commands: Boost Your Productivity and Efficiency!
Photo by Gabriel Heinzer on Unsplash
Table of contents
No headings in the article.
To print the word, we entered the
echo
command. This command is usually used for printing environmental variables.To list all the contents of the directory –
ls
To change directory –
cd
To print the directory, you are currently in –
pwd
To create a new directory –
mkdir < new-directory>
To use multiple commands together, done by separating each command with a semicolon. For example,
cd new_dir; mkdir blues; pwd
To make Directory Hierarchy like this
/tmp/Asia/India/Bangalore
Instead of doing this:-
mkdir /tmp/Asia
mkdir /tmp/Asia/India
mkdir /tmp/Asia/India/Bangalore
We can create it in a single shot by:-
mkdir -p /tmp/Asia/India/Bangalore
To remove a directory,
rm -r
To copy a directory from one location to another
cp -r my_dir1 /path-of/my_dir1
To create a new file with no contents
touch new_file.txt
Add contents to the file.
cat > new_file.txt
To exit and save the file use CTRL + DTo view the contents of the file
cat new_file.txt
To copy a file
cp new_file.txt copy_file.txt
To move or rename the file.
mv new_file.txt sample_file.txt
To remove or delete a file.
rm new_file.txt
To check free space in Linux
df -h
( For a more human-readable format)to check the free space for the root file system ("/"), you can run:
df /
To know which user, you are –
whoami
To know more info about
user – id
To search for a specific pattern in files -
grep
To switch from one user to another –
su
If you are accessing one system from another system using ssh & want to login to another system using a different user than the current user -
ssh <username>@<hostname>
Every Linux system has a super user known as the root user. The root user has no restrictions on the system. When we use the command :
ls /root
, it will show permission denied.A root user can grant regular users some sudo privileges by making an entry into the sudoers file. When we use
sudo ls/root
after putting the right password you will see the output i.e., in this case is snap.Remember to add
sudo
prefix when writing the command. WHENEVER YOU GET A PERMISSION DENIED ERROR ON LINUX, IT MIGHT BE CAUSED BY NOT USING THE SUDO PREFIX BEFORE THE COMMAND.To download files from the internet, commands that will be used are:-
curl http://
www.some-site.com/some-file.txt
-O
Here-O
is used to save the result to a file.Another way to download files from the internet
wget -O some-file.txt
Here some-file.txt is used to store files locally.To check on which O.S. you are working use this
ls /etc/release
To see more details about the OS
cat /etc/release