User:Andy Crowd/Get information about files

From ArchWiki


Get information about files

For a new or unknown files

  • file - get a warrior information about a file
  • xdg-mime - getting a mime type of a file
  • md5sum - shows md5sum of a file
  • shasum - shows SHA sum, (sha1sum sha224sum sha256sum sha384sum sha512sum shasum)
  • ls, dir - those commands are used to list a content in folders

Mostly used on an already installed operative system

  • basename - shows only filename without its path. $ basename /path/filename will show only filename.
  • "${FilePathVariable##*/}" - same as basename but is a bash expression that cuts dir path
  • echo /path/filename | sed 's/[^*]*\///g' - shows the basename, same as two examples above
  • touch - can create an empty file but not overwriting if the file already exist and can change a file timestamps
  • stat - statistics of a file
  • lsof - list open files
  • mount - mount or show mounted files or devices
  • ps - shows information about processes
  • du - shows the size of a folder tree or a single file
  • if [ -f '/path/filename'];then echo exist;fi - checking if the file exists
  • if [ ! -f '/path/filename'];then echo exist;fi - checking if the file «does not» exists
  • getfacl - get info about file's extended access rights
  • getfattr - get info about extended attributes
  • find - search files or check for broken symlinks $ find -L -type l
  • find -type f -print0 | xargs -0 -L 1 file | grep text - grep from stdout info from file command.
  • df - shows up to ~95% of all available free as without reserved free space
  • tune2fs - shows a warriors information about block device including available reserved free space - tune2fs -l /dev/sd"XY"
  • pacman - arch package installer and can check which of packages a file belongs to. $ pacman -Qo /usr/bin/ifconfig
  • check dependences pactree -l pacman | sort -u | cut -f 1 -d ' '

Download files

With correct file names

  • wget - download files or mirror websites, to download with correct file names if possible:
wget --content-disposition -m -nd -nH http://website_to_mirror/
  • curl - download files
curl -J -O http://website_to_mirror/

See also in forum

dump links

From youtube:

lynx -dump 'https://www.youtube.com/playlist?list=PL90ABNRn4Rq7n3xYPjRZZqRLYfoFrVDZj' |  awk '/http/{if(index($2,"watch"))print $2}'

See also: dump links

Specialized

  • identify — Shows more information (and metadata) about image files.$ identify -verbose imagename
http://www.imagemagick.org/ || imagemagick
  • mediainfo — shows info about video/audio files.$ mediainfo -f mediafile
http://mediaarea.net/en/MediaInfo || mediainfo
  • feh — Shows the image and/or information about it.$ feh -l imagename
http://feh.finalrewind.org/ || feh
  • exiv2 — Shows a meta-data info of image files.$ exiv2 pr -v imagename
http://www.exiv2.org/ || exiv2
  • pdfinfo — Shows extra information about PDF files.$ pdfinfo -js -meta -rawdates -box filename.pdf
http://poppler.freedesktop.org/ || poppler
  • jpeginfo — Shows info and integrity of jpeg files. $ jpeginfo -ci imagename.jpg.
http://www.kokkonen.net/tjko/projects.html || jpeginfoAUR
  • pngcheck — Shows info and integrity of PNG, JNG and MNG image types. $ pngcheck *.png.
http://www.libpng.org/pub/png/apps/pngcheck.html || pngcheckAUR
  • exiftool — Shows metadata of images. $ exiftool *jpg.
http://xahlee.info/img/metadata_in_image_files.html || perl-image-exiftool
  • mogrify — Adding a comment to the image.$ mogrify -comment "yourcomment" /path/file.png.
http://www.imagemagick.org/ || imagemagick}}
  • which - Shows a path to an executable file by searching it in folders that are in the $PATH environment variable.$ which bash will show only /bin/bash.
  • isoinfo - Shows warriors information about the ISO image. isoinfo -d /path/isofile.iso

Check integrity of images with scripts

This is a python3 script that tests integrity of an image by loading its data and showing errors if got any. Requires the python-pillow library for the proper running. It can be combined with find -type f -name "*.jpg" -exec ThisScript.py "{}" \; to check multiple images.

#!/bin/python3
import sys
from PIL import Image
from optparse import OptionParser
parser = OptionParser()
(options, args) = parser.parse_args()
FileName = "".join(args)
try:
    im = Image.open(FileName,"r")
except IOError:
    print("Cannot open the «",FileName,"» file!")
else:
     try:
        TestLoadImgData = list(im.getdata())
     except IOError:
        print("An error was found in a «",FileName,"» file!")
        im.close()
     else:
        print("No Errors were found!")
        im.close()")

Archive testers

  • p7zip — Test integrity of files in 7z, wim, tar archives. $ 7z t archivename *
http://p7zip.sourceforge.net/ || p7zip
  • unrar — Test integrity of archive files. $ unrar t archivename *
http://www.rarlab.com/rar_add.htm || unrar

Gzip and tar verbose test

$ gunzip -kvc archivename.tar.gz | tar tv
$ gunzip -ktv archivename.gz
$ tar tv archivename.tar
Note: Most of the compress/uncompress archive tools includes their own test abilities.

MIME-types list of the path to files

There are available additional preset MIME-type descriptions for a various desktop environments.

The factual accuracy of this article or section is disputed.

Reason: The following comparison table either conflicts with the previous note or the items should not be compared at all. defaults.list sets default applications associations, AFAIK the others do not. shared-mime-info is required by many desktop-independent packages. (Discuss in User talk:Andy Crowd/Get information about files)
Package name Description Files
gnome-defaults-listAUR Ubuntu defaults /etc/gnome/defaults.list
/usr/share/applications/defaults.list
mime-types Additional list of MIME-types /etc/mime.types
shared-mime-info XDG MIME-type database is a part of the package /usr/share/mime/packages/freedesktop.org.xml