Home  >  Blog  >   Linux

Linux Commands for Beginners

Rating: 5
  
 
12863

As we know that the Operating System is an important component of the computer. Linux operating system is open-source and community-developed for mainframes, servers. Linux is one of the widely accepted operating systems across the world. 

Here in this article, we are going to discuss briefly the top 50 Linux commands, and their working in a real-time environment. To enhance your skills on Linux, visit our Linux Tutorials.

Now, Let's get into the commands section.

If you want to enrich your career and become a professional in Linux, then visit Mindmajix - a global online training platform: "Linux Training Certification" This course will help you to achieve excellence in this domain.

File Commands in Linux Operating System

File command:

This command is used to determine the file type, and you can easily read and understand it. This command categorizes each argument after testing.  

It has three sets to test the argument.

  • Filesystem Test: Based on the stat system call results it verifies empty files and sorts few files, this prints the type of the file. 
  • Magic Test: It checks the format of data in a particular file and prints the category.
  • Language Test: It searches the string which appears in the blocks of a file. 

Syntax: 

file [option] [filename]

[ Related Article: Latest Linux Interview Questions ]

Example: 

file email.py
file name.jpeg
file invoice.pdf
file exam.ods
file videosong.mp4

Output:

Option: this displays the file types. 

-b, [–brief]: This gives a brief mode of the file. 

MindMajix Youtube Channel

Syntax:

file -b filename

Example: 

file -b email.py

Output:

root@tryit-next:~ file xyz.py
xyz.py : ASCII text

