How to Find all Files Containing a String in Linux. This tutorial will help you to search all files containing specific text string recursively. This tutorial uses “find” command to search string in files. Alternatively, You can also use grep command to search text.
Category: Uncategorized
How to use DPKG commands in Linux
DPKG is the main package management program in Debian and Debian based System. It is used to install, build, remove, and manage packages. Aptitude is the primary front-end to dpkg.
|
COMMAND DETAILS
|
DPKG COMMAND
|
|
Install a package
|
dpkg -i {file.deb}
|
|
Update package
|
dpkg -i {file.deb}
|
|
Remove an installed package
|
dpkg -r {package}
|
|
List all installed packages
|
dpkg -l
|
|
List files in an installed package
|
dpkg -L {package}
|
|
Show information about installed package
|
dpkg -p {package}
|
|
Show information about package file
|
dpkg -I {file.deb}
|
|
List files in a package file
|
dpkg -c {file.deb}
|
Example:
sudo dpkg -i package.deb
Installing Package:
Removing Package:
How to use RPM Commands in Linux
RPM command is used for installing, uninstalling, upgrading, querying, listing, and checking RPM packages on your Linux system. RPM stands for Red Hat Package Manager.
|
COMMAND DETAILS
|
RPM COMMAND
|
|
Install a package
|
rpm -i {package.rpm}
|
|
Update package
|
rpm -U {file.rpm}
|
|
Remove an installed package
|
rpm -e {package}
|
|
List all installed packages
|
rpm -qa
|
|
List files in an installed package
|
rpm -ql {package}
|
|
Show information about installed package
|
rpm -qi
|
|
Show information about package file
|
rpm -qpi {file.rpm}
|
|
List files in a package file
|
rpm -qpl {file.rpm}
|
|
Verify all installed packages
|
rpm -Va
|
|
Verify installed package
|
rpm -V {package}
|
Example:
rpm -i package-1.2.3.rpm
Installing Package:
Removing Package:
How to Exit Vim Text Editor
VIM is an enhanced version of VI text editor. It is highly configurable text editor to edit files very efficiently. Many of Linux beginners faces issue with exit form vi/vim editor. This tutorial will help you to exit Vim text editor in Linux command line.
How to Exit Vim?
ESC to go to command mode. Now type a colon :to before writing exit command.- ESC + :q – Simple exit from a file, only if no changes made to file.
- ESC + :wq – Write changes and quite from Vim editor.
- ESC + :q! – Quit Vim editor without saving any changes (discard all changes made after edit file or last saved).
Using Keyboard Shortcuts
ESC to make sure you are in command mode.- Shift + z + z – save changes and exit
- Shift + z + q – exit without saving changes
How to use cut Command in Linux
Linux cut command is used for extracting file content on fields basis. text files do not have row/column like databases and some times we need the data of single column only. Cut identified columns on basis of separator (eg: colon ‘:’, semicolon ‘;’, comma ‘,’ etc).

1. Select Single Field from File –
2. Select Multiple Columns from File –
- Here first command will select 1’st, 2’nd,3’rd and 4’th fields.
- Second command will select 3’rd, 4’th and 5’th fields.
- Last command will show 2’nd, 3’rd, 4’th, 6’th and 10’th fields.
3. Selecting Single Character’s from File –
How to Use chattr Command in Linux
Chattr – command is useful to change file attributes on Linux second extended file system. It provides more security on your files from unwanted changes and deletes. There are many attributes available to do it.
How to Use Chattr Command
Add Attribute on File
i attribute on filei attribute on file, let’s try to remove this file, you we get following error, even file has 777 permissions.List Attributes of File
lsattr command specified with file name.Remove Attributes of File
Attributes List in Chattr Command
i attribute cannot be modified, it cannot be deleted or renamed by any user included root. Only root can clear this attribute. By this attribute you can keep safe your impotent files from other users or accidental delete.How to read file Line by Line using Linux Shell Script
You can use while..do to read file line by line on a Linux or Unix-like system.
Syntax: Read file line by line on a Bash Unix & Linux shell:
- The syntax is as follows for bash, ksh, zsh, and all other shells to read a file line by line
- while read -r line; do COMMAND; done < input.file
- The -r option passed to read command prevents backslash escapes from being interpreted.
- Add IFS= option before read command to prevent leading/trailing whitespace from being trimmed –
- while IFS= read -r line; do COMMAND_on $line; done < input.file
Example:-
How to Read a File Line By Line in Bash
How to Find File Creation Time in Linux
File creation time is stored in inode in EXT4 file system. An earlier version of EXT files systems doesn’t support file creation time.
There is a crtime (create time) timestamp in the debugfs stat output. finally EXT4 supports create time just like btime in NTFS windows.
Follow below instructions to how to find file creation time. Select an existing file or create a new file for testing. For this example, I am using an existing file.
Step 1 – Find Inode Number of File
Step 2 – Find File Creation Time (crtime)
Implementation:
Find Public IP using Linux Command
Public IP is used for communication between computers over the Internet. A computer running with public IP is accessible all over the world using the Internet. So we can say that it is the identity of the computer on the internet. Now the question is how do we know our public IP?. For computers having GUI can easily get there IP using web tools but how to get public IP of the computers having terminal access only. The solution is here – use one of the following commands to find public IP of your system using Linux terminal. These are also useful to use in a shell script.
Find Public IP using Linux Command
Command 1 –
Command 2 –
Command 3,4,5 –
Get Public IP in Shell Script
How to Remove Empty Lines from File in Linux
Some time we need to remove empty lines from a file. Its can be done manually if file have few lines but if file have thousands of line this is hard to be done manually. Use one of following method to remove empty lines from a file.
Method 1 – Using sed
- -i ( edit files in place ) Used for make changes in same file.
