- How to display file details (size, date, etc.) from Linux “locate” command?
- 3 Answers 3
- How do I see file details in Linux?
- How do you view file details in Unix?
- How do I see metadata in Linux?
- Is I command in Linux?
- How do I view EXIF metadata?
- What is the Linux command?
- Where is run command in Linux?
- How do I view EXIF data in Linux?
- Who am I command in Linux?
- How do you find a file in Linux?
- How to view all details or metadata in Linux?
- How does the find command work in Linux?
- Which is the best way to find a file?
- how to view all details or metadata of a file in linux command line
- ls Command
- stat Command
- Image Files
How to display file details (size, date, etc.) from Linux “locate” command?
The (slow) Linux “find” command has an option, “-ls”, to display size, date, etc. like the “ls -l” command. But the “locate” command doesn’t seem to have that. So how can I get the equivalent functionality with locate? I’ve used back-ticks to pass the output of locate to ls, like this:
…which works as long as somefile exists. But if somefile doesn’t exist, it gives me a full directory listing. If I do this:
ls -al `locate -e somefile` thisfileneverexists
ls: cannot access thisfileneverexists: No such file or directory
ls -al `locate -e somefile` thisfileneverexists 2>/dev/nul
3 Answers 3
Use xargs . This takes as input a series of parameters, and carries out an operation on them:
locate -eb0P somefile | xargs -r0 ls -ald
xargs will carry out the ls -ald command using the results of the locate as parameters.
The -e switch tells locate to check that files found in the database really exist, and ignore any which don’t.
The -b switch tells locate to match just basenames.
The -0 (zero) switch tells locate to generate null delimiters instead of blanks (so it can handle file names which contain blanks)
The -P switch tells locate to list broken symlinks
The -r switch tells xargs to not carry out the command if nothing is passed in — ie when the locate returns nothing.
The -0 switch tells xargs to expect nulls instead of blanks as delimiters
The -a switch tells ls to list even files that begin with «.»
The -d switch tells ls to list directories rather than their contents
How do I see file details in Linux?
The easiest way to list files by name is simply to list them using the ls command. Listing files by name (alphanumeric order) is, after all, the default. You can choose the ls (no details) or ls -l (lots of details) to determine your view.
How do you view file details in Unix?
- You can limit the files that are described by using fragments of filenames and wildcards. .
- If you would like to list files in another directory, use the ls command along with the path to the directory. .
- Several options control the way in which the information you get is displayed.
How do I see metadata in Linux?
- Using ImageMagick. ImageMagick has a command line tool named «Identify» to find image metadata. .
- Using file command. We can use file command, which is used to determine file types, to view metadata of an image. .
- Using Exif Tool.
Is I command in Linux?
Using the -i argument with the command helps to ignore the case (it doesn’t matter if it is uppercase or lowercase). So, if you want a file that has the word “hello”, it gives the list of all the files in your Linux system containing the word «hello» when you type in “locate -i hello”.
How do I view EXIF metadata?
Viewing EXIF data in Windows is easy. Just right-click on the photo in question and select “Properties”. Click on the “Details” tab and scroll down—you’ll see all kinds of information about the camera used, and the settings the photo was taken with.
What is the Linux command?
The Linux command is a utility of the Linux operating system. All basic and advanced tasks can be done by executing commands. The commands are executed on the Linux terminal. The terminal is a command-line interface to interact with the system, which is similar to the command prompt in the Windows OS.
Where is run command in Linux?
Its distros come in GUI (graphical user interface), but basically, Linux has a CLI (command line interface). In this tutorial, we are going to cover the basic commands that we use in the shell of Linux. To open the terminal, press Ctrl+Alt+T in Ubuntu, or press Alt+F2, type in gnome-terminal, and press enter.
How do I view EXIF data in Linux?
- Using ImageMagick. ImageMagick has a command line tool named «Identify» to find image metadata. .
- Using file command. We can use file command, which is used to determine file types, to view metadata of an image. .
- Using Exif Tool.
Who am I command in Linux?
whoami command is used both in Unix Operating System and as well as in Windows Operating System. It is basically the concatenation of the strings “who”,”am”,”i” as whoami. It displays the username of the current user when this command is invoked.
How do you find a file in Linux?
Well, surprise, surprise, you’re going to need the find command in Linux to scour your directory or file system. The Linux find command can filter objects recursively using a simple conditional mechanism, and if you use the -exec flag, you’ll also be able to find a file in Linux straightaway and process it without needing to use another command.
How to view all details or metadata in Linux?
If you are using another command such as find or locate to print out files, then you can pipe (|) the output of that command to either ls or stat to print out more meaningful information. A simple example is
How does the find command work in Linux?
The “find” command allows you to search for files for which you know the approximate filenames. The simplest form of the command searches for files in the current directory and recursively through its subdirectories that match the supplied search criteria.
Which is the best way to find a file?
The best way to find files is to utilize several different terminal commands. Mastering these commands can give you complete control over your files, and they are much more powerful than the simple search functions on other operating systems. Search for a file by its file name. This is the most basic search you can perform using the find command.
This post and this website contains affiliate links. See my disclosure about affiliate links.
how to view all details or metadata of a file in linux command line
When viewing a particular file in Linux, you might want to see all the relevant file metadata associated with it. The file metadata details includes information regarding its size, permissions, creation date, access date, inode number, uid/gid, file type etc.
There are mainly two different commands that you can use for this purpose, ls and stat. Both will print out almost the same information but in different format.
ls Command
The most useful of the two commands is ls, (at least in my opinion) which lists the file details. Using some command line options you can print out all the details and metadata information of the particular file.
The various command line options above prints out various information as detailed below
l : This uses the long listing format while printing out. This is much more informative than the default format.
i : Prints out the inode number of the file
s : Prints the file size in blocks
a : Prints out all entries and does not ignore any files
n : Prints out the numeric user id and group id
h : Print the sizes in human readable format.
The above command will print out all relevant metadata information about the file, but usually is not very human readable in its format. As long as you know what information is printed in each column it should work just fine.
If you prefer a much more human readable format, then you can use the stat command instead.
stat Command
The basic stat command works without any command line arguments, other than the file name…
[root 17:03:19] ~ # stat world_bkp
File: ‘world_bkp’
Size: 2434 Blocks: 8 IO Block: 4096 regular file
Device: 804h/2052d Inode: 262149 Links: 1
Access: (0644/-rw-r—r—) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2014-02-13 05:06:57.883217273 -0600
Modify: 2014-02-13 05:06:57.893217273 -0600
Change: 2014-02-13 05:06:57.893217273 -0600
Birth: —
This prints out almost the same information as the ls command, but prints it out in a much more human readable format. There is also a basic description for each value in the format.
Both the ls and stat commands can be used for any file descriptor, which means both the file as well as directories. stat can be used on file systems as well.
The -f command line option specifies to print out the file system status instead of the file status. You can see the difference by running the command with and without the -f option.
If you are using another command such as find or locate to print out files, then you can pipe (|) the output of that command to either ls or stat to print out more meaningful information. A simple example is
bash$ locate world_bkp | xargs stat
The above command will print out the file details exactly as before, but is useful if you didn’t know the exact location of the world_bkp file. Another example of piping to ls command is
bash$ locate world_bkp | xargs ls -lisan
Again, as with most Linux commands, you can input multiple files in the command line to print the details of multiple files or use the pipe to output details of multiple files.
Image Files
There are in fact a couple of more commands that shows you specific information of a file depending on the type of the file. If you want to see what the file type is, then the file command can help you out.
Also in the case of image files, the identify command that is part of the imagemagick package is a very good option. The identify command will print out the image specific properties such as the format, colorspace, channel information etc.
bash$ identify -verbose myimage.jpg