If you are a Linux user then Linux commands are something that you should learn. You may ask why, and the answer is, knowing commands makes you more productive with Linux, it is quicker and offers more control. Tasks that may require many steps in GUI can be done with a single command. Also, you do not need to learn new commands for different Linux distribution
In this blog, you will learn all the commands that you should know to get comfortable with the terminal.
To start let’s first understand some basic terms:
Command Line Interface ( CLI ): A CLI is a text-based user interface to run programs.
Shell: A shell is a piece of software that interprets typed commands and runs them.
Terminal: A terminal is software that a shell program runs inside of.
What are commands?
Commands are programs that are available on a system. When we run a command, the system takes some specific action. Most of the commands have a short name.
General command syntax:
command option(s) argument(s)
We don’t always need to have options and arguments.
The option tells the command how to operate.
ex:
ls -l
ls -a -l
ls -alh
Here -l is an option. We can have the option of single characters starting with a dash(-), and multiple single-character options can be written together as shown above in the third command. Options with more than one alphabets start with two dashes(—) and those options cannot be written along with other options.
You can use —help option to know details about some commands.
The argument is where we tell the command what to operate on.
ex:
ls -l ./Documents
Here ./Documents is an argument.
File system in Linux:
In the above image shivam is the username, ASUS is the hostname and ~/Desktop is the present working directory.
It is good to know the following directory to get a better understanding of how the commands are working.
- Root user’s home directory:
/root
- User’s home directory:
/home
- Common configuration files reside in:
/etc
- Common programs and commands in:
/bin,/sbin
- Shared libraries and modules:
/lib
- Shared location for mounting other file systems:
/mnt,/media
- Kernel and system information:
/dev,/proc, and/sys.
Some useful keyboard shortcuts:
Up and Down arrow keys: Using the up arrow key you can get previously written commands.
Tab: It comes very handy while writing arguments in a command if there is some directory with a long name then you can press the tab after writing some of the starting portions of the command if that portion uniquely matches with some directory then the tab will autocomplete it for you.
Tab-Tab: In case you remember only some initial characters of a command, then pressing the tab twice will give a list of commands starting with those characters.
Ctrl-A: Move to the beginning of the line.
Ctrl-E: Move to the end of the line.
Ctrl-Shift-C: Copy text to the clipboard.
Ctrl-Shift-V: Paste text from the clipboard.
Let’s start to look into commands now:
COMMANDS:
man: This command is used to open the manual of any other command.
ex: on typing command
man ls.
pwd: This command is used to know the present working directory.
ls: Lists directory contents.
We can use various useful options with the ls command.
ls -l: Here -l will tell the ls command to use the long listing format.
ls -a: Here -a will tell the ls command to show all the files including hidden, files that start with ‘.’ are hidden files.
ls -R: Here -R will tell ls to show all the files recursively i.e. everything that is present in the directory will be printed in the output. If there is a folder inside the current working directory and it has some files inside it, then even those files will be printed as output in this case.
mkdir: This will help to create directories
In the above image, we can see that when the directory is not empty we cannot delete it.
In the above image, we can see that we copied the abc.txt file from the Desktop to the newFolder folder present on the desktop.
mv: This command can be used to move files between different directories. This command can also be used to move files to different directories with different names, which we can also use to rename files.
In the above image, we can see that abc.txt was present in the Desktop directory but after using the command rm abc.txt, it is not there anymore. Similarly, we can see newFolder folder in the Desktop directory with mno.txt file inside it, using the command rm -r newFolder folder newFolder is not there anymore.
find: This command can be used to search files or folders using options as filters. You can explore this command using man.
su: This command can be used to substitute the user. One of the uses of switching users is to do system administration tasks.
There are generally two kinds of users, Normal users, and Superusers.
Super Privileges
- The root is often disabled on the modern Linux system.
- Admin can borrow the root’s privilege using the sudo command.
sudo: Root privileges can be borrowed using sudo command followed by a password verification.
File Permissions
For every file, there are permissions details for three types of users:
- user (owner of the file)
- group (collection of users for whom we can define specific actions)
- others (all other users)
When we write command stat with some file name then we get the details of access related to that file.
In the above image, we can use that, the first user in one.txt had permission to read and write only, but after using the command chmod u+x one.txt it also gets permission to execute.
chown: This command can be used to change the file’s owner. This command needs root permission to run.
If we would not pass any option with the command then the link will be a hard link.
One thing to note with the soft link is that if we change the location of the file to which the pointer points to then the pointer would not give the correct output or even if the location of the pointer file gets changed, in that case also it would not work.
Commands to read text
cat: This command displays the contents of one or more files without having to open the file for editing.
tail: This command is similar to the head command but the only difference is that it will print the last lines.
If you have any suggestions, please write them in the comment section. I would love to add it to the blog.
SOCIAL SHARE CARD GENERATOR