LINUX BASIC COMMANDS

INTRODUCTION:

Introduction to shell and the command prompt was explained in the last part, in this tutorial will directly take you into the basic Linux commands.

TYPES OF BASIC COMMANDS:

AN EXECUTABLE PROGRAM:

The executable program is like all those files can have in /usr/bin.

COMMAND BUILT INTO THE SHELL ITSELF:

The bash provides the number of commands internally called shell built-ins. The cd command for example is a shell built-in command.

A SHELL FUNCTION:

These are miniature shell scripts incorporated into environment.

AN ALIAS:

Commands that you can define yourself, build from other commands.

To know the type of command, try $ type <command>

BASIC COMMANDS:

ls – List the files/folder in the directory.

OPEN LAST EDITED FILE USING ls –t:

To open the last edited file in the directory use the combination of ls, head and vi commands as shown below.

ls –t sorts the file by modification, showing the last edited file first head -1 picks up this first.


DISPLAY ONE FILE PER LINE USING ls -1:

To show single entry per line, use -1 option as shown below.

DISPLAY ALL INFORMATION ABOUT FILE/DIRECTORIES USING ls –l:

To show long listing information about the file/directory.

File Type (First Character): First character specifies the type of file. The (-) hyphen in the first character in the field indicates it as normal file. The possible file type options in the first character.

FIELD TYPE EXPLANATION

- -> Normal file

d -> Directory

s -> Socket file

l -> Link file

Field 1 – File Permissions: Next Nine characters specify the file permissions. Each 3 character refers to read, write and execute permissions for the user, group and others.

Field 2 – Number of Links: Second field specifies the number of links for this file. 1 means, only one link to the file.

Field 3 – Owner: Third field describes the owner of the file.

Field 4 – Group: Fourth field specifies the group of the file.

Field 5 – Size: Fifth field specifies the size of the file.

Field 6 – Last Modified: Sixth field specifies the last modified date and time of the file.

Field 7 – File/Directory Name: Seventh field specifies the name of the file or directory name.


DISPLAY FILE SIZE IN READABLE FORMAT ls –lh:

The command ls –lh displays the size of file in the human readable format (i.e, MB, KB, GB) in the fifth field. It’s shown below with example.

DISPLAY DIRECTORY INFORMATION USING ls –ld:

The use of ls –l command will give the details of directories content. To display only the details of the directory use –d option.

LISTING THE FILE BASED ON LAST MODIFIED TIME ls –lt:

In order to display the files in last modified order use –t with the ls command. The example for the command is shown below.

In order to list the files in reverse order based on the modification time, command –ltr can be used with ls command.

DISPLAY HIDDEN FILES USING ls –a:

To display all the hidden files in directory –a option is used. Hidden files in unix starts with ‘.’ (dot).


DISPLAY FILES RECURSIVELY USING ls –R:

In order to display the files recursively, use –R option.

DISPLAY FILE INODE NUMBER USING ls –i:

Sometimes there will be need of an inode number of file for internal maintenance. By using ls –i command inode number for file will be displayed. Using inode number files which has the special character with their name can be deleted.

cd COMMAND EXAMPLES:

cd command sets the current working directory of the process. The user must have execute permission in the specified directory.

CHANGING FROM CURRENT WORKING DIRECTORY TO LOGIN DIRECTORY:

TO CHANGE THE DIRECTORY:

If cd <Directory Name> command is used to change from one directory to another directory.

TO GO UP ONE LEVEL OF DIRECTORY TREE:

The command cd .. is used to move back (Up one level) of one directory.

For navigating a very long directory structure, you may be using cd ../../ with multiple ../’s depending on how many directories to go up.

pwd COMMAND:

pwd – present working directory.

The pwd command is used to display the current working directory.


7 views

Copyright © 2018 StudyBuff. Proudly created with Wix.com

Follow Us