How VPS - How to use/setup VPS
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
How VPS - How to use/setup VPS
No Result
View All Result
Home Operating System Linux

5 Useful Commands to Manage File Types and System Time in Linux – Part 3

How VPS by How VPS
November 2, 2018
in Linux, Operating System
0
0
SHARES
13
VIEWS
Share on FacebookShare on Twitter

Contents

  1. File Types in Linux
    1. 1. Determining the type of a file using ‘file’ command
    2. 2. Determining the file type using ‘ls’ and ‘dir’ commands
    3. 3. Counting number of files of a specific type
      1. Counting number of regular files
      2. Counting number of directories
      3. Counting number of symbolic and hard links
      4. Counting number of block and character files
    4. 4. Finding files on a Linux system
      1. Using the locate command to find files
      2. Using the find command to find files
      3. Using the whatis command to locate commands
      4. Using which command to locate commands
    5. 5. Working with time on your Linux system
  2. Summary

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.

5 Useful Commands to Manage File Types and System Time in Linux – Part 3

Manage File Types and Set Time in Linux – Part 3

Please go through our previous parts of this Linux Tricks series.

  1. 5 Interesting Command Line Tips and Tricks in Linux – Part 1
  2. 10 Useful Commandline Tricks for Newbies – Part 2

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.

File Types in Linux

In Linux, everything is considered as a file, your devices, directories and regular files are all considered as files.

There are different types of files in a Linux system:

  1. Regular files which may include commands, documents, music files, movies, images, archives and so on.
  2. Device files: which are used by the system to access your hardware components.

There are two types of device files block files that represent storage devices such as harddisks, they read data in blocks and character files read data in a character by character manner.

  1. Hardlinks and softlinks: they are used to access files from any where on a Linux filesystem.
  2. Named pipes and sockets: allow different processes to communicate with each other.

1. Determining the type of a file using ‘file’ command

You can determine the type of a file by using the file command as follows. The screenshot below shows different examples of using the file command to determine the types of different files.

[email protected] ~/Linux-Tricks $ dir
BACKUP				      master.zip
crossroads-stable.tar.gz	      num.txt
EDWARD-MAYA-2011-2012-NEW-REMIX.mp3   reggea.xspf
Linux-Security-Optimization-Book.gif  tmp-link

[email protected] ~/Linux-Tricks $ file BACKUP/
BACKUP/: directory 

[email protected] ~/Linux-Tricks $ file master.zip 
master.zip: Zip archive data, at least v1.0 to extract

[email protected] ~/Linux-Tricks $ file crossroads-stable.tar.gz
crossroads-stable.tar.gz: gzip compressed data, from Unix, last modified: Tue Apr  5 15:15:20 2011

[email protected] ~/Linux-Tricks $ file Linux-Security-Optimization-Book.gif 
Linux-Security-Optimization-Book.gif: GIF image data, version 89a, 200 x 259

[email protected] ~/Linux-Tricks $ file EDWARD-MAYA-2011-2012-NEW-REMIX.mp3 
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

[email protected] ~/Linux-Tricks $ file /dev/sda1
/dev/sda1: block special 

[email protected] ~/Linux-Tricks $ file /dev/tty1
/dev/tty1: character special 

2. Determining the file type using ‘ls’ and ‘dir’ commands

Another way of determining the type of a file is by performing a long listing using the ls and dir commands.

Using ls -l to determine the type of a file.

When you view the file permissions, the first character shows the file type and the other charcters show the file permissions.

[email protected] ~/Linux-Tricks $ ls -l
total 6908
drwxr-xr-x 2 tecmint tecmint    4096 Sep  9 11:46 BACKUP
-rw-r--r-- 1 tecmint tecmint 1075620 Sep  9 11:47 crossroads-stable.tar.gz
-rwxr----- 1 tecmint tecmint 5916085 Sep  9 11:49 EDWARD-MAYA-2011-2012-NEW-REMIX.mp3
-rw-r--r-- 1 tecmint tecmint   42122 Sep  9 11:49 Linux-Security-Optimization-Book.gif
-rw-r--r-- 1 tecmint tecmint   17627 Sep  9 11:46 master.zip
-rw-r--r-- 1 tecmint tecmint       5 Sep  9 11:48 num.txt
-rw-r--r-- 1 tecmint tecmint       0 Sep  9 11:46 reggea.xspf
-rw-r--r-- 1 tecmint tecmint       5 Sep  9 11:47 tmp-link

Using ls -l to determine block and character files.

[email protected] ~/Linux-Tricks $ ls -l /dev/sda1
brw-rw---- 1 root disk 8, 1 Sep  9 10:53 /dev/sda1

[email protected] ~/Linux-Tricks $ ls -l /dev/tty1
crw-rw---- 1 root tty 4, 1 Sep  9 10:54 /dev/tty1

Using dir -l to determine the type of a file.

