{"id":13576,"date":"2019-04-03T10:59:41","date_gmt":"2019-04-03T10:59:41","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=13576"},"modified":"2019-04-03T10:59:41","modified_gmt":"2019-04-03T10:59:41","slug":"5-useful-commands-to-manage-file-types-and-system-time-in-linux-part-3","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/03\/5-useful-commands-to-manage-file-types-and-system-time-in-linux-part-3\/","title":{"rendered":"5 Useful Commands to Manage File Types and System Time in Linux \u2013 Part 3"},"content":{"rendered":"<p>Adapting to using the command line or terminal can be very hard for beginners who want to learn Linux. Because the terminal gives more control over a Linux system than GUIs programs, one has to get a used to running commands on the terminal. Therefore to memorize different commands in Linux, you should use the terminal on a daily basis to understand how commands are used with different options and arguments.<\/p>\n<div id=\"attachment_15655\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Find-File-Types-in-Linux.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15655\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Find-File-Types-in-Linux-620x297.jpg\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Find-File-Types-in-Linux-620x297.jpg 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Find-File-Types-in-Linux.jpg 720w\" alt=\"Manage File Types and Set Time in Linux\" width=\"620\" height=\"297\" aria-describedby=\"caption-attachment-15655\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15655\" class=\"wp-caption-text\">Manage File Types and Set Time in Linux \u2013 Part 3<\/p>\n<\/div>\n<p>Please go through our previous parts of this\u00a0<a href=\"https:\/\/www.tecmint.com\/tag\/linux-tricks\/\" target=\"_blank\" rel=\"noopener\">Linux Tricks<\/a>\u00a0series.<\/p>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/free-online-linux-learning-guide-for-beginners\/\" target=\"_blank\" rel=\"noopener\">5 Interesting Command Line Tips and Tricks in Linux \u2013 Part 1<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/10-useful-linux-command-line-tricks-for-newbies\/\" target=\"_blank\" rel=\"noopener\">10 Useful Commandline Tricks for Newbies \u2013 Part 2<\/a><\/li>\n<\/ol>\n<p>In this article, we are going to look at some tips and tricks of using 10 commands to work with files and time on the terminal.<\/p>\n<h3>File Types in Linux<\/h3>\n<p>In Linux, everything is considered as a file, your devices, directories and regular files are all considered as files.<\/p>\n<p>There are different types of files in a Linux system:<\/p>\n<ol>\n<li><strong>Regular files<\/strong>\u00a0which may include commands, documents, music files, movies, images, archives and so on.<\/li>\n<li><strong>Device files<\/strong>: which are used by the system to access your hardware components.<\/li>\n<\/ol>\n<p>There are two types of device files block files that represent storage devices such as\u00a0<strong>harddisks<\/strong>, they read data in blocks and character files read data in a character by character manner.<\/p>\n<ol>\n<li><strong>Hardlinks and softlinks<\/strong>: they are used to access files from any where on a Linux filesystem.<\/li>\n<li><strong>Named pipes and sockets<\/strong>: allow different processes to communicate with each other.<\/li>\n<\/ol>\n<h4>1. Determining the type of a file using \u2018file\u2019 command<\/h4>\n<p>You can determine the type of a file by using the\u00a0<strong>file<\/strong>\u00a0command as follows. The screenshot below shows different examples of using the file command to determine the types of different files.<\/p>\n<pre><strong>tecmint@tecmint ~\/Linux-Tricks $<\/strong> <strong>dir<\/strong>\r\nBACKUP\t\t\t\t      master.zip\r\ncrossroads-stable.tar.gz\t      num.txt\r\nEDWARD-MAYA-2011-2012-NEW-REMIX.mp3   reggea.xspf\r\nLinux-Security-Optimization-Book.gif  tmp-link\r\n\r\n<strong>tecmint@tecmint ~\/Linux-Tricks $<\/strong> <strong>file BACKUP\/<\/strong>\r\n<strong>BACKUP\/: directory<\/strong> \r\n\r\n<strong>tecmint@tecmint ~\/Linux-Tricks $<\/strong> <strong>file master.zip<\/strong> \r\n<strong>master.zip: Zip archive data, at least v1.0 to extract<\/strong>\r\n\r\n<strong>tecmint@tecmint ~\/Linux-Tricks $<\/strong> <strong>file crossroads-stable.tar.gz<\/strong>\r\n<strong>crossroads-stable.tar.gz: gzip compressed data, from Unix, last modified: Tue Apr  5 15:15:20 2011<\/strong>\r\n\r\n<strong>tecmint@tecmint ~\/Linux-Tricks $<\/strong> <strong>file Linux-Security-Optimization-Book.gif<\/strong> \r\n<strong>Linux-Security-Optimization-Book.gif: GIF image data, version 89a, 200 x 259<\/strong>\r\n\r\n<strong>tecmint@tecmint ~\/Linux-Tricks $<\/strong> <strong>file EDWARD-MAYA-2011-2012-NEW-REMIX.mp3<\/strong> \r\n<strong>EDWARD-MAYA-2011-2012-NEW-REMIX.mp3: Audio file with ID3 version 2.3.0, contains: MPEG ADTS, layer III, v1, 192 kbps, 44.1 kHz, JntStereo<\/strong>\r\n\r\n<strong>tecmint@tecmint ~\/Linux-Tricks $<\/strong> <strong>file \/dev\/sda1<\/strong>\r\n<strong>\/dev\/sda1: block special <\/strong>\r\n\r\n<strong>tecmint@tecmint ~\/Linux-Tricks $<\/strong> <strong>file \/dev\/tty1<\/strong>\r\n<strong>\/dev\/tty1: character special <\/strong>\r\n<\/pre>\n<h4>2. Determining the file type using \u2018ls\u2019 and \u2018dir\u2019 commands<\/h4>\n<p>Another way of determining the type of a file is by performing a long listing using the\u00a0<a href=\"https:\/\/www.tecmint.com\/15-basic-ls-command-examples-in-linux\/\" target=\"_blank\" rel=\"noopener\">ls<\/a>\u00a0and\u00a0<a href=\"https:\/\/www.tecmint.com\/linux-dir-command-usage-with-examples\/\" target=\"_blank\" rel=\"noopener\">dir<\/a>\u00a0commands.<\/p>\n<p>Using\u00a0<strong>ls -l<\/strong>\u00a0to determine the type of a file.<\/p>\n<p>When you view the file permissions, the first character shows the file type and the other charcters show the file permissions.<\/p>\n<pre><strong>tecmint@tecmint ~\/Linux-Tricks $<\/strong> <strong>ls -l<\/strong>\r\ntotal 6908\r\ndrwxr-xr-x 2 tecmint tecmint    4096 Sep  9 11:46 BACKUP\r\n-rw-r--r-- 1 tecmint tecmint 1075620 Sep  9 11:47 crossroads-stable.tar.gz\r\n-rwxr----- 1 tecmint tecmint 5916085 Sep  9 11:49 EDWARD-MAYA-2011-2012-NEW-REMIX.mp3\r\n-rw-r--r-- 1 tecmint tecmint   42122 Sep  9 11:49 Linux-Security-Optimization-Book.gif\r\n-rw-r--r-- 1 tecmint tecmint   17627 Sep  9 11:46 master.zip\r\n-rw-r--r-- 1 tecmint tecmint       5 Sep  9 11:48 num.txt\r\n-rw-r--r-- 1 tecmint tecmint       0 Sep  9 11:46 reggea.xspf\r\n-rw-r--r-- 1 tecmint tecmint       5 Sep  9 11:47 tmp-link\r\n<\/pre>\n<p>Using\u00a0<strong>ls -l<\/strong>\u00a0to determine\u00a0<strong>block<\/strong>\u00a0and\u00a0<strong>character<\/strong>\u00a0files.<\/p>\n<pre><strong>tecmint@tecmint ~\/Linux-Tricks $<\/strong> <strong>ls -l \/dev\/sda1<\/strong>\r\nbrw-rw---- 1 root disk 8, 1 Sep  9 10:53 \/dev\/sda1\r\n\r\n<strong>tecmint@tecmint ~\/Linux-Tricks $<\/strong> <strong>ls -l \/dev\/tty1<\/strong>\r\ncrw-rw---- 1 root tty 4, 1 Sep  9 10:54 \/dev\/tty1\r\n<\/pre>\n<p>Using\u00a0<strong>dir -l<\/strong>\u00a0to determine the type of a file.<\/p>\n<pre><strong>tecmint@tecmint ~\/Linux-Tricks $<\/strong> <strong>dir -l<\/strong>\r\ntotal 6908\r\ndrwxr-xr-x 2 tecmint tecmint    4096 Sep  9 11:46 BACKUP\r\n-rw-r--r-- 1 tecmint tecmint 1075620 Sep  9 11:47 crossroads-stable.tar.gz\r\n-rwxr----- 1 tecmint tecmint 5916085 Sep  9 11:49 EDWARD-MAYA-2011-2012-NEW-REMIX.mp3\r\n-rw-r--r-- 1 tecmint tecmint   42122 Sep  9 11:49 Linux-Security-Optimization-Book.gif\r\n-rw-r--r-- 1 tecmint tecmint   17627 Sep  9 11:46 master.zip\r\n-rw-r--r-- 1 tecmint tecmint       5 Sep  9 11:48 num.txt\r\n-rw-r--r-- 1 tecmint tecmint       0 Sep  9 11:46 reggea.xspf\r\n-rw-r--r-- 1 tecmint tecmint       5 Sep  9 11:47 tmp-link\r\n<\/pre>\n<h4>3. Counting number of files of a specific type<\/h4>\n<p>Next we shall look at tips on counting number of files of a specific type in a given directory using the\u00a0<strong>ls<\/strong>,\u00a0<a href=\"https:\/\/www.tecmint.com\/12-practical-examples-of-linux-grep-command\/\" target=\"_blank\" rel=\"noopener\">grep<\/a>\u00a0and\u00a0<a href=\"https:\/\/www.tecmint.com\/wc-command-examples\/\" target=\"_blank\" rel=\"noopener\">wc<\/a>\u00a0commands. Communication between the commands is achieved through named piping.<\/p>\n<ol>\n<li><strong>grep<\/strong>\u00a0\u2013 command to search according to a given pattern or regular expression.<\/li>\n<li><strong>wc<\/strong>\u00a0\u2013 command to count lines, words and characters.<\/li>\n<\/ol>\n<h6>Counting number of regular files<\/h6>\n<p>In Linux, regular files are represented by the\u00a0<code>\u2013<\/code>\u00a0symbol.<\/p>\n<pre><strong>tecmint@tecmint ~\/Linux-Tricks $<\/strong> <strong>ls -l | grep ^- | wc -l<\/strong>\r\n<strong>7<\/strong>\r\n<\/pre>\n<h6>Counting number of directories<\/h6>\n<p>In Linux, directories are represented by the\u00a0<code>d<\/code>\u00a0symbol.<\/p>\n<pre><strong>tecmint@tecmint ~\/Linux-Tricks $<\/strong> <strong>ls -l | grep ^d | wc -l<\/strong>\r\n<strong>1<\/strong>\r\n<\/pre>\n<h6>Counting number of symbolic and hard links<\/h6>\n<p>In Linux, symblic and hard links are represented by the\u00a0<code>l<\/code>\u00a0symbol.<\/p>\n<pre><strong>tecmint@tecmint ~\/Linux-Tricks $<\/strong> <strong>ls -l | grep ^l | wc -l<\/strong>\r\n<strong>0<\/strong>\r\n<\/pre>\n<h6>Counting number of block and character files<\/h6>\n<p>In Linux, block and character files are represented by the\u00a0<code>b<\/code>\u00a0and\u00a0<code>c<\/code>\u00a0symbols respectively.<\/p>\n<pre><strong>tecmint@tecmint ~\/Linux-Tricks $<\/strong> <strong>ls -l \/dev | grep ^b | wc -l<\/strong>\r\n<strong>37<\/strong>\r\n<strong>tecmint@tecmint ~\/Linux-Tricks $<\/strong> <strong>ls -l \/dev | grep ^c | wc -l<\/strong>\r\n<strong>159<\/strong>\r\n<\/pre>\n<h4>4. Finding files on a Linux system<\/h4>\n<p>Next we shall look at some commands one can use to find files on a Linux system, these include the\u00a0<strong>locate<\/strong>,\u00a0<strong>find<\/strong>,\u00a0<strong>whatis<\/strong>\u00a0and\u00a0<strong>which<\/strong>\u00a0commands.<\/p>\n<h6>Using the locate command to find files<\/h6>\n<p>In the output below, I am trying to locate the\u00a0<a href=\"https:\/\/www.tecmint.com\/setup-samba-file-sharing-for-linux-windows-clients\/\" target=\"_blank\" rel=\"noopener\">Samba server configuration<\/a>\u00a0for my system.<\/p>\n<pre><strong>tecmint@tecmint ~\/Linux-Tricks $<\/strong> <strong>locate samba.conf<\/strong>\r\n<strong>\/usr\/lib\/tmpfiles.d\/samba.conf<\/strong>\r\n<strong>\/var\/lib\/dpkg\/info\/samba.conffiles<\/strong>\r\n<\/pre>\n<h6>Using the find command to find files<\/h6>\n<p>To learn how to use the find command in Linux, you can read our following article that shows more than\u00a0<strong>30+<\/strong>practical examples and usage of find command in Linux.<\/p>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/35-practical-examples-of-linux-find-command\/\" target=\"_blank\" rel=\"noopener\">35 Examples of \u2018find\u2019 Command in Linux<\/a><\/li>\n<\/ol>\n<h6>Using the whatis command to locate commands<\/h6>\n<p>The\u00a0<strong>whatis<\/strong>\u00a0command is mostly used to locate commands and it is special because it gives information about a command, it also finds configurations files and manual entries for a command.<\/p>\n<pre><strong>tecmint@tecmint ~\/Linux-Tricks $<\/strong> <strong>whatis bash<\/strong>\r\n<strong>bash (1)             - GNU Bourne-Again SHell<\/strong>\r\n\r\n<strong>tecmint@tecmint ~\/Linux-Tricks $<\/strong> <strong>whatis find<\/strong>\r\n<strong>find (1)             - search for files in a directory hierarchy<\/strong>\r\n\r\n<strong>tecmint@tecmint ~\/Linux-Tricks $<\/strong> <strong>whatis ls<\/strong>\r\n<strong>ls (1)               - list directory contents<\/strong>\r\n<\/pre>\n<h6>Using which command to locate commands<\/h6>\n<p>The\u00a0<strong>which<\/strong>\u00a0command is used to locate commands on the filesystem.<\/p>\n<pre><strong>tecmint@tecmint ~\/Linux-Tricks $<\/strong> <strong>which mkdir<\/strong>\r\n<strong>\/bin\/mkdir<\/strong>\r\n\r\n<strong>tecmint@tecmint ~\/Linux-Tricks $<\/strong> <strong>which bash<\/strong>\r\n<strong>\/bin\/bash<\/strong>\r\n\r\n<strong>tecmint@tecmint ~\/Linux-Tricks $<\/strong> <strong>which find<\/strong>\r\n<strong>\/usr\/bin\/find<\/strong>\r\n\r\n<strong>tecmint@tecmint ~\/Linux-Tricks $<\/strong> $ <strong>which ls<\/strong>\r\n<strong>\/bin\/ls<\/strong>\r\n<\/pre>\n<h4>5. Working with time on your Linux system<\/h4>\n<p>When working in a networked environment, it is a good practice to keep the correct time on your Linux system. There are certain services on Linux systems that require correct time to work efficiently on a network.<\/p>\n<p>We shall look at commands you can use to manage time on your machine. In Linux, time is managed in two ways:\u00a0<strong>system time<\/strong>\u00a0and\u00a0<strong>hardware time<\/strong>.<\/p>\n<p>The\u00a0<strong>system time<\/strong>\u00a0is managed by a system clock and the hardware time is managed by a hardware clock.<\/p>\n<p>To view your system time, date and timezone, use the date command as follows.<\/p>\n<pre><strong>tecmint@tecmint ~\/Linux-Tricks $<\/strong> <strong>date<\/strong>\r\n<strong>Wed Sep  9 12:25:40 IST 2015<\/strong>\r\n<\/pre>\n<p>Set your system time using\u00a0<strong>date -s<\/strong>\u00a0or\u00a0<strong>date \u2013set=\u201dSTRING\u201d<\/strong>\u00a0as follows.<\/p>\n<pre><strong>tecmint@tecmint ~\/Linux-Tricks $<\/strong> <strong>sudo date -s \"12:27:00\"<\/strong>\r\n<strong>Wed Sep  9 12:27:00 IST 2015<\/strong>\r\n\r\n<strong>tecmint@tecmint ~\/Linux-Tricks $<\/strong> <strong>sudo date --set=\"12:27:00\"<\/strong>\r\n<strong>Wed Sep  9 12:27:00 IST 2015<\/strong>\r\n<\/pre>\n<p>You can also set time and date as follows.<\/p>\n<pre><strong>tecmint@tecmint ~\/Linux-Tricks $<\/strong> <strong>sudo date 090912302015<\/strong>\r\n<strong>Wed Sep  9 12:30:00 IST 2015<\/strong>\r\n<\/pre>\n<p>Viewing current date from a calendar using\u00a0<strong>cal<\/strong>\u00a0command.<\/p>\n<pre><strong>tecmint@tecmint ~\/Linux-Tricks $<\/strong> <strong>cal<\/strong>\r\n   September 2015     \r\nSu Mo Tu We Th Fr Sa  \r\n       1  2  3  4  5  \r\n 6  7  8  <strong>9<\/strong> 10 11 12  \r\n13 14 15 16 17 18 19  \r\n20 21 22 23 24 25 26  \r\n27 28 29 30      \r\n<\/pre>\n<p>View hardware clock time using the\u00a0<strong>hwclock<\/strong>\u00a0command.<\/p>\n<pre><strong>tecmint@tecmint ~\/Linux-Tricks $<\/strong> <strong>sudo hwclock<\/strong>\r\n<strong>Wednesday 09 September 2015 06:02:58 PM IST  -0.200081 seconds<\/strong>\r\n<\/pre>\n<p>To set the hardware clock time, use\u00a0<strong>hwclock \u2013set \u2013date=\u201dSTRING\u201d<\/strong>\u00a0as follows.<\/p>\n<pre><strong>tecmint@tecmint ~\/Linux-Tricks $<\/strong> <strong>sudo hwclock --set --date=\"09\/09\/2015 12:33:00\"<\/strong>\r\n\r\n<strong>tecmint@tecmint ~\/Linux-Tricks $<\/strong> <strong>sudo hwclock<\/strong>\r\n<strong>Wednesday 09 September 2015 12:33:11 PM IST  -0.891163 seconds<\/strong>\r\n<\/pre>\n<p>The system time is set by the hardware clock during booting and when the system is shutting down, the hardware time is reset to the system time.<\/p>\n<p>Therefore when you view system time and hardware time, they are the same unless when you change the system time. Your hardware time may be incorrect when the\u00a0<strong>CMOS<\/strong>\u00a0battery is weak.<\/p>\n<p>You can also set your system time using time from the hardware clock as follows.<\/p>\n<pre>$ sudo hwclock --hctosys\r\n<\/pre>\n<p>It is also possible to set hardware clock time using the system clock time as follows.<\/p>\n<pre>$ sudo hwclock --systohc\r\n<\/pre>\n<p>To view how long your Linux system has been running, use the\u00a0<strong>uptime<\/strong>\u00a0command.<\/p>\n<pre><strong>tecmint@tecmint ~\/Linux-Tricks $<\/strong> <strong>uptime<\/strong>\r\n<strong>12:36:27 up  1:43,  2 users,  load average: 1.39, 1.34, 1.45<\/strong>\r\n\r\n<strong>tecmint@tecmint ~\/Linux-Tricks $<\/strong> <strong>uptime -p<\/strong>\r\n<strong>up 1 hour, 43 minutes<\/strong>\r\n\r\n<strong>tecmint@tecmint ~\/Linux-Tricks $<\/strong> <strong>uptime -s<\/strong>\r\n<strong>2015-09-09 10:52:47<\/strong>\r\n<\/pre>\n<h3>Summary<\/h3>\n<p>Understanding file types is Linux is a good practice for begginers, and also managing time is critical especially on servers to manage services reliably and efficiently. Hope you find this guide helpful. If you have any additional information, do not forget to post a comment.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/manage-file-types-and-set-system-time-in-linux\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Adapting to using the command line or terminal can be very hard for beginners who want to learn Linux. Because the terminal gives more control over a Linux system than GUIs programs, one has to get a used to running commands on the terminal. Therefore to memorize different commands in Linux, you should use the &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/03\/5-useful-commands-to-manage-file-types-and-system-time-in-linux-part-3\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;5 Useful Commands to Manage File Types and System Time in Linux \u2013 Part 3&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-13576","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13576","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=13576"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13576\/revisions"}],"predecessor-version":[{"id":13577,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13576\/revisions\/13577"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=13576"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=13576"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=13576"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}