linux commands – ExpLinux https://explinux.com Explore Linux How to, Tutorials, Unix, Updates, Technology. Sun, 11 May 2025 17:08:30 +0000 en-US hourly 1 https://wordpress.org/?v=6.8.1 https://explinux.com/wp-content/uploads/2023/04/cropped-favicon-32x32-1-32x32.png linux commands – ExpLinux https://explinux.com 32 32 100 Best Use Cases of Find Command in Linux -ExpLinux https://explinux.com/2023/02/100-use-of-find-command-in-linux.html Mon, 20 Feb 2023 20:05:50 +0000 https://explinux.online/?p=794 Find Command In Linux
Find Command in Linux
Find Command in linux

The very popular Linux admins friend find command in Linux was created as a part of the Unix operating system by Ken Thompson and Dennis Ritchie at Bell Labs in the golden era of new computer development in the 1970s. Thompson and Ritchie were two of the pioneer developers of the Unix operating system and also developed the mother of most programming language C programming language, C is mostly used for developing software for Unix-based systems. The find command in Linux and Unix operating systems is still widely used today for searching for files and directories on a system and performing operations on them.

Some Alternatives of Find Command

Related Post: MV Command

22 Most Useful Linux Commands

15 Linux Commands to Boost Productivity

Master Guide to Vi Editor

There are only locate is main alternatives to the find command in Linux, which gives it some competition but we have added 4 more alternatives that can be useful in specific tasks.

locate: The locate command is the fastest way to search for files and directories on a Linux system. Unlike the find command, locate command creates its database of file paths that are generated periodically, so it provides faster results than find but it may not always be up to date. It will not come default in the system we have to install it and before first use has to update the Database of locate command. Update duration will depend upon your system file number.

grep: The grep command is an awesome tool for searching for patterns in text files. It can also be used to search for files and directories by name, although it is not as versatile as the find command in Linux because it searches only in text files.

whereis: The whereis command in Linux is used to locate the binary, source, and manual page files for a specified command. It is a simple but useful tool that provides basic information about a command, including its all locations on the system. for example command may be in /bin/ /sbin/ or /usr/bin/ it will show all.

which: The which command is in Linux is also used to locate the binary for a specified command. Unlike whereis, it only provides the location (bin /usr/bin, etc) of the executable file for the command for your bash profile and does not provide information about its source code or manual pages.

findmnt: The findmnt command in Linux is used to find and display information about mounted file systems on a Linux and Unix system. It provides information about the mounted file system type, source, and target mounted on for each mounted file system.

These are some alternatives but the find command is still on top because it gives you real-time all details of the file and provides the ability to perform operations even in the script you can use the find command to get currently accurate results and perform operations on the right file.

Top 100 Use Cases of Find Command

Please find below examples