[ Related Article: Kernel Tutorial

 

 

Following are the few commands to check the file type without filename

1. * option: Shows all files, file types

Syntax: file *

Displays all files types in the system.

2. directory name/* option: Shows all files file type in the current directory

Syntax: file directoryname/*

3. -I option: this displays the mime type files.

Syntax: file -i filename

4. -z option: displays compressed files

Syntax: file -z flash.tar.gz

5. -s option: Displays special files

Syntax: file -s filename

df command: this command displays the space of the hard disk and how much disk was free. 

Syntax: df 

The following image will show you the output of the df command. 

To print the same output in GB/MB/KB, use the -h option in the command.

Syntax: df -h

du command: It displays the size of the file and to know that how much disk space using by the files in the directories. 

Syntax: #du

Output: It shows how much space used by files in the current directory.

du/boot: this displays the file size in another directory also.

Syntax: #du/boot

Output: Print the file size of the current directory and another directory.

du-h/boot: It displays the size of the file in GB/MB/Kb.

Syntax: #du -h/ boot

[ Related Article: Linux vs Unix Differences ]

Output: 

The diff Command: 

This diff command is used to check the differences between two files.

Syntax: 

diff file1  file2

Let us consider one example and check how the command works

Create a dummy file and copy the same data to the dummy file and change the data in the original file now check the command. See the changes in the output.

find command

This command helps to search the necessary data in the specified location.

Syntax:

#find [where to search] -name [what to search]

Example: 

#find /etc -named hostname

Cat command:

This command used to create and view single or multiple files, and concatenate the files. It will consider one file output as another file input and print in the terminal or file. 

General Syntax: 

cat [option] [file]..

Multiple files content view: In this multiple files data will be displayed in the terminal.

Let’s us consider one example 

1. cat file file1

Output: 

# cat file file1

Hello mindmajix
Hai world,

2. Using the cat command create a file:

Syntax:

# cat >org

Output:

# cat >org

Hai Mindmajix, Hello world

3. Display the line numbers in the file

To display the line numbers in the file using -n in the command.

Syntax:

cat -n filename

Let us consider one example

#cat -n mindmajix.text

Output:

#cat -n mindmajix.txt
1 Have a wonderful life
2 Happy Birthday!

4. View multiple files

To display multiple files at once we can use the command below

Syntax:

# cat filename; 
cat filename1; 
cat filename2

Let us check with one example

# cat org; cat file; cat file1

Output:

# cat org; cat file; cat file1
Hai Mindmajix,
Hello mindmajix
Hai world,

Copy command

Copy command represent with cp, it helps to copy the data into other files and directories. In cp command at least pass 2 arguments.

Syntax: 

cp [OPTION] Source Destination
cp [OPTION] Source Directory
cp [OPTION] Source-1 Source-2 Source-3 Source-n Directory

Two file names: If the command contains 2 file names, then the data will be copied from the first file to the second file. If the second file does not exist it will create a new file and then data will be copied to the second file. 

Syntax: cp Source_file Dest_file

Example: 

$ ls
file.txt
$ cp file.txt file1.txt
$ ls
file.txt  file1.txt

One or more arguments: If the command has one or more arguments and the destination is a directory then these source files will copy as it is to the directory.

Syntax:

cp Src_file1 Src_file2 Src_file3 Dest_directory

Let us consider one example

$ ls
file.txt file1.txt  new
Initially new is empty
$ ls ne
$ cp file.txt file1.txt new
$ ls new
file.txt file1.txt

3. Directories:

In this command, we need to consider two directories, which means the data is copied from the source directory to the destination directory.

Syntax:

cp -R Src_directory Dest_directory

PWD Command:

This command print the current working directory. 

Syntax: pwd [option]

Option: 

-L: It prints logical links
Syntax: pwd -L
-P: It prints physical links
syntax: pwd -P
-version: Display the current version of the system.
Syntax: pwd -version  

ls Command : 

This command is used to display the directory content. 

Syntax: # ls [option] [file]

Display list of files and directories without using options

Syntax: # ls 

Output: 

# ls

File.py  file1.text  music  download  mindmajix.html  docs 

2. Option -l

Syntax:

#ls -l

Output: 

total 167
-rw-r--r--. 1 root root   683 Jan 19 08:59 0002.py
-rw-------. 1 root root  1568 Jun 31 03:17 anaconda.cfg
drwxr-xr-rw.2 root root  0496 Jul 26 06:48 Dsktop
drwxr-xr-x. 2 root root  4096 Jul 31 07:48 Docs
drwxr-xr-x. 3 root root  4096 Aug 16 02:55 Downlds
-rw-r--r--. 1 root root 21262 Jan 12 12:42 fbcmd.php
-rw-r--r--. 1 root root 46071 Jul 25 09:58 index1.html
-rw-r--rw-. 1 root root 46887 Jul 31 02:26 install.log
-rw-rw-r--. 1 root root 14139 Jan 31 05:13 install.syslog
drwxr-wr-x. 2 root root  4096 Aug 31 02:48 Music
drwxr-xr-x. 2 root root  4906 Jul 24 06:48 Pictures
drwxr-wr-x. 2 root root  4906 Jul 31 03:48 Public
drwxr-xr-x. 2 root root  4906 Aug 28 02:48 Templts
drwxr-wr-x. 2 root root  9046 Jul 31 05:48 Videos

3. # ls -r

This command is used to display the list in reverse order.

Syntax:

# ls -r 

Output: 

# ls -r 
docs  mindmajix.html download music file1.txt  file.txt 

chmod command:

This command is used to change the mode. 

It can be used in two ways

Octal value & position

Using symbolic values and removing the file permission

Octal value & position: To set the permissions for groups, owners, and others with the octal value. 

4- read permission

2- write permission

    1. execute permission

Syntax:

chmod [option] MODE file

    2. Using symbolic values and removing the file permission:

It represents as

u- user
g- group
o- others all
r- read
w -write
x - execute

Syntax:

chmod [option] Mode1, Mode2,...file 

Options:

-c, --changes the mode
-f, --silent, --quiet
-v, --verbose
--no- preserve-root
--preserve-root
--reference=RFILE
-R, --recursive

chown command:

This command is used to change the ownership

Syntax:

# chown [OPTION]... [OWNER][:[GROUP]] FILE... 

Example:

chown owner_name file_name

Chsh command:

It changes the user login shell. It specifies the user name in the login command. Superuser changes the ownership to any account, but the user can change only for his account.

Syntax:

$chsh [options] [LOGIN]
 -l It prints the list of variables in the system
chsh  change the login shell 
 -s path_to_ksh -- It changes the current login shell from Bash to Ksh
-s --- It changes the user shell

Move command: 

This command is used to move the files and directories

Syntax:

# mv [options] source dest 

Example: 

# ls
file1.txt  file2.txt  file3.txt  file4.txt
# mv file1.txt geek.txt
# ls
file2.txt  file3.txt  file4.txt  geek.txt

Options: 

-i (interactive):

This command confirms with the user before moving the file or overwriting the existing file. If the user is presses y, then it moves or overwrites the file.

Syntax:

mv -i  srce  dest 

Example: 

# ls
file1.txt  file2.txt  file3.txt  geek.txt
# cat geek.txt

Welcome to mindmajix

# cat file2.txt

Hello world

Welcome to Mindmajix

2. -f(force):

This command overwrites the data to the destination and deletes the source file forcefully. 

Syntax:

mv -f src dest

Example: 

# ls
file1.txt  file2.txt  file3.txt  geek.txt
# cat file2.txt

Welcome to Mindmajix

# ls -l b.txt
-r--r--r--+ 1 User User 14 Jan  9 15:37 file2.txt
# mv geek.txt file2.txt
mv: replace 'file2.txt', overriding mode 0444 (r--r--r--)? n
# ls
file1.txt  file2.txt  file3.txt  geek.txt
# mv -f geek.txt file2.txt
# ls
file1.txt  file2.txt  file3.txt
# cat file2.txt

Hello World

3. -n (no-clobber):

It prevents the overwriting of the existing files. 

Syntax:

mv -n source file dest file

Example: 

# ls
file1.txt  file2.txt  file3.txt  geek.txt
# cat file2.txt

Welcome Mindmajix

# mv -n geek.txt file2.txt
# ls
file1.txt  file2.txt  file3.txt  geek.txt
$ cat file2.txt
Welcome Mindmajix

4. -b (backup):

Using this command it is easier to take backup for the existing overwritten file using the mv command. It represents the (~) 

Syntax:

mv -b source file dest file

Example: 

# ls
file1.txt  file2.txt  file3.txt  geek.txt
$ mv -b geek.txt file2.txt
$ ls
file1.txt  file2.txt~  file3.txt  file4.txt

5. -version:

This command is used to display the current version of the system.

Syntax:

mv --version

Example:

# mv --version
mv (GNU coreutils) 8.26
Packaged by Cygwin (8.26-2)
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later .
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Mike Parker, David MacKenzie, and Jim Meyering.

Remove command: This command is used to remove the file from the current directory.

Syntax:

rm [option].. file name..

Example:

#ls 
file1.txt  file2.txt  file3.txt 
#rm file1.txt
#ls
file2.txt  file3.txt

-i (interactive deletion):

This command confirms with the user whether to delete the file from the current directory or not. Once the user confirms deletion, it deletes the file from the directory.

Syntax:

rm -i file name

Example: 

# rm -i file1.tx
rm: remove regular empty file 'file1.txt'? y
# ls
file2.txt

-f(force deletion):

This command forcefully removes the file from the current directory.

Syntax:

rm -f filename

Example: 

# ls -l
total 0
-r--r--r--+ 1 User User 0 Jan  2 22:56 file1.txt
# rm file1.txt
rm: remove write-protected regular empty file 'file1.txt'? n
# ls
file1.txt
# rm -f file1.txt

-r(recursion deletion):

It deletes all files, subdirectories, and directories. Actually, rm couldn’t delete the directory, but when you use this option it will delete the directory also. 

Syntax:

rm -r filename/directory name

--version:

This command displays the current version of the system.

Syntax: 

rm --version

Example: 

# rm --version
rm (GNU coreutils) 8.26
Packaged by Cygwin (8.26-2)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later .
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Paul Rubin, David MacKenzie, Richard M. Stallman,
and Jim Meyering.

mkdir:

This command is used to create a directory 

Syntax:

mkdir [options...] [directories ...]

Example:

# mkdir mynew_dir

Option: 

-v[verbose]:

Whenever it creates the directory it displays the message.

Syntax:

mkdir -v  directory name

Example: 

#mkdir -v mindmajix tekslate 
mkdir: created directory 'mindmajix'
mkdir: created directory 'tekslate'
#ls 

mindmajix tekslate

2. -p :

This command is used to enable the parent directory.

Syntax:

mkdir -p [directories]

Let the check with an example

# mkdir -p -v mindmajix online trainings
mkdir: created directory 'mindmajix'
mkdir: created directory 'online’ trainings'
mkdir: created directory ‘mindmajix’ ‘online’ 'trainings’

3. -m(mode):

This command sets the file permissions to the directories. 

Syntax:

mkdir -m a=wrx [directory names]

Example: 

# mkdir -m a=rw Suneel

rmdir(remove directory):

This command is used to delete the directory. 

Syntax: 

rmdir [-p] [-v | -verbose] [-ignore-fail-on-non-empty] directories ...

Linux Network Command list

In this internet era, every computer has connected to some other computer through the desired network, whether externally or internally, to transfer information.

These networks range varies from small to large or even more complicated on the entire internet.

Linux Networking commands used to troubleshoot relating to networking issues.

Linux Training In Hyderabad, Linux Training In Bangalore.

Essential Linux Networking Command list

Linux Network Command
Used for
ping
ping Linux command used to check the connectivity between two nodes.
netstat
netstat Linux network command used to display connection information
ss
ss Linux command used as instead of netstat
dig
It is used to find Query related information
nslookup
used to find DNS related query
route
Manipulate and shows the IP routing table.
hostname 
hostname Linux networking command used to identify a network name.

List of Other Linux Blogs:

Linux File PermissionsLinux Advanced Functions And Commands
Introduction to Linux Operating SystemLinux Networking Commands with Examples
What is Linux?Top 10 Reasons Why You Should Learn Linux
Linux Kernel TutorialWhat is Linux Operating System
Join our newsletter
inbox

Stay updated with our newsletter, packed with Tutorials, Interview Questions, How-to's, Tips & Tricks, Latest Trends & Updates, and more ➤ Straight to your inbox!

Course Schedule
NameDates
Linux TrainingApr 20 to May 05View Details
Linux TrainingApr 23 to May 08View Details
Linux TrainingApr 27 to May 12View Details
Linux TrainingApr 30 to May 15View Details
Last updated: 03 Apr 2023
About Author

Usha Sri Mendi is a Senior Content writer with more than three years of experience in writing for Mindmajix on various IT platforms such as Tableau, Linux, and Cloud Computing. She spends her precious time on researching various technologies, and startups. Reach out to her via LinkedIn and Twitter.

read more