Linux

Linux Commands

In this section you will learn the Linux commands. To become Linux user or experts you will have to learn the Linux commands. Most of the task in Linux have been accomplished by commands. Here i am presenting basic type of Linux commands.

Logging in to a Linux System

Start from the login screen.
Two types of login screens: virtual console (text-based) and graphical logins.
Login using login name and password.
Each user has a home directory for personal file storage. What is root user and other user, will discuss in detail in next chapter.
Where will I write my command?
You can write your commands either in terminal or Virtual console.
How to open the terminal. Terminal works on X windows (graphical) system.
Application -->System Tools -->Terminal (as redline Arrow showing), in figure below.
Linux Terminal
Linux Terminal

This is defaults terminal screen.
Linux default terminal screen
Linux Terminal

Some important terms in Terminal.
# indicates that you are logged as root.
~ shows your present home directory.
Linux default terminal screen
Linux Terminal

$ indicates that you are logged as normal user.
Linux Terminal for normal user
Linux Terminal for normal user

You will write any command after the # or $ sign.

Switching between virtual consoles and the graphical environment.

The root user

User switching Command

su (Switching Users)
Description: This command is used to switch the user, In Linux you no need to logout to change the username, just type su username then press enter key. If you are normal user, want to switch as root (superuser) then just type su . as shown in figure below.
Linux Terminal switching user
Switching user

If want to change user root to mohit (normal user) use command.
[root@localhost ~]# su mohit

Next prompt would be
[mohit@localhost ~]$
Now you will be thinking that there is no need of password because root user does not need any password to switch as normal user.

Simple Linux Commands

All commands should be written after [root@localhost ~]# this prompt.
[root@localhost ~]# date To display date and time
The date command also can be used to set the time and date. To set the time manually, do this:
[root@localhost ~] # date -s "21:46:00"
or
[root@localhost ~] # date -s "21:52:00 1 April, 2015" See the figure below
Linux date setting
Linux date command

If you want to display the calendar use command cal as shown in figure.
Linux calendar  command
Linux calendar command

if you specify the year after cal command, it will display full calender.


Absolute and Relative Pathnames

Absolute path is begin with forward slash ( / ). absolute path contains the root directory and all other subdirectories that contain a file or folder.
Relative path It is not begin with forward slash. The location of file or folder is relative to your current working directory.
A command has many options or switches written with command after - (hyphen)



Many levels of help

In Linux OS there are many type of help available for command learning.
The first is

whatis

[root@localhost ~]# whatis command
This whatis command display the short descriptions of commands.
Example shown below.
Linux whatis  command
Linux whatis command

man

[root@localhost ~]# man command
This man command provides the manual page of command. The man give the details specified command with its options. When manual page is open you can press key q to get back to terminal.


Linux Directory Commands

In Linux OS, there are variety of command are available in the context of directory operation.

cd

cd changes directories
To an absolute or relative path:
# cd cd /var/www/html
# cd www/html

Example shown below
Linux cd  command
Linux cd command

To a directory one level up:
[root@localhost ~] # cd ..

To your home directory:
[root@localhost ~] # cd

To your previous working directory:
[root@localhost ~] # cd -

To know current working directory:
[root@localhost ~] # pwd
See the example below
Linux directory   command
Linux directory command

Creating and Removing Directories in Linux

mkdir creates directories
# mkdir /game
# rmdir /game removes empty directories.
# rm -r recursively removes directory trees

Listing Directory Contents

ls command lists the contents of the current directory or a specified directory.
Syntax
ls [options] [dir]
Here i am presenting important options of ls in order see all options of ls see man page of ls command.
  • -a (all) - Lists all files in the directory, including hidden files
  • -l (long) - Lists details about contents, including permissions (modes), owner, group, size, creation date
  • -r (reverse) - Lists the contents of the directory in reverse sort order.
  • -R (recursive) -Lists the contents of all directories below the current directory recursively.
  • -S (size) -Sorts files by their sizes
  • -i for inodes
Linux directory   command
Linux directory command
Rest of command you see next page.





admin