SNUseCommand
1Find files in a specific directory:find /path/to/directory -type f
2Find directories in a specific directory:find /path/to/directory -type d
3Find files with a specific name:find /path/to/directory -name “file_name”
4Find files with a specific extension:find /path/to/directory -name “*.extension”
5Find files based on their size:find /path/to/directory -size +10M
6Find files based on their modification time:find /path/to/directory -mtime +7
7Find files based on their access time:find /path/to/directory -atime +7
8Find files based on their inode number:find /path/to/directory -inum 123456
9Find files that are readable:find /path/to/directory -perm -444
10Find files that are writable:find /path/to/directory -perm -222
11Find files that are executable:find /path/to/directory -perm -111
12Find files that are owned by a specific user:find /path/to/directory -user user_name
13Find files that are owned by a specific group:find /path/to/directory -group group_name
14Find files with a specific user ID:find /path/to/directory -uid 123456
15Find files with a specific group ID:find /path/to/directory -gid 123456
16Find files that match a specific pattern:find /path/to/directory -regex “.*pattern.*”
17Find files that contain a specific word or phrase:find /path/to/directory -type f -exec grep -q “word or phrase” {} \; -print
18Find files that are symbolic links:find /path/to/directory -type l
19Find files that are hard links:find /path/to/directory -type f -links +1
20Find files that are empty:find /path/to/directory -empty
21Find files that are not empty:find /path/to/directory ! -empty
22Find files and execute a specific command on each file:find /path/to/directory -type f -exec command {} \;
23Find files and move them to a new location:find /path/to/directory -type f -exec mv {} /path/to/new/location \;
24Find files and delete themfind /path/to/directory -type f -exec rm -i {} \;
25Find files and copy them to a new location:find /path/to/directory -type f -exec cp {} /path/to/new/location \;
26Find files and change the permissions on each file:find /path/to/directory -type f -exec chmod 755 {} \;
27Find files and change the owner of each file:find /path/to/directory -type f -exec chown user:group {} \;
28Find files and change the group of each file:find /path/to/directory -type f -exec chgrp group_name {} \;
29Find files and print the full path of each file:find /path/to/directory -type f -printf “%p\n”
30Find files and print the size of each file:find /path/to/directory -type f -printf “%s\n”
31Find files and print the inode number of each file:find /path/to/directory -type f -printf “%i\n”
32Find files and print the modification time of each file:find /path/to/directory -type f -printf “%T@\n”
33Find files and print the user name of the owner of each file:find /path/to/directory -type f -printf “%u\n”
34Find files and print the group name of the owner of each file:find /path/to/directory -type f -printf “%g\n”
35Find files and print the permissions of each file:find /path/to/directory -type f -printf “%M\n”
36Find files and execute a command with a specific time limit:find /path/to/directory -type f -mmin +5 -exec command {} \;
37Find files and execute a command only if the file has been modified in the last 5 minutes:find /path/to/directory -type f -mmin -5 -exec command {} \;
38Find files and execute a command only if the file has not been modified in the last 5 minutes:find /path/to/directory -type f ! -mmin -5 -exec command {} \;
39Find files and search for a specific string in each file:find /path/to/directory -type f -exec grep “string” {} \;
40Find files and list only the first 10 files that match a specific criteria:find /path/to/directory -type f -print | head -10
41Find files and list only the last 10 files that match a specific criteria: find /path/to/directory | head 10
42Find files and exclude a specific directory from the search:find /path/to/directory -type f -not -path “/path/to/directory/to/exclude/*” -print
43Find files and exclude multiple directories from the search:find /path/to/directory -type f \( -not -path “/path/to/directory/to/exclude/*” -and -not -path “/path/to/directory/to/exclude2/*” \) -print
44Find files and search for files with a specific name pattern:find /path/to/directory -type f -name “*.txt”
45Find files and search for files with a specific size:find /path/to/directory -type f -size +100M
46Find files and search for files smaller than a specific size:find /path/to/directory -type f -size -100M
47Find files and search for files larger than a specific size:find /path/to/directory -type f -size +100M
48Find files and search for files of an exact size:find /path/to/directory -type f -size 100M
49Find files and search for files with a specific user owner:find /path/to/directory -type f -user user_name
50Find files and search for files with a specific group owner:find /path/to/directory -type f -group group_name
51Find files and search for files with a specific type of permissions:find /path/to/directory -type f -perm 644
52Find files and search for files that are writable:find /path/to/directory -type f -perm -222
53Find files and search for files that are readable:find /path/to/directory -type f -perm -444
54Find files and search for files that are executable:find /path/to/directory -type f -perm -111
55Find files and search for files with specific type of executability:find /path/to/directory -type f -perm /u=x,g=x
56Find files and search for files that have changed in the last 7 days:find /path/to/directory -type f -ctime -7
57Find files and search for files that have changed more than 7 days ago:find /path/to/directory -type f -ctime +7
58Find files and search for files that have been modified in the last 7 days:find /path/to/directory -type f -mtime -7
59Find files and search for files that have been modified more than 7 days ago:find /path/to/directory -type f -mtime +7
60Find files and search for files that have been accessed in the last 7 days:find /path/to/directory -type f -atime -7
61Find files and search for files that have not been accessed in the last 7 days:find /path/to/directory -type f -atime +7
62Find files and search for files that match multiple criteria:find /path/to/directory -type f \( -name “*.txt” -or -name “*.pdf” \) -and -size +100M
63Find files and delete the files that match certain criteria:find /path/to/directory -type f -name “*.bak” -delete
64Find files and print the output in a specific format:find /path/to/directory -type f -printf “%p %u %g %s\n”
65Find files and execute a specific command on the matching files:find /path/to/directory -type f -exec chmod 644 {} \;
66Find files and limit the number of results to display:find /path/to/directory -type f -print | head -10
67Find files and sort the results by file size:find /path/to/directory -type f -printf “%s %p\n” | sort -nr
68Find files and exclude specific files or directories from the results:find /path/to/directory -type f \( ! -name “*.bak” ! -path “/path/to/directory/to/exclude/*” \) -print
69Find files and search for files based on their inode number:find /path/to/directory -type f -inum 123456
70Find files and search for files based on their access time and modification time:find /path/to/directory -type f -anewer file.txt -or -mnewer file.txt
71Find files and search for files with a specific type of type:find /path/to/directory -type l -ls
72Find files and search for files with a specific type of type and perform an action on them:find /path/to/directory -type l -exec ls -l {} \;
73Find files and search for files based on the number of links:find /path/to/directory -type f -links +5
74Find files and search for files based on the number of links and perform an action on them:find /path/to/directory -type f -links +5 -exec ls -l {} \;
75Find files and search for files based on the type of file system they are on:find /mnt/c/ -type f -fstype xfs
76Find files and search for files with a specific owner:find /path/to/directory -type f -user username
77Find files and search for files with a specific group:find /path/to/directory -type f -group groupname
78Find files and search for files with a specific permissions:find /path/to/directory -type f -perm 0644
79Find files and search for files with a specific name and perform a certain action on them:find /path/to/directory -type f -name “*.log” -exec gzip {} \;
80Find files and search for files that match a certain pattern and perform a certain action on them:find /path/to/directory -type f -regex “.*\.\(jpg\|jpeg\|png\)” -exec cp {} /path/to/destination/ \;
81Find files and search for files that have been modified in the last 7 days and perform a certain action on them:find /path/to/directory -type f -mtime -7 -exec rm {} \;
82Find files and search for files that have a specific size and perform a certain action on them:find /path/to/directory -type f -size +100M -exec mv {} /path/to/destination/ \;
83Find files and search for files that have a specific size range and perform a certain action on them:find /path/to/directory -type f -size +10M -size -100M -exec cp {} /path/to/destination/ \;
84Find files and search for files that have a specific size range and print the results in a specific format:find /path/to/directory -type f -size +10M -size -100M -printf “%p %u %g %s\n”
85Find files and search for files that have a specific name and move them to a specific location:find /path/to/directory -type f -name “*.log” -exec mv {} /path/to/destination/ \;
86Find files and search for files that have a specific name and copy them to a specific location:find /path/to/directory -type f -name “*.log” -exec cp {} /path/to/destination/ \;
87Find files and search for files that have a specific name and count the number of matches:find /path/to/directory -type f -name “*.log” | wc -l
88Find files and search for files that have a specific name and delete the matches:find /path/to/directory -type f -name “*.log” -delete
89Find files and search for files that have a specific name and rename the matches:find /path/to/directory -type f -name “*.log” -exec mv {} {}.bak \;
90Find files that have been modified in the last day and delete them:find /path/to/directory -type f -mtime -1 -delete
91Find files that have been modified in the last 7 days and compress them:find /path/to/directory -type f -mtime -7 -exec gzip {} \;
92Find files that have a specific name and show the details in a human-readable format:find /path/to/directory -type f -name “*.log” -exec stat -c “%n %s %y” {} \;
93Find all symbolic links and delete them:find /path/to/directory -type l -delete
94Find all symbolic links and replace them with their targets:find /path/to/directory -type l -exec sh -c ‘ln -sf “$(readlink -f “$1″)” “$1″‘ _ {} \;
95Find all symbolic links that point to a specific location and delete them:find /path/to/directory -type l -lname “/path/to/link/target” -delete
96Find all files that are larger than a specific size and delete them:find /path/to/directory -type f -size +100M -delete
97Find mp3 files in ext4 filesystemfind /mnt/usb/ -type f -fstype ext4 | grep -i ‘\.mp3$’
98Find files that have been modified in the last hour and move them to a different location:find /path/to/directory -type f -mmin -60 -exec mv {} /path/to/destination/ \;
99Find commnad in linux with sed command . Find file and replace text mylinux to explinuxfind my_files -type f -name ‘*.txt’ -exec sed -i ‘s/mylinux/explinux/g’ {} \;
100Find process pid status and print from proc find /proc/1234 -maxdepth 0 -name status -o -name stat -exec cat {} \;
Find Command in Linux – explinux

Feel free to provide you advice and a new or effective way to use the find command in Linux.

Conclusion:

Here we have seen 100 use cases of the find command in Linux and this can be used in a script or in daily use of system admin and troubleshooting tasks using the find command.

]]>
A Comprehensive Guide to the “mv” Command for Renaming Files in Linux 2023 https://explinux.com/2023/01/command-for-renaming-files-in-linux.html Thu, 19 Jan 2023 19:36:19 +0000 https://explinux.online/?p=784 Renaming files in Linux is an important part of basic file management. mv command was written by Ken Thompson. With the “mv” command, you can quickly and easily rename your files in a few simple steps. This guide provides a step-by-step overview of the process so you can get organized fast!

Renaming Files in Linux

Understand the Basics of the mv Command

The “mv” command is an abbreviation for “move” and is used to rename files or directories in Linux. By using the syntax mv Old_Filename New_Filename, you can move a target file or folder from its current location to a new location you specify. This command also allows you to rename files or folders by simply specifying the same source and destination. This is the most common and useful command for all Linux administrators.

Related article: 22 Linux Commands you should learn now

Move and Rename Files at Once With mv

In addition to renaming files, you can use the mv command to move a file by simply combining both a relocation and naming action into one command. For example, if you have a file called “mysecrete.txt” which is currently in the current working directory and want to move it to the “TopSecrete” folder and rename it as “mynewsecrete.txt”, all you need to do is use the below command:

# mv mysecrete.txt /TopSecrete/mynewsecrete.txt 

or If you want to rename on the same directory just use the below command :

# mv mysecrete.txt mynewsecrete.txt

This way, you will be able to move and rename your file in one simple step!

Move Only When Source File is Newer

The mv command offers the option to move only newer source files because sometimes we move files and it rewrites on an existing file, So in case to avoid this situation, we can use the -u option. This is useful in case of backup or backup script and could save your time by not moving unnecessary files, use this command:

# mv -u myimportantfile.txt importantSubdirectory/

Copy a File Directory and Its Contents Using mv

You can copy a file or directory and all its content (subdirectories and files) using the mv command. To do this, simply give the directory name to your command to move the directory to another directory with all data. For example, as shown above you could use as below :

# mv olddirectory Subdirectory/

If you want to move only “olddirectory” content to a Subdirectory use * at end of the directory, it will loop through all contents of the directory and move it and the directory will be empty.

# mv olddirectory/* Subdirectory/

Interactive mv Command for Rename File

mv command never as before rename but in case we want to give confirmation before renaming or moving a Linux file we can use -i (interactive) with the mv command.

If this is the new file and no overwrite then it will rename and move the file without any prompt.

# mv -i myfile.txt yourfile.txt

It will not ask for any confirmation if yourfile.txt does not exist.

But in case of files exist with the same name. So each time before overwriting the file in Linux or moving, IT will prompt for confirmation we can enter “y” or “n” respectively to accept and reject

# # mv -i myfile.txt yourfile.txt
mv: overwrite ‘yourfile.txt’? 

It will ask for your confirmation and you can provide your input with “y” or “n” in small letters.

Alternatives of mv Commands

There are many other functions we can perform with other commands too like renaming the “rename” command but this is not installed by default.

“cp” Command to copy files but the original file will not be renamed or moved.

“rsync” and “scp” commands also copy files and we can rename them in the destination folder. These commands are basically used for the remote server’s file copy and sync.

Conclusion

In this article, we have learned how to rename files in Linux with the help of the mv command. Even we have seen some more use cases of the mv command with alternatives that we can think of performing the same kind of operation. But alternatives will keep the source file too.

Hope this helps you understand how to file rename in Linux

]]>
22 Linux commands that every Linux user should know worth https://explinux.com/2022/04/20-linux-commands-that-every-linux-user-should-know-worth.html https://explinux.com/2022/04/20-linux-commands-that-every-linux-user-should-know-worth.html#respond Thu, 28 Apr 2022 18:56:02 +0000 https://explinux.online/?p=529 22 Linux commands that every Linux user should know worth

 

If you are working in IT ,data scientist or just an Linux user, basic Linux command is necessary for you . If you know basic your Linux admin task or if you are a developer or data scientist your job will be very easy .

In this post we will go through with 22 useful command which we use in our daily work .

22 Linux commands

cat

This command help you to view the content of file . This will show entire content of file .

less

If you want to see the content line by line from a big file use less instead of cat.

head

It will show the top 10 line from a file. In case you want to see the older files written in logs or heading from a file

tail

It will show you last 10 lines of file . This command is useful to see new generated logs or what last code written in file .

pwd

This command will show you your present working directory. Basically your folder path where you are currently working.

ls

This is most used command in Linux to check content of directory and permission of files.

passwd

In case you forgot your password or if you want to change password . This command will help you to change password. In technical term it will write your password in shadow file.

history

Such a great command this will let you know what is command history. Every command you run will store and show from this command .

grep

Want to check some specific words use grep command this will show if file contains certain words or not . This will show only those lines which has your search words.

gzip

This command will compress and decompress files , Mostly cases we get files in compress or if we want to send file compress is required . This command will do it for you .

diff

Want to check difference of two files just use this command .

ps

This command is very useful if you are using Linux. This will show all process active sleep or zombie. This will show you PID of process.

kill

This command is use to terminate any unwanted process . Use PID for this which you get from ps command.

ssh

Ohh you have to work on your Linux machine remotely use ssh . This will provide secure connection remotely. This has password , key , token authentication based on your requirements.

df

This command will show you space available in Linux filesystem. But sometimes some process stuck and this will show space full but actually space is not full . So we use du command for actual space and ps to check stuck process.

du

This command will show actual space taken by files on drive.

free

This command use to see RAM usages . Is you are running out of RAM or it just buffered by any useless application

cp

Now you want to copy file from on directory to another directory . This command is used to copy files from one place to another.

scp

This command is used to copy file from one computer to another or one machine to another machine .

touch

This command is use to create a empty file .

mkdir

This command is use to create directory . Just specify path and name directory created.

rm

If you don’t want to see some files and directory in your system use this command . This command is use to delete .

 

Hope this article helped you to get better understanding of linux . I would like to recommend you to learn vim if you really want to work on files . This is the article link – How to use vim Editor

Keep Learning and growing !

]]>
https://explinux.com/2022/04/20-linux-commands-that-every-linux-user-should-know-worth.html/feed 0
How to Use vi Editor in Linux and vi Editor Cheat-Sheet with 38 Shortcut https://explinux.com/2020/07/how-to-use-vi-editor-in-linux-and-vi-editor-command-in-linux.html https://explinux.com/2020/07/how-to-use-vi-editor-in-linux-and-vi-editor-command-in-linux.html#respond Sun, 05 Jul 2020 04:30:00 +0000 https://explinux.online/2020/07/05/how-to-use-vi-editor-in-linux-and-vi-editor-command-in-linux/
How to Use vi Editor in Linux and vi Editor Command in Linux
How to Use vi Editor in Linux and vi Editor Command in Linux

How to Use vi Editor in Linux and vi Editor Command in Linux

vi Editor :

. vi is the symbolic link of vim and this default editor comes with Linux based OS. This is very popular among sysadmins. This a very simple and powerful editor. You can use it to make your rivels list, a letter to your valentine, script, code, and edit any source code. This is your best friend in the Linux system.

vi Editor modes:

vi Editor has 3 modes –

1- Command mode :

                                This is the default mode when we enter in vi editor. In this mode almost every key n keyboard has a function, so use it very carefully.
Command mode
Command mode when enter file using vi <filename>
Command mode when press esc key
Command mode when press esc key from any other mode

2- Insert Mode :

                         You can enter this mode by pressing the “i” key on the keyboard. In this mode, you can write anything your code, list, or edit file.
insert mode

3- Visual mode  or GUI mode :

                                                This is not available in all distro and less used feature of vi editor. You can enter this mode by pressing the “v” key on the keyboard from command mode.
visual mode
Note: By default vi editor mode is Command mode. You can enter any mode from command mode only and escape from that mode to command mode by pressing the “esc” key on the keyboard.
These are the modes of vi editor in Linux. Below you will see some vi editor cheat sheet which you can use in your sysadmin work and give you more understanding of vi editor commands in Linux.

vi Editor Basic Commands :

In this section, we will talk about the basic command of vi editor which has to know by every Linux user for use of the basic function of vi editor.

Create New File or Enter Any Existing File :

To enter any file use command vi <filename>. For example, see below
# vi explinux
enter vi editor
you will enter in command mode as default by this command.

Write or edit in vi editors:

Press lowercase i to enter in edit mode. Now you can write anything or delete and navigate by keyboard navigation arrow key.
insert mode

vi Editor Save and Exit :

When you finished your editing you have to come in command mode for exit or save the file. Please find below the steps to save and exit from the file.
  1. Press esc key on the keyboard to change command mode from insert mode.
  2. write “:wq! ” in lowercase. Press enter key to execute the command to save and exit from file. Please check below pic to understand more.
vi editor save and exit
w – stands for save file 
q – stands for quit from file 
! – do not ask anything just run my command 

vi Editor Cheat Sheet :

Now you have learned how to use vi editor and basic commands of vi editor which every Linux user should have known. Now we will talk about some advance command which should be known by every Linux sysadmin or any advance user.
These commands will run only in command mode as mentioned earlier. By default vi is in command mode if you are in another mode press esc key to enter in command mode.
Linux is a case sensitive so be careful about it.

List of Commands :

Open or edit any file :

# vi <filename>

Enter to Insert mode 

i

Enter in Command Mode:

esc key on the keyboard
Save the file and Continue Editing:
:w
Save and quit vi Editor :
:wq!
Quit from file and do not write change :
:q!

Yank :

Copy or yank line :
yy
Copy X number of lines :
Xyy
for example 3 lines – 3yy
Paste Yanked File Below the Cursor Line :
p
Paste Yanked File Above the Cursor Line :
P    or  shift+p
This is the yank function that can be used to reduce time. This is a very useful command.
Create a New Line below the current line of Cursor :
o
Create a New Line Above the Current Cursor Line:
O  or shift+o
Go To End of Line and Switch To Insert Mode for Write:
A  or shift+a
Switch To Insert Mode At Start Of Line:
a
Switch to Insert Mode at the Beginning of Line :
I   or  shift+ i
Move to Begin of the Word :
b
Move to End of  the Word:
e
 
Go to the Last Line of Open file :
G  or shift+g
Go to the X Number Line of Open file :
XG
for example, we have to go on 3rd line: 3G
Go to the X Number Line of Open file :
gg
Delete a Single Letter or Character:
x
Delete a Single Word in Open File:
dw
Delete X Number of Words in Open File :
Xdw
for example, delete 3 words: 3dw
Change Any Word in vi Editor :
cw
Delete an Entire Current Line :
dd
Delete X Lines in One Command :
Xdd
For example, we have to delete 3 lines then: 3dd
Change or Replace Any Character or Letter :
r
Overwrite All Characters form onwards Cursor Position: 
R  or shift+r
Get the Current Line’s line Number in Open File:
:num  and press enter
Get All Lines’s Line Number in Open File:
:set nu  and press enter key
Undo Last Change in vi Editor :
u
Undo Last Change in entire Line vi Editor :
U  or shift+g

Search in vi Editor :

/<yourstring>
or
?<yourstring>
press n for the next result in an open file in vi editor .

Navigation In vi Editor :

Move left :
h
Move Down:
j
Move up :
k
Move right :
l
At this point, you are familiar with vi editor commands. Practice more to become pro at vi editor.

Summary :

  • The vi editor is most popular and distributed in every Linux distribution to edit almost all types of files.
  • There are 3 modes of vi editor
  • In this article, we covered almost all commands of vi editor
Share Article if you like it or report any bug in comments
]]>
https://explinux.com/2020/07/how-to-use-vi-editor-in-linux-and-vi-editor-command-in-linux.html/feed 0
DU vs DF – Why du and df show different results in Linux https://explinux.com/2020/06/du-vs-df-why-du-and-df-show-different-results-in-linux.html https://explinux.com/2020/06/du-vs-df-why-du-and-df-show-different-results-in-linux.html#respond Wed, 24 Jun 2020 03:00:00 +0000 https://explinux.online/2020/06/24/du-vs-df-why-du-and-df-show-different-results-in-linux/ df vs du

DU vs DF – Why du and df show different results in Linux?

This is a common problem and question of every sysadmin that why they got different results in du and df. Mostly sysadmin relies on du over df for accurate results. In this article, we learn some basic facts about df and du to help you choose which one better and where to use.

Basic Definition:

df(Disk Free):

df reads disk blocks directly in the filesystem metadata and its trust on the superblock information . df reads the deleted file information also which is open in the running process. This always happens in case of big directory deletion which is used by large audiences. This command reads how much disk is totally free and trust filesystem metadata. This is the reason it gives you faster results.

df -h

du(Disk Usage): 

du reads every file in the directory and read their size. If any file deleted and open in the running process, it will not take any reference of the deleted file. du relies on which file currently in the directory and what is actual size. This is the reason it is slower than the df.

du -h

Conclusion: 

We can say df work on the filesystem and on the other hand du work on files. 

When to use df or du?

DF-

1- Use df in the new system both will show the same results because there is no delay or more running processes.
2- For daily operations use df because it is much faster and we required an overview of space
3- scripts where you create small or fewer files for a faster solution.

DU –

1- When you are running very low space in the directory use du to get all files accurate size.
2- Scripts where you create files on a large scale.
3- Disk size troubleshooting the best option is du.
At this point, you have understood the basic difference between du and df.
]]>
https://explinux.com/2020/06/du-vs-df-why-du-and-df-show-different-results-in-linux.html/feed 0
How To Use fdisk To Partition Disk latest updated https://explinux.com/2020/06/how-to-use-fdisk-to-partition-disk-latest-updated.html https://explinux.com/2020/06/how-to-use-fdisk-to-partition-disk-latest-updated.html#respond Mon, 22 Jun 2020 03:00:00 +0000 https://explinux.online/2020/06/22/how-to-use-fdisk-to-partition-disk-latest-updated/ How to use fdisk in linux for partition disk

How to use fdisk to Partition Disk in Linux

Fdisk is a disk partition table manipulation program. By this command, you can manipulate the disk partition table. fdisk is can be used for less than 2TB disk more than 2TB you have to use the parted command. 

In this article, we will see how to delete and create a new partition using fdisk in Linux.

Step 1 – List the disk 

Use the below command to list the disk and their partition table.
#fdisk -l 
check disk using fdisk
This will show you the disk information. In our case, we have added new disk in our system so we will check sdb (select which disk you have added) by below command:
#fdisk -l /dev/sdb
check disk by fdisk

Step 2 – Using the command to delete 

Now we have one disk sdb with label gpt we have to delete it. Use below command to enter :
#fdisk /dev/sdb
fdisk delete
Type “m” for help, this will show you all command available for this disk. This is a tip also because in a small Linux environment people share the same disk to another system and sysadmin tries to create a partition but he fails because everyone skips step one and then we get an error ” Value out of range. ” in the disk. check size available too.
fdisk help
We are going to delete so we press “d” for delete partition :
Command (m for help): d
delete disk partition
Command (m for help): w
fdisk save configuration
press w to save the configuration.
If you have raw disk then you can skip step 2 but it is always safe to check first then proceed.

Step 3 – Create partition 

We will do the same steps to enter the disk and press m for listing available options for the disk.
use n for creating a new partition,1 for the number of partition one press enter to leave default settings to use the full disk.
# fdisk /dev/sdb
Command (m for help): m  
Command (m for help): n
Partition number (1-128, default 1): 1
First sector (34-33554398, default 2048):    press enter key if you need default 
Last sector, +sectors or +size{K,M,G,T,P} (2048-33554398, default 33554398):  press enter key if you need default
Command (m for help): w
create partition using fdisk

Now you have successfully created partition. Now you can create PV,VG , LVM, and formate disk in any filesystem to mount on the mount point.

]]>
https://explinux.com/2020/06/how-to-use-fdisk-to-partition-disk-latest-updated.html/feed 0
How to Use Parted for Partition Disk https://explinux.com/2020/06/how-to-use-parted-for-partition-disk.html https://explinux.com/2020/06/how-to-use-parted-for-partition-disk.html#respond Thu, 18 Jun 2020 01:26:00 +0000 https://explinux.online/2020/06/18/how-to-use-parted-for-partition-disk/ How to Use Parted for Partition Disk
Sometimes we face issues in fdisk for more than 2TB volume format. In the end, it will ask for gpt error.
Parted is commonly used by sysadmin for volume more than 2 TB but you can use less volume too. Please find the below method how to use parted command :

Step 1- Check disk from lsblk which disk you want to format

#lsblk
explinux-lsblk-output
Here you can see sdb is new disk and not mounted on any mount point or directory. In case of multipath volume, you need to take extra care because sometimes mount point does not show. So compare before and after command output.

Step 2- Run below the command if you want only one partition from that disk 

# parted /dev/sdb
GNU Parted 2.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel gpt
(parted) unit GB
(parted) mkpart
Partition name?  []? 1
File system type?  [ext2]? ext4
Start? 0%
End? 100%
(parted) set 1 lvm on
(parted) quit

Information: You may need to update /etc/fstab.

how-to-use-parted-command
Now at this point, you have formated disk using parted. Now you have learned how to use the parted command on Linux systems or servers s For more updates subscribe to our blog.
]]>
https://explinux.com/2020/06/how-to-use-parted-for-partition-disk.html/feed 0
15 Linux Commands – Certainly Boost Productivity https://explinux.com/2020/05/linux-commands.html https://explinux.com/2020/05/linux-commands.html#respond Wed, 13 May 2020 06:56:00 +0000 https://explinux.online/2020/05/13/linux-commands/ This is our section where we will let you know about how to maximum utilize Linux commands.

This is an introduction page where we will understand Linux commands and why we need to use the command line. Maybe this post can have a different perspective for Linux users and admin. So basically this post is for Linux users and new admins.

Linux Command

Why Linux Command Line

Many new users can ask this question why Linux command. Like windows also have command line cmd and PowerShell but we never use them. So why it is important to use the command in Linux ?

In windows, we use applications like browser, Excel, PowerPoint, etc and we never try to change windows OS, and even legally we can not modify windows. In Linux we can modify Linux as per our requirements, most users use Linux because they find the freedom to customize there user experience according to them. Some point I al mentioning below why we need to use command line :

  • Faster execution – you can perform any action with command line
  • Single view Administration – You can perform all actions from putty or terminal
  • Edit beyond GUI- Mostly system tweak features are not integrated with GUI because GUI made only for the normal user. If you want to be a power user who can tweak system settings you need to use the command line.
  • Automate Script – If you want to automate your daily task. Command-line is a very easy and effective way. You can use any other programs and other languages. But in Linux shell script is much faster and effective to automate tasks. for Shell scripting Linux command are same as they are in terminal.

Who Can Skip Linux Commands

If you are using any specific GUI-based property application on Linux. Then you can skip the Linux command line. Otherwise, some basic command is mandatory to know.

Basic Linux Command for Everyone

Below are some basic Linux command which you should know even you are a user or new to linux. Please find some basic command below:

Note: Linux commands are case sensitive, so be careful otherwise you will get a command not found error.

  1. touch – This command is used to create a new file without any text or content
  2. vi or vim – This command is used to create a new file with a text or edit any existing file.
  3. nano – This command also has the same function as vi or vim. You can create or modify files.
  4. cat – View file content without opening the file
  5. Package Manager – This is different in different distribution like in Ubuntu apt is package manager in RHEL yum and dnf are package manager. You need to check as per your distribution but usages are the same.
  6. cp – Copy any file or directory from one location to another location.
  7. mv – Move file or directory from one location to another.
  8. rm – Remove or erase any file or directory.
  9. mkdir – Create a directory or folder.
  10. rmdir – Remove or delete the directory.
  11. systemctl or service – This command is used to start, stop, restart any service. systemctl has more functions but for basic this is enough.
  12. wget and curl – Both Linux commands are used to download files from the internet.
  13. ping – This command is very useful to check network connectivity. Very useful command for any admin but for new users a tool to test internet or connectivity.
  14. ip a – Check the IP address of your system and port status.
  15. reboot – This is a common command to reboot your system.

Here I have mentioned some basic commands for any Linux users and which can help you to increase productivity and use Linux faster than GUI mode.

Please let me in the comment if any other Linux commands is for new users.

]]>
https://explinux.com/2020/05/linux-commands.html/feed 0