Narayana Tutorial

Online Java Tutorial Blog

Most Important Basic Linux Commands

In this blog, I am sharing an important basic Linux commands which are frequently used in our day to day work.

Here I have created four files (file1.txt, file2.txt, file3.txt and .file4.txt) inside workfolder to show an example for the below commands.

ls command

ls command is a basic command to see the list of files in the current directory

ls

The ls command lists files and directories within the current working directory. Files listed in the grid format.

Example

[[email protected] workfolder]$ ls
file1.txt file2.txt file3.txt

ls -lrt

Files listed order based on Last Modified Time (In Reverse Order).

Example

[[email protected] workfolder]$ ls -ltr
total 0
-rw-rw-r--. 1 narayanatutorial narayanatutorial 0 Apr 16 15:25 file1.txt
-rw-rw-r--. 1 narayanatutorial narayanatutorial 0 Apr 16 15:37 file2.txt
-rw-rw-r--. 1 narayanatutorial narayanatutorial 0 Apr 16 15:43 file3.txt
[[email protected] workfolder]$

ls -a

By default ls command will not display hidden files which contains .(dot) in front of the file name. So by using this command we can see hidden files. Here .file4.txt is a hidden file.

Example

[[email protected] workfolder]$ ls -a
. .. file1.txt file2.txt file3.txt .file4.txt

cd command

The cd command changes the current directory in Linux and can toggle between directories conveniently. cd is similar to the CD and CHDIR commands in MS-DOS.

Example

[[email protected] ~]$ cd workfolder/

Here we can see the current directory path using pwd
[[email protected] workfolder]$ pwd
/home/narayanatutorial/workfolder
[[email protected] workfolder]$

pwd command

The pwd (print working directory) command displays the name of the current working directory.

Example

[[email protected] workfolder]$ pwd
/home/narayanatutorial/workfolder
[[email protected] workfolder]$

clear command

The clear command clear the screen which is similar to cls command in the MS-DOS.

man command

If we don’t know options of the command or syntax of the command  then no need to worry. we have documented all commands options and syntax in . we can see more details of the each command by using the man command.

The man is short for manual. The  man allows a user to format and display the user manual built into Linux distributions which documents commands and other aspects of the system.

Example 

[[email protected] workfolder]$ man ls

Output

LS(1) User Commands LS(1)

NAME
 ls - list directory contents

SYNOPSIS
 ls [OPTION]... [FILE]...

DESCRIPTION
 List information about the FILEs (the current directory by default).
 Sort entries alphabetically if none of -cftuvSUX nor --sort.

 Mandatory arguments to long options are mandatory for short options
 too.

 -a, --all
 do not ignore entries starting with .

 -A, --almost-all
 do not list implied . and ..

 --author
 with -l, print the author of each file
:

mkdir command

Creates a new directory. Here we have created workfolder-2 folder inside /home/narayanatutorial

Example

[[email protected] ~]$ mkdir workfolder-2
[[email protected] ~]$ ls
Desktop Downloads Pictures Templates workfolder
Documents Music Public Videos workfolder-2
[[email protected] ~]$ pwd
/home/narayanatutorial

rmdir command

Deletes the specified directory, provided it is already empty. Here we have deleted workfolder-2 inside /home/narayanatutorial

[[email protected] ~]$ rm -r workfolder-2/
[[email protected] ~]$ ls
Desktop Downloads Pictures Templates workfolder
Documents Music Public Videos
[[email protected] ~]$ pwd
/home/narayanatutorial
[[email protected] ~]$
Narayanaswamy

Hello! I am Narayanaswamy founder and admin of narayanatutorial.com. I have been working in IT industry more than 7 years. NarayanaTutorial is my web technologies blog. My specialties are Java / J2EE, Spring, Hibernate, Struts, Webservices, PHP, Oracle, MySQL, SQLServer, Web Hosting and Website Development.

I am a self learner and passionate about training and writing. I am always trying my best to share my knowledge through my blog.

The Author

Narayanaswamy

Narayanaswamy

Hello! I am Narayanaswamy founder and admin of narayanatutorial.com. I have been working in IT industry more than 7 years. NarayanaTutorial is my web technologies blog. My specialties are Java / J2EE, Spring, Hibernate, Struts, Webservices, PHP, Oracle, MySQL, SQLServer, Web Hosting and Website Development. I am a self learner and passionate about training and writing. I am always trying my best to share my knowledge through my blog.

2 Comments

Add a Comment
  1. I have seen lot blogs and Information on othersites But in this Java Blog Information is very useful thanks for sharing it……..

Leave a Reply

Narayana Tutorial © 2016 Frontier Theme
Show Button
Hide Button