[email protected] ~/Linux-Tricks $ dir -l
total 6908
drwxr-xr-x 2 tecmint tecmint    4096 Sep  9 11:46 BACKUP
-rw-r--r-- 1 tecmint tecmint 1075620 Sep  9 11:47 crossroads-stable.tar.gz
-rwxr----- 1 tecmint tecmint 5916085 Sep  9 11:49 EDWARD-MAYA-2011-2012-NEW-REMIX.mp3
-rw-r--r-- 1 tecmint tecmint   42122 Sep  9 11:49 Linux-Security-Optimization-Book.gif
-rw-r--r-- 1 tecmint tecmint   17627 Sep  9 11:46 master.zip
-rw-r--r-- 1 tecmint tecmint       5 Sep  9 11:48 num.txt
-rw-r--r-- 1 tecmint tecmint       0 Sep  9 11:46 reggea.xspf
-rw-r--r-- 1 tecmint tecmint       5 Sep  9 11:47 tmp-link

3. Counting number of files of a specific type

Next we shall look at tips on counting number of files of a specific type in a given directory using the ls, grep and wc commands. Communication between the commands is achieved through named piping.

  1. grep – command to search according to a given pattern or regular expression.
  2. wc – command to count lines, words and characters.
Counting number of regular files

In Linux, regular files are represented by the – symbol.

[email protected] ~/Linux-Tricks $ ls -l | grep ^- | wc -l
7
Counting number of directories

In Linux, directories are represented by the d symbol.

[email protected] ~/Linux-Tricks $ ls -l | grep ^d | wc -l
1
Counting number of symbolic and hard links

In Linux, symblic and hard links are represented by the l symbol.

[email protected] ~/Linux-Tricks $ ls -l | grep ^l | wc -l
0
Counting number of block and character files

In Linux, block and character files are represented by the b and c symbols respectively.

[email protected] ~/Linux-Tricks $ ls -l /dev | grep ^b | wc -l
37
[email protected] ~/Linux-Tricks $ ls -l /dev | grep ^c | wc -l
159

4. Finding files on a Linux system

Next we shall look at some commands one can use to find files on a Linux system, these include the locate, find, whatis and which commands.

Using the locate command to find files

In the output below, I am trying to locate the Samba server configuration for my system.

[email protected] ~/Linux-Tricks $ locate samba.conf
/usr/lib/tmpfiles.d/samba.conf
/var/lib/dpkg/info/samba.conffiles
Using the find command to find files

To learn how to use the find command in Linux, you can read our following article that shows more than 30+ practical examples and usage of find command in Linux.

  1. 35 Examples of ‘find’ Command in Linux
Using the whatis command to locate commands

The whatis command 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.

[email protected] ~/Linux-Tricks $ whatis bash
bash (1)             - GNU Bourne-Again SHell

[email protected] ~/Linux-Tricks $ whatis find
find (1)             - search for files in a directory hierarchy

[email protected] ~/Linux-Tricks $ whatis ls
ls (1)               - list directory contents
Using which command to locate commands

The which command is used to locate commands on the filesystem.

[email protected] ~/Linux-Tricks $ which mkdir
/bin/mkdir

[email protected] ~/Linux-Tricks $ which bash
/bin/bash

[email protected] ~/Linux-Tricks $ which find
/usr/bin/find

[email protected] ~/Linux-Tricks $ $ which ls
/bin/ls

5. Working with time on your Linux system

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.

We shall look at commands you can use to manage time on your machine. In Linux, time is managed in two ways: system time and hardware time.

The system time is managed by a system clock and the hardware time is managed by a hardware clock.

To view your system time, date and timezone, use the date command as follows.

[email protected] ~/Linux-Tricks $ date
Wed Sep  9 12:25:40 IST 2015

Set your system time using date -s or date –set=”STRING” as follows.

[email protected] ~/Linux-Tricks $ sudo date -s "12:27:00"
Wed Sep  9 12:27:00 IST 2015

[email protected] ~/Linux-Tricks $ sudo date --set="12:27:00"
Wed Sep  9 12:27:00 IST 2015

You can also set time and date as follows.

[email protected] ~/Linux-Tricks $ sudo date 090912302015
Wed Sep  9 12:30:00 IST 2015

Viewing current date from a calendar using cal command.

[email protected] ~/Linux-Tricks $ cal
   September 2015     
Su Mo Tu We Th Fr Sa  
       1  2  3  4  5  
 6  7  8  9 10 11 12  
13 14 15 16 17 18 19  
20 21 22 23 24 25 26  
27 28 29 30      

View hardware clock time using the hwclock command.

[email protected] ~/Linux-Tricks $ sudo hwclock
Wednesday 09 September 2015 06:02:58 PM IST  -0.200081 seconds

To set the hardware clock time, use hwclock –set –date=”STRING” as follows.

[email protected] ~/Linux-Tricks $ sudo hwclock --set --date="09/09/2015 12:33:00"

[email protected] ~/Linux-Tricks $ sudo hwclock
Wednesday 09 September 2015 12:33:11 PM IST  -0.891163 seconds

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.

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 CMOS battery is weak.

You can also set your system time using time from the hardware clock as follows.

$ sudo hwclock --hctosys

It is also possible to set hardware clock time using the system clock time as follows.

$ sudo hwclock --systohc

To view how long your Linux system has been running, use the uptime command.

