Wednesday, August 22, 2018

Linux basic commands

Few linux commands, which we encounter in everyday routine, are displayed below.
command Description

ls This command is used to check the contents of the directory.
pwd This command is used to check the present working directory.And also to verify whether we are in expected directory.
mkdir <dirname> We will work in a separate directory called work in our home directory. Use this command to create a new directory called work in the current folder.
cd <dirname> This command will change our working directory to the newly created directory work.
touch <filename> This command is used to create a new empty file called hello.sh in the current folder.
cp file1 file2 This command is used to copy one file to another file.
mv file1 file2 This command is used to rename a file.
ll This command will display detailed information about files.
ls -a This command is used to see hidden files.
rm file1 This command is used to delete the file.



Note: Hidden files are named starting with . (dot).
So, file1.txt when renamed to .file1.txt will be set as hidden file.

Let us learn a few commands, which are required very often, such as man, echo, cat.

man man

It will show the various types of manual pages displayed by the man command .

From the following table, you can get an idea about various types of man
pages for the same command:
Section number                 Subject area
1                                       User commands
2                                      System calls
3                                      Library calls
4                                      Special files
5                                      File formats
6                                      Games
7                                      Miscellaneous
8                                      System admin
9                                      Kernel routines


man -k passwd // show all pages with keyword
man –K passwd // will search all manual pages for pattern

It is like a manual page to the command.Here it is passwd.
We can get brief information about the command as follows
whatis passwd

Every command we type in the terminal has an executable binary program
file associated with it. We can check the location of a binary file as follows

which passwd

We can get complete information about the binary file location as well as
manual page location of any command by following:
 whereis passwd

 whoami -- current user name
 su -- switch user -- used to change the running user to admin/elevated mode.sudo is also similar to it.


exit -- will close the terminal or exit the sudo session.

Many a times, you might need to create new commands from existing commands. Sometimes, existing commands have complex options to remember. In such cases, we can create new commands using alias and remove it using unalias

Sometimes, we need to copy a file or directory in many places. In such situations, instead of copying the original file or directory again and again, we can create soft links. In Windows, a similar feature is called as creating a shortcut.
$ ln -s file file_link 


To learn about the type of file, you can use the command file. In Linux,
various types of files exist. Some examples are as follows:
  •  Regular file (-) 
  •  Directory (d) 
  •  Soft link (l) 
  • Character device driver (c) 
  •  Block device driver (b) 
  • Pipe file (p) 
  • Socket file (s)
We can get information about a file using the following command:
$ file fil_name // show type of file




 

 


2 comments:

  1. it’s really nice and meanful. it’s really cool blog. Linking is very useful thing.you have really helped lots of people who visit blog and provide them usefull information.
    AWS Online Training

    ReplyDelete
    Replies
    1. Thank you, this is my other blog you can check it out.
      https://devopsdiaryblog.wordpress.com/

      Delete