Difference between revisions of "Linux"

Line 1: Line 1:
===[[find]]===
+
==[[find]]==
 
<source>
 
<source>
 
find /home/username/ -name "*.err"
 
find /home/username/ -name "*.err"
Line 5: Line 5:
  
  
===[[grep]]===
+
==[[grep]]==
  
 
<source>
 
<source>
Line 35: Line 35:
 
</source>
 
</source>
  
===How To Extract Zip, Gz, Tar, Bz2, 7z, Xz and Rar File in Linux===
+
==How To Extract Zip, Gz, Tar, Bz2, 7z, Xz and Rar File in Linux==
====How to Extract .zip File:====
+
===How to Extract .zip===
 
<source>
 
<source>
 
$ unzip filename.zip
 
$ unzip filename.zip
 
</source>
 
</source>
  
====How to Extract .gz File:====
+
===How to Extract .gz===
 
Gz files are compressed files created using the Gzip compression utility. In general, GZIP is better in compared to ZIP, in terms of compression, especially when compressing a huge number of files. Use gunzip command to extract .gz archive file.
 
Gz files are compressed files created using the Gzip compression utility. In general, GZIP is better in compared to ZIP, in terms of compression, especially when compressing a huge number of files. Use gunzip command to extract .gz archive file.
 
<source>
 
<source>
Line 47: Line 47:
 
</source>
 
</source>
  
====How to Extract .tar File:====
+
===How to Extract .tar===
 
Tar is the sort of Tape Archive and also referred as the tarball. This is another popular archiving method which is also known as the consolidated Unix archive format. To extract .tar file use following command
 
Tar is the sort of Tape Archive and also referred as the tarball. This is another popular archiving method which is also known as the consolidated Unix archive format. To extract .tar file use following command
 
<source>
 
<source>
Line 53: Line 53:
 
</source>
 
</source>
  
====How to Extract .tar.gz File:====
+
===How to Extract .tar.gz===
 
TAR.GZ file is a combination of TAR and GZIP archives. If provides more compression format of data. You can use -z switch to extract these files.
 
TAR.GZ file is a combination of TAR and GZIP archives. If provides more compression format of data. You can use -z switch to extract these files.
  
Line 60: Line 60:
 
</source>
 
</source>
  
====How to Extract .tar.xz File:====
+
===How to Extract .tar.xz===
 
The XZ format is a single file compression format and does not offer archiving capabilities. It preserves the original data with no loss in quality. You can use -J switch to extract these files.
 
The XZ format is a single file compression format and does not offer archiving capabilities. It preserves the original data with no loss in quality. You can use -J switch to extract these files.
 
<source>
 
<source>
Line 66: Line 66:
 
</source>
 
</source>
  
====How to Extract .tar.bz2 File:====
+
===How to Extract .tar.bz2===
 
Tar.bz2 is an combination of tar and bzip2 archive formats. You can use -j to filter the archive through bzip2. Use the following to extract .tar.bz2 compressed file.
 
Tar.bz2 is an combination of tar and bzip2 archive formats. You can use -j to filter the archive through bzip2. Use the following to extract .tar.bz2 compressed file.
 
<source>
 
<source>
Line 76: Line 76:
 
</source>
 
</source>
  
====How to Extract .7z File:====
+
===How to Extract .7z===
 
These files are 7zip archive files. This is not generally used on Linux systems, but sometimes you may need to extract some source files. You must have the 7zip package installed on your system. Use the following command to extract these files.
 
These files are 7zip archive files. This is not generally used on Linux systems, but sometimes you may need to extract some source files. You must have the 7zip package installed on your system. Use the following command to extract these files.
 
<source>
 
<source>
Line 82: Line 82:
 
</source>
 
</source>
  
====How to Extract .rar File:====
+
===How to Extract .rar===
 
These are common archive format for Windows systems, but Linux users avoid to use this. Still you may need sometimes to extract .rar file on Linux. You can use 7z command to extract this or unrar.
 
These are common archive format for Windows systems, but Linux users avoid to use this. Still you may need sometimes to extract .rar file on Linux. You can use 7z command to extract this or unrar.
  

Revision as of 04:26, 9 August 2018

find

find /home/username/ -name "*.err"


grep

grep -rnw '/path/to/somewhere/' -e 'pattern'
  • -r or -R is recursive,
  • -n is line number, and
  • -w stands for match the whole word.
  • -l (lower-case L) can be added to just give the file name of matching files.

Along with these, --exclude, --include, --exclude-dir flags could be used for efficient searching:

This will only search through those files which have .c or .h extensions:

grep --include=\*.{c,h} -rnw '/path/to/somewhere/' -e "pattern"

This will exclude searching all the files ending with .o extension:

grep --exclude=*.o -rnw '/path/to/somewhere/' -e "pattern"

For directories it's possible to exclude a particular directory(ies) through --exclude-dir parameter. For example, this will exclude the dirs dir1/, dir2/ and all of them matching *.dst/:

grep --exclude-dir={dir1,dir2,*.dst} -rnw '/path/to/somewhere/' -e "pattern"

How To Extract Zip, Gz, Tar, Bz2, 7z, Xz and Rar File in Linux

How to Extract .zip

$ unzip filename.zip

How to Extract .gz

Gz files are compressed files created using the Gzip compression utility. In general, GZIP is better in compared to ZIP, in terms of compression, especially when compressing a huge number of files. Use gunzip command to extract .gz archive file.

$ gunzip filename.gz

How to Extract .tar

Tar is the sort of Tape Archive and also referred as the tarball. This is another popular archiving method which is also known as the consolidated Unix archive format. To extract .tar file use following command

$ tar -xvf filename.tar

How to Extract .tar.gz

TAR.GZ file is a combination of TAR and GZIP archives. If provides more compression format of data. You can use -z switch to extract these files.

$ tar -xzf filename.tar.gz

How to Extract .tar.xz

The XZ format is a single file compression format and does not offer archiving capabilities. It preserves the original data with no loss in quality. You can use -J switch to extract these files.

$ tar -xJf filename.tar.xz

How to Extract .tar.bz2

Tar.bz2 is an combination of tar and bzip2 archive formats. You can use -j to filter the archive through bzip2. Use the following to extract .tar.bz2 compressed file.

$ tar -xjf filename.tar.bz2

The latest version fo tar automatically detects the archive format. So you can simply use the following command.

$ tar -xf filename.tar.gz

How to Extract .7z

These files are 7zip archive files. This is not generally used on Linux systems, but sometimes you may need to extract some source files. You must have the 7zip package installed on your system. Use the following command to extract these files.

$ 7z x filename.7z

How to Extract .rar

These are common archive format for Windows systems, but Linux users avoid to use this. Still you may need sometimes to extract .rar file on Linux. You can use 7z command to extract this or unrar.

$ 7z x filename.rar         # Using 7zip 
$ unrar x filename.rar      # Using Unrar