[email protected] ~/Linux-Tricks $ uptime
12:36:27 up  1:43,  2 users,  load average: 1.39, 1.34, 1.45

[email protected] ~/Linux-Tricks $ uptime -p
up 1 hour, 43 minutes

[email protected] ~/Linux-Tricks $ uptime -s
2015-09-09 10:52:47

Summary

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. Stay connected to Tecmint.

Source: tecmint.com

Tags: Linux Commandslinux guidelinux vps setup guide
How VPS

How VPS

Related Posts

Failed to download metadata for repo 'appstream' on Centos 8
CentOS

How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

February 25, 2022
How to Install Apache Tomcat 8 on CentOS 7
Linux

How to Install Apache Tomcat 8 on CentOS 7?

February 11, 2020
Install Arch Linux With Btrfs Snapshotting
Uncategorized

Install Arch Linux With Btrfs Snapshotting

February 13, 2020
Next Post

How to Find Difference Between Two Directories Using Diff and Meld Tools

GoDaddy Review

GoDaddy Review

How To CloudFlare to Mitigate Distributed Denial of Service (DDoS) Attacks

How To CloudFlare to Mitigate Distributed Denial of Service (DDoS) Attacks

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Follow Us

  • 121 Followers
  • 87.2k Followers

Recommended

NetworkSolutions Review

4 years ago

How to Synchronize Time with NTP in Linux

4 years ago

Progress – A Tiny Tool to Monitor Progress for (cp, mv, dd, tar, etc.) Commands in Linux

4 years ago

Securing SSH on Ubuntu 14.04

3 years ago

Instagram

    Please install/update and activate JNews Instagram plugin.

Categories

  • Arch
  • Authentication
  • Backups
  • BSD
  • Centmin Mod
  • CentOS
  • Control Panels
  • CoreOS
  • CWP
  • Debian
  • Directadmin
  • Encryption
  • Fedora
  • Firewalls
  • Hocvps Script
  • Hosting providers
  • Kloxo-MR
  • Linux
  • Mitigations
  • Operating System
  • Plesk
  • Reviews
  • Securing VPS/Servers
  • Security Patches
  • SSL Certificates
  • Uncategorized
  • Upgrading
  • VPS/Servers management guides
  • Vulnerability Detection
  • Web servers software
  • Webhosting Control Panel

Topics

Apache Web Server Bluehost Review 2019 Bluehost Review 2020 Bluehost Review 2021 Centmin Mod CentminMod centos install htop fsck htop install HTTP DoS attack Install Snort on an Ubuntu install Zabbix on CentOS install Zabbix on CentOS 7 Linux Commands linux guide linux install htop linux vps setup guide MariaDB MariaDB Error Mysql mysqld error optimize MariaDB optimize Mysql snort Ubuntu
No Result
View All Result

Highlights

Top Free Web Hosting Control Panels To Manage VPS/Dedicated Servers

Webmin Reviews

Virtualmin Reviews

CentOS Web Panel Reviews

Ajenti Reviews

ISPConfig Reviews

Trending

Failed to download metadata for repo 'appstream' on Centos 8
CentOS

How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

by How VPS
February 25, 2022
0

I tried to update some extensions by use yum on centOs which I specified in Dockerfile. After...

How to Fix MySQL Error "Plugin 'InnoDB' registration as a STORAGE ENGINE failed"?

How to Fix MySQL Error “Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed”?

November 17, 2020
How to optimize Mysql or MariaDB

How to optimize Mysql or MariaDB

November 3, 2020
Top Free Web Hosting Control Panels To Manage VPS/Dedicated Servers

Top Free Web Hosting Control Panels To Manage VPS/Dedicated Servers

February 17, 2020
Webmin Reviews

Webmin Reviews

February 17, 2020
How VPS – How to use/setup VPS

We bring you the best Premium WordPress Themes that perfect for news, magazine, personal blog, etc. Visit our landing page to see all features & demos.
LEARN MORE »

Recent News

  • How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8 February 25, 2022
  • How to Fix MySQL Error “Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed”? November 17, 2020
  • How to optimize Mysql or MariaDB November 3, 2020

Categories

  • Arch
  • Authentication
  • Backups
  • BSD
  • Centmin Mod
  • CentOS
  • Control Panels
  • CoreOS
  • CWP
  • Debian
  • Directadmin
  • Encryption
  • Fedora
  • Firewalls
  • Hocvps Script
  • Hosting providers
  • Kloxo-MR
  • Linux
  • Mitigations
  • Operating System
  • Plesk
  • Reviews
  • Securing VPS/Servers
  • Security Patches
  • SSL Certificates
  • Uncategorized
  • Upgrading
  • VPS/Servers management guides
  • Vulnerability Detection
  • Web servers software
  • Webhosting Control Panel

[mc4wp_form]

© 2018 JNews - City News Magazine WordPress theme. All rights belong to their respective owners.
JNews is a top selling 2018 WordPress News, Blog, Newspaper & Magazine Theme.

No Result
View All Result
  • Home

© 2023 JNews - Premium WordPress news & magazine theme by Jegtheme.