Introduction
This is the 2nd article in this series. In previous article, we saw how to install ubuntu and started with some basic commands. In this post, we will continue our journey and learn few more commands to widen our knowledge.
There are lot of Linux command and you may be using some more than others. Don’t worry if you can not remember the command syntax, me neither. As long as you understand the concepts, you can always search online to find the syntax and related examples.
Check for the distribution
You can check the distribution and version info by using following command:
cat /etc/issue
pwd
pwd (print working directory) shows the current directory (basically, the folder) you’re in.
cd
allows you to change directory.
Typing cd alone without any argument (without anything that follows it) will bring you to the home directory of the user.
cd followed by a dash (–)will bring you to the recent directory you were in.
mkdir
mkdir (make directory) is used to create a directory.
mv
To move files, the command mv (move) is used.
It can also be used to rename things as well!
rm
rm
(remove) removes files.
Notice I combined ls command with rm by using a semicolon.
rm
cannot be used with directories, unless accompanied by -r
flag (short for recursive).
rmdir
(remove directory) can be used with empty directories.
cp
You can use this command to copy files:
by adding -r flag you can also copy directories:
echo
echo prints out whatever you say to it.
You can redirect the output to a file by the following method:
you can use any of the following commands to print the contents of the file:
cat / more / less / head / tail
grep
grep is an extremely powerful tool to search the content of a file. It prints out the line containing the word(s) specified, if it is present in the file. For example.
Piping and Redirection
Pipe
|
(that vertical bar) is called a pipe. It redirects the output of the left command to the input of the right:
Redirection
Redirections are similar to pipe; but instead of passing the output as an input, they save the output to a file, or read the content of a file.
- > saves the output to a file
- < reads the content of a file
Redirection overwrites the files each time it is used. Use appends (>> and <<) should you decide to not overwrite them, and append instead.
Summary
In this post, we learned few more Linux commands and we will resume our journey in next post. Stay tuned and happy coding.
Other Links
- https://fosswire.com/post/2007/08/unixlinux-command-cheat-sheet/
My Recent Books
Discover more from Hex Quote
Subscribe to get the latest posts sent to